[openCV, PIL] openCV to PIL / PIL to openCV

2020. 4. 23. 10:42Coding/Android Studio

728x90

#공통 import 목록
import cv2
import numpy as np
from PIL import Image,ImageEnhance
from matplotlib import pyplot as plt

 


 

openCV방식
img = cv2.imread("/home/ubuntu/dev/_dataset/dental/panorama/188.png")
print(type(img))
-> numpy.ndarray

 

openCV -> PIL
img = cv2.imread("/home/ubuntu/dev/_dataset/dental/panorama/188.png")
pil_image=Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
print(type(pil_image))
-> PIL.Image.Image

 

 


 

PIL방식
img = Image.open("./188.png")
print(type(img))
-> PIL.PngImagePlugin.PngImageFile

 

PIL -> openCV
img = 
Image.open("./188.png")
numpy_image=np.array(img)
print(type(numpy_image))
-> numpy.ndarray

 

 

 

참고
https://stackoverflow.com/questions/43232813/convert-opencv-image-format-to-pil-image-format

 

Convert opencv image format to PIL image format?

I want to convert an image loaded TestPicture = cv2.imread("flowers.jpg") I would like to run a PIL filter (http://pillow.readthedocs.io/en/4.0.x/reference/ImageFilter.html) like on the example ...

stackoverflow.com

 

728x90