6

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?

1 Answer 1

17

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great this was exactly what I needed! Thanks Dave! This worked for me opening a .jpeg editing it then saving as a .png.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.