Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image color changed after converting from numpy array to PIL image python

I am trying to convert the image that I read using cv2.imread which is store in numpy array to PIL Image object , the color of Image will be changed Here is the code

I=cv2.imread("Image.jpg")
PILImage=Image.fromarray(I,mode='RGB')

How can get back my original Image?

like image 630
Jitesh Avatar asked Aug 28 '26 19:08

Jitesh


1 Answers

OpenCV likes to treat images as having BGR layers instead of RGB layers. Adding

I = cv2.cvtColor(I, cv2.COLOR_BGR2RGB)

will swap layers to what you expect.

like image 149
Dave W. Smith Avatar answered Aug 30 '26 10:08

Dave W. Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!