前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Day and Night Image data Standardization

Day and Night Image data Standardization

作者头像
小飞侠xp
发布2018-08-28 17:53:32
4570
发布2018-08-28 17:53:32
举报
import resource
代码语言:javascript
复制
import cv2 # computer vision library
import helpers

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

%matplotlib inline
训练/测试数据
代码语言:javascript
复制
# 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)
可视化数据
代码语言:javascript
复制
# 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))
预处理数据
输入

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

代码语言:javascript
复制
def standardize_input(image):
    standedinput = cv2.resize(image, (1100, 600))
    return standedinput
输出
代码语言:javascript
复制
# 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
代码语言:javascript
复制
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
代码语言:javascript
复制
# 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))
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.08.05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • import resource
  • 训练/测试数据
  • 可视化数据
  • 预处理数据
    • 输入
      • 输出
      • Visualize the standardized data
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档