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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by