Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading jpg files gives different results in 3.4.0 and 3.4.2 #12340

Closed
gilbertfrancois opened this Issue Aug 29, 2018 · 4 comments

Comments

3 participants
@gilbertfrancois
Copy link

gilbertfrancois commented Aug 29, 2018

System information
  • OpenCV => 3.4.2
  • Operating System / Platform => macOS 10.13.6
  • Language => Python 3.6 (Anaconda), numpy 0.14.2
  • OpenCV installed from pypi (pip install --no-deps opencv-python)
Description

I noticed different output values when using the function cv2.imread for loading JPG files between opencv version 3.4.0 and 3.4.2. To test if there is a bug in 3.4.0 or 3.4.2 I compared the output with the library scikit-image version 0.14.0.

  • opencv-3.4.0 and skimage 0.14.0 => same results
  • opencv-3.4.2 and skimage 0.14.0 => different results

cv2.cvtColor(cv2.imread('myfile.jpg'), cv2.COLOR_BGR2RGB) in OpenCV 3.4.0 gives exactly the same result as skimage.io.imread('my file.jpg). However, when doing cv2.imread('myfile.jpg') with OpenCV 3.4.2, it gives a different image where many pixels have a different value. Most of the absolute values differ only 1 and 2, but the most extreme difference values I've seen in the tests are in range of [-9, 9].

In code, some checks I did:

import cv2
import skimage.io
import numpy as np
           
image_cv2 = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
image_skimage = skimage.io.imread(image_path)
diff = np.subtract(image_cv2.astype(np.float), image_skimage.astype(np.float))

print(np.sum(image_cv2), np.sum(image_skimage))
print(np.array_equal(image_cv2, image_skimage))
print(np.min(diff), np.max(diff))

Is it a bug in the recent cv2.imread implementation? Or is there a specific reason for the change in output?

@alalek

This comment has been minimized.

Copy link
Contributor

alalek commented Aug 29, 2018

JPEG is not bit-exact format. Use PNG if you want bit-exact results.

OpenCV is switched to libjpeg-turbo (by default in case of building libjpeg from sources, but general builds can reuse system library).

@gilbertfrancois

This comment has been minimized.

Copy link
Author

gilbertfrancois commented Aug 29, 2018

Ok, thanks.

@yzsatgithub

This comment has been minimized.

Copy link

yzsatgithub commented Dec 16, 2018

I came with exactly the same problem -- reading jpeg image between 3.4.0 and 3.4.2
Is there a neat way to install opencv 3.4.0 with conda ? () @alalek
My system is Ubuntu 14.04

Besides, can version 3.4.1 reads the same values as 3.4.0 does?

@yzsatgithub

This comment has been minimized.

Copy link

yzsatgithub commented Dec 16, 2018

I came with exactly the same problem -- reading jpeg image between 3.4.0 and 3.4.2
Is there a neat way to install opencv 3.4.0 with conda ? () @alalek
My system is Ubuntu 14.04

Besides, can version 3.4.1 reads the same values as 3.4.0 does?

I found that conda doesn't support 3.4.0 . But I managed to install it using pip.
pip install opencv-python==3.4.0.12

Hope it will help those who would come here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.