python处理mat数据和处理png的区别_Python---利用scipy.misc等库对jpg以及png等图像数据预处理(用于深度学习喂数据)...

这篇博客介绍了如何使用Python的scipy库对jpg和png图像进行预处理,包括读取、调整大小和数据增强,为深度学习模型提供输入数据。文章还展示了如何找到对应的png注释文件,并提供了批量处理和数据分批的方法。
摘要由CSDN通过智能技术生成

转载自:http://blog.csdn.net/qq_16949707/article/details/56306720import os

import glob

image_dir = "D:\\data\\ADEChallengeData2016"

file_glob = os.path.join(image_dir, "images", "training", '*.' + 'jpg')

file_list = []

file_list.extend(glob.glob(file_glob))

1

2

3

4

5

6

file_list_test = file_list[0:10]

1

import random

random.shuffle(file_list_test)

1

2

import numpy as np

import scipy.misc as misc

1

2

def read_and_transform(filename):

image = misc.imread(filename)

resize_image = misc.imresize(image,[224, 224], interp='nearest')

return np.array(resize_image)

1

2

3

4

images = np.array([read_and_transform(filename) for filename in file_list_test])

1

def find_annotations_image_path(image_path):

return image_path.replace("images","annotations").replace("jpg","png")

1

2

annotations_file_list_test = [find_annotations_image_path(image_path) for image_path in file_list_test]

1

annotations = np.array([np.expand_dims(read_and_transform(filename), axis=3) for filename in annotations_file_list_test])

1

batch_offset = 0

1

def next_batch(batch_size,batch_offset,images,annotations,epochs_completed):

start = batch_offset

batch_offset += batch_size

if batch_offset > images.shape[0]:

# Finished epoch

epochs_completed += 1

print("****************** Epochs completed: " + str(epochs_completed) + "******************")

# Shuffle the data

perm = np.arange(images.shape[0])

np.random.shuffle(perm)

images = images[perm]

annotations = annotations[perm]

# Start next epoch

start = 0

batch_offset = batch_size

end = batch_offset

print start,end

# return images[start:end], self.annotations[start:end]

1

2

3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值