0

I have image (JPG/JPEG) which looks like this:

enter image description here

As part of the tests, I decided to create an identical image while preserving the dimensions of the original image through the .resize method of the OpenCV library. After the transformations, the image changes its original color.

image = numpy.asarray(bytearray(response.read()), dtype="uint8")

image = cv2.imdecode(image_file, cv2.IMREAD_COLOR)

image_height, image_width = image.shape[:2]

dimension = (image_width, image_height)

resized_image = cv2.resize(image, dimension, interpolation=cv2.INTER_LINEAR)

enter image description here

In a similar stackoverflow question, I found that OpenCV uses BGR. So I converted BGR to RGB with the code below. Unfortunately it returns me strange result.

image = numpy.asarray(bytearray(response.read()), dtype="uint8")

image = cv2.imdecode(image, cv2.IMREAD_COLOR)

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

...

enter image description here

Nurzhan Nogerbek
  • 4,806
  • 16
  • 87
  • 193
  • 1
    Perhaps you lost a color profile – fmw42 Feb 07 '21 at 19:53
  • the first image has ProPhoto RGB color profile, while the second image has no embedded color profile. I'm doing some googling on how to deal with color profiles on opencv – Aaron Feb 07 '21 at 19:53
  • 1
    see https://stackoverflow.com/questions/44562776/color-gets-dull-opencv-cv2-imread-cv2-imwrite and https://stackoverflow.com/questions/33168615/how-to-read-jpeg-image-with-adobe-rgb-colorspace-in-opencv – Stef Feb 07 '21 at 20:08
  • 1
    OpenCV does not have any support for icc color profiles. you must use another library like PIL – Aaron Feb 07 '21 at 20:16
  • @Aaron thank you for your response. I was convinced that `OpenCV` has everything you need to work with images. That's why I chose it to work with pictures. Where did you get this information that `OpenCV` does not have any support for `ICC` color profiles? – Nurzhan Nogerbek Feb 08 '21 at 05:30
  • @NurzhanNogerbek one of the linked questions or another one I found with similar search terms – Aaron Feb 08 '21 at 07:27
  • Also just looking through the docs, there's no mention of icc color profiles (even though there is [color correction](https://docs.opencv.org/4.5.1/de/df4/group__color__correction.html)) – Aaron Feb 08 '21 at 07:34

0 Answers0