小编xiu*_*sir的帖子

PIL.Image.open 和 tf.image.decode_jpeg 返回值的区别

我使用 PIL.Image.open 和 tf.image.decode_jpeg 将图像文件解析为数组。但是发现PIL.Image.open()中的像素值和tf.image.decode_jpeg不一样。为什么会发生这种情况?

谢谢 !

代码输出:

tf 100 100 [132 145 161]
pil 100 100 [134 147 164]
Run Code Online (Sandbox Code Playgroud)

我的代码:

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from datetime import datetime
import math
import time

import numpy as np
import tensorflow as tf

def decode_jpeg(image_file):
  from PIL import Image
  im = Image.open(image_file)
  data = np.array(im)
  return data

def tfimageread(filenames):
  filename_queue = tf.train.string_input_producer(filenames)
  reader = tf.WholeFileReader(name='image_reader')
  key, value = reader.read(filename_queue)
  uint8image = tf.image.decode_jpeg(value, channels=3)

  with …
Run Code Online (Sandbox Code Playgroud)

python image python-imaging-library tensorflow

5
推荐指数
1
解决办法
1205
查看次数