normalization of image data for neural network
조회 수: 5 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (1개)
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);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!