2017-01-02 80 views
-2

在我下面的算法中,resize_images将我的图像的颜色更改为错误。为什么?我的形象是375行1242科拉姆3通道tensorflow调整图像颜色变化

# Typical setup to include TensorFlow. 
import tensorflow as tf 
import matplotlib.pyplot as plt 

# Make a queue of file names including all the JPEG images files in the relative 
# image directory. 
filename_queue = tf.train.string_input_producer(
    tf.train.match_filenames_once("./MNIST_data/*.png")) 

reader = tf.WholeFileReader() 
key, value = reader.read(filename_queue) 

image_f = tf.image.decode_png(value) # use png or jpg decoder based on your files. 
image = tf.image.resize_images(image_f, [375, 1242]) 

#Generate batch 
# num_preprocess_threads = 1 
# min_queue_examples = 256 
# batch_size=2; 
# images = tf.train.shuffle_batch(
    # [image], 
    # batch_size=batch_size, 
    # num_threads=num_preprocess_threads, 
    # capacity=min_queue_examples + 3 * batch_size, 
    # min_after_dequeue=min_queue_examples) 

init_op = tf.initialize_all_variables() 

with tf.Session() as sess: 
    sess.run(init_op) 

    # Start populating the filename queue. 
    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(coord=coord) 
    my_image = image.eval() #here is your image Tensor :) 
    print(my_image.shape) 
    fig = plt.figure() 
    plt.imshow(my_image) 
    plt.show() 

    coord.request_stop() 
    coord.join(threads) 

它看起来像我的帖子主要是代码,所以我增加了一些更多的细节,它看起来像我的帖子主要是代码,所以我增加了一些更detailsit看起来像我的帖子主要是代码,所以我增加了一些更detailsit看起来像我的帖子主要是代码,所以我增加了一些更detailsit看起来像我的帖子主要是代码,所以我增加了一些细节

+1

你认为StackOverflow是一些编码服务吗?这是您在2天内提出的第6个问题! – martianwars

回答

1

tf.resize_images文件引用,

调整大小的图像将被扭曲,如果他们原来的asp等比例与大小不一样。为避免失真,请参阅resize_image_with_crop_or_pad

您的纵横比不正确,所以由于扭曲图像的颜色似乎在变化。如果您不希望发生这种情况,请使用resize_image_with_crop_or_pad


请开始阅读文件。他们将回答超过一半的问题。