Convert loaded images to rgb565 results in color shift

When I load images taken with the board and convert them to rgb565, a color shift occurs, also on firmware 4.2.3. This is visible on the new images below.

Original image taken by H7+, then cropped in gthumb and saved:

Original image cropped and saved with H7+:

As you see, the red cable becomes yellow.
Original:


This script can be used:

import sensor, image, time, pyb
img=image.Image("66.jpg",copy_to_fb=True)
print("original loaded image:",img)
img.save("66_straight.jpg")
img.to_rgb565()
print("rgb565-converted image:",img)
img.save("66_torgb.jpg")

When I load a jpeg and save it immediately after loading, no color shift is visible. If I do a to_rgb565 conversion, the impact on colors can be dramatic, for example here (on another image):
original:
image

converted:
image

Are you cropping the image then saving it as jpeg then reloading ? Can you post like steps to reproduce this issue ? It might be related to cropping on odd bayer boundaries.

I tried it with and without cropping (referring to the previous forum thread where this post was originally found), to then realise that cropping did not matter, to_rgb565 conversion did. If you download any of the original images linked above and run the minimal working example, you will see the color shift. Here is the original image whose histogram is shown right above :


By the way, it seems that img.format() returns the size and not the sensor format.

Can you post these issues on github so they can be tracked. This one and the jpeg decompress one? They both seem to stem from the same issue. I am free this weekend and can take a crake at fixing the hardware jpeg code.

When you post an issue on github, please post a minimal script to reproduce the issue, steps and attach the images in a zip file.

this was filed on GItHub:

Thanks, this bug was fixed in the latest 4.3.1 firmware release - the color shift is much more subtle (there is still one but I suppose that is because the conversion cannot be lossless?).

Can you try this: imlib: Enable hardware JPEG decoder. by kwagyeman · Pull Request #1604 · openmv/openmv · GitHub. The code here should have the best performance. I notice no color shifts. If you still see it then there’s nothing that can be done. It’s at the best.

I tested it on more images. The issue appears solved and the slight changes I observed might be due to re-compression. Thanks a lot