normalization of image data for neural network

5 ビュー (過去 30 日間)
Joakim Kargaard
Joakim Kargaard 2018 年 2 月 27 日
回答済み: Pooja Sethia 2018 年 3 月 7 日
Hi,
I have greyscale images, resized to 32x32 pixels. I need to normalize the images before training a neural network. From my reading, I need to normalize by subtracting the mean from each pixel and then dividing by the standard deviation. The pixel numbers should be positive, so scaling should be in the range [0,1]. I am new to matlab so trying things out to figure out what I need to do. I ran: I = imread('file'); Image = magic(32) means = conv2(Image, ones(3)/(3*3), 'valid) This seems to find the means of each pixel (I believe). But, is there a way of getting matlab to subtract the mean from each pixel and then divide by the standard deviation and if so, what would the code be?
I would appreciate any help.
Thanks.

回答 (1 件)

Pooja Sethia
Pooja Sethia 2018 年 3 月 7 日
Hi,
'mean2' and 'std2' commands are used to find mean and standard deviation of a matrix. Since a greyscale image is a matrix of intensity values of grey color we can use those functions. You can refer to the below example to normalize an image by subtracting the mean from each pixel and then dividing by the standard deviation.
image = im2double(imread('imagefilename'));
subplot(1, 2, 1);
imshow(image);
title('Original Image', 'FontSize', 20);
image = rgb2gray(image);
image = (image - mean2(image))./std2(image);
subplot(1, 2, 2);
imshow(image);
title('Output image', 'FontSize', 20);

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by