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

Different results from scipy imread and tensorflow decode_jpeg #11623

Closed
HaaPut opened this issue Jul 19, 2017 · 4 comments
Closed

Different results from scipy imread and tensorflow decode_jpeg #11623

HaaPut opened this issue Jul 19, 2017 · 4 comments

Comments

@HaaPut
Copy link

HaaPut commented Jul 19, 2017

Problem Description

Image decoded using decode_jpeg from tensor flow is visually similar, but numerically different from one returned by scipy imread.

Minimal Example:

import numpy as np
import scipy
import tensorflow as tf
def minimal_example():
    #image_source = 'https://upload.wikimedia.org/wikipedia/commons/8/88/Astronaut-EVA.jpg'
    image_path = 'astronaut.jpg'
    image_file = open(image_path,'rb')
    image_raw = image_file.read()
    image_scipy = scipy.misc.imread(image_path)
    image_tf = tf.image.decode_jpeg(image_raw).eval(session=tf.Session())
    print('Error: ', np.sum(np.abs(image_tf - image_scipy)))
    #Error:  3420883624

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux Ubuntu 16.04
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version (use command below): v1.2.0-rc2-21-g12f033d 1.2.0
  • Python version: 3.5
@yangda75
Copy link

I can reproduce the result with exactly the same error using the same image and code.
Can this be caused by decoders' differences? Since scipy.misc.imread uses pillow, tf.image.decode_jpeg still functions without pillow.

system information

  • OS: Fedora 26
  • Python version: 3.5.3
  • Python related management tool: Anaconda 3
  • Tensorflow(installed via conda install) version: 1.1.0, np112py35_0

printed a small portion of the results

[1:10,:,2] scipy image
 [[0 0 0 ..., 0 2 1]
 [0 0 0 ..., 0 5 4]
 [0 0 0 ..., 0 5 4]
 ..., 
 [0 0 2 ..., 0 5 5]
 [0 0 0 ..., 0 3 0]
 [0 0 0 ..., 3 3 0]]
[1:10,:,2] tf image
 [[0 0 0 ..., 0 0 0]
 [0 0 0 ..., 0 3 4]
 [0 0 0 ..., 0 3 4]
 ..., 
 [0 0 0 ..., 0 3 3]
 [0 0 0 ..., 0 2 0]
 [0 0 0 ..., 0 2 0]]

@drpngx
Copy link
Contributor

drpngx commented Jul 19, 2017

We use libjpeg. I am not sure what your application is. If you really need this, I would recommend writing your own op on top of pillow.

I am going to close this, since I don't think it warrants changing the TF core.

@drpngx drpngx closed this as completed Jul 19, 2017
@HaaPut
Copy link
Author

HaaPut commented Jul 20, 2017

I think the reason for this difference is that Tensorflow used fast integer DCT as a default decode jpeg image

// The TensorFlow-chosen default for jpeg decoding is IFAST, sacrificing

@drpngx
Copy link
Contributor

drpngx commented Jul 20, 2017

Oh yes, I remember some discussion about that. I think we change the default but the other version is available through options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants