2017-01-02 111 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


請開始閱讀文件。他們將回答超過一半的問題。