在我看来,图像归一化是将每个像素的值归一化为0到1之间的数值,对吗?
但是下面的代码是什么意思呢?
image_size = 28 # 像素宽度和高度。
pixel_depth = 255.0 # 每个像素的级别数。
for image in image_files:
image_file = os.path.join(folder, image)
try:
image_data = (ndimage.imread(image_file).astype(float) -
pixel_depth / 2) / pixel_depth # 为什么??
if image_data.shape != (image_size, image_size):
raise Exception('意外图像形状: %s' % str(image_data.shape))
dataset[num_images, :, :] = image_data
num_images = num_images + 1
except IOError as e:
print('无法读取:', image_file, ':', e, '- 没关系,跳过。')
回答:
图像归一化仅仅是改变像素强度值范围的过程。
新范围的选择取决于你。
在你展示的案例中,看起来选择了-0.5到0.5的范围。