I am trying to write a program to standardize an image which I need to better perform image classification. I found the definition of standardisation which is obtained simply by subtracting the mean pixel from every pixel, and then dividing by the standard deviation.

What I don't understand if this has to be done (1) component by component:

  • Calculate mean alpha, alpha standard deviation, and then subtract the mean alpha and divide by the standard deviation of alpha, for every alpha component of every pixel
  • Same for the RGB components

Or (2) value by value. Every pixel can be stored as an integer of 32 bits and I could calculate the mean and the standard deviation of every pixel intended as a 4 bytes integer, and do every of the above operations using 32 bits integers.

Both approaches produce different results but it's not clear to me which one is the most effective for image standardization intended as a way to get a better image classification algorithm.

  • $\begingroup$ Could you please review my answer? If it fits you, could you mark it? $\endgroup$
    – Royi
    Commented May 30, 2023 at 7:51

1 Answer 1


I will display image standardization using MATLAB:

mI = im2single(imread('ImageFileName.png')); %<! Assuming RGB Image
numRows = size(mI, 1);
numCols = size(mI, 2);

% Reshaping the image into 3 columns where each column is the whole pixels of a channel
mI = reshape(mI, numRows * numCols, 3);

vMeanVal = mean(mI, 1);
vStdVal  = std(mI, 1);

mI = (mI - vMeanVal) ./ vStdVal;

mI = reshape(mI, numRows, numCols, 3); %<! Going back into image form

Basically we calculated the mean value and the standard deviation per channel and normalized per channel. It was done per image.

When working on a set of images, sometimes, we learn the mean value and the standard deviation per channel for the whole set and then use those numbers for any image (Both on training and testing).

  • 1
    $\begingroup$ So for the whole dataset the columns should be composed by all images? $\endgroup$ Commented Mar 13, 2022 at 10:22
  • $\begingroup$ @EricJohnson, Indeed. We calculate the mean of the R channel of all images, and doing that also for G and B channels. $\endgroup$
    – Royi
    Commented Mar 13, 2022 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.