简体   繁体   English

使用 Tensorflow 处理图像

[英]Processing an Image using Tensorflow

I've a 15 images which are stored locally.我有 15 张图像存储在本地。 How do I transform these images to a array using tensorflow for a CNN type of Classification?如何使用 tensorflow 将这些图像转换为数组以进行 CNN 类型的分类?

Convert the image to numpy array format将图像转换为 numpy 数组格式

import cv2
im = cv2.imread("some_image.tiff")

Reshape them to an arbitrary, but identical, size将它们重塑为任意但相同的大小

def reshape(image_array):
    return np.reshape(image_array, [128, 128, 3])

Put them all in a list and then standardize them so they all have standardized pixel values using:将它们全部放在一个列表中,然后使用以下方法对它们进行标准化,以便它们都具有标准化的像素值:

def per_image_standardization(arrays):
    sess = tf.InteractiveSession()
    standardized_tensors = tf.map_fn(lambda array:                            
        tf.image.per_image_standardization(array), 
                                           arrays)
    standardized_images = standardized_tensors.eval()
    return standardized_images

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM