Day and Night Image data Standardization

import resource

import cv2 # computer vision library
import helpers

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

%matplotlib inline

训练/测试数据

# Image data directories
image_dir_training = "day_night_images/training/"
image_dir_test = "day_night_images/test/"
IMAGE_LIST = helpers.load_dataset(image_dir_training)

可视化数据

# Print out 1. The shape of the image and 2. The image's label

# Select an image and its label by list index
image_index = 0
selected_image = IMAGE_LIST[image_index][0]
selected_label = IMAGE_LIST[image_index][1]

# Display image and data about it
plt.imshow(selected_image)
print("Shape: "+str(selected_image.shape))
print("Label: " + str(selected_label))

Day and Night Image data Standardization_第1张图片

预处理数据

输入

输入数据应该相同尺寸,相同形式。这里我们将图片尺寸修订在600*1100

def standardize_input(image):
    standedinput = cv2.resize(image, (1100, 600))
    return standedinput
输出
# encode("day") should return: 1
# encode("night") should return: 0

def encode(label):
        
    numerical_val = 0
    ## TODO: complete the code to produce a numerical label
    if(label == 'day'):
        numerical_val = 1
    return numerical_val

def standardize(image_list):
    
    # Empty image data array
    standard_list = []

    # Iterate through all the image-label pairs
    for item in image_list:
        image = item[0]
        label = item[1]

        # Standardize the image
        standardized_im = standardize_input(image)

        # Create a numerical label
        binary_label = encode(label)    

        # Append the image, and it's one hot encoded label to the full, processed list of image data 
        standard_list.append((standardized_im, binary_label))
        
    return standard_list

# Standardize all training images
STANDARDIZED_LIST = standardize(IMAGE_LIST)

Visualize the standardized data

# Select an image by index
image_num = 0
selected_image = STANDARDIZED_LIST[image_num][0]
selected_label = STANDARDIZED_LIST[image_num][1]

# Display image and data about it
## TODO: Make sure the images have numerical labels and are of the same size
plt.imshow(selected_image)
print("Shape: "+str(selected_image.shape))
print("Label [1 = day, 0 = night]: " + str(selected_label))
Day and Night Image data Standardization_第2张图片

你可能感兴趣的:(Day and Night Image data Standardization)