Getting Standard Deviation for Image based on normalized color band

5 views (last 30 days)
I need to evaluate the SD for an imported image (PNG). The thing is the image actually represents a color band from 0 - 1 (blue - red) and the SD is calculated for the about the mean i.e SD of (conc - 0.5). How do I implement this in MATLAB? I tried using mat2gray to normalize the matrix and used std2 but the result doesn't quite match. It seems I need to normalize on the band -0.5 to 0.5 but not really sure. Suggestions?

Accepted Answer

Chitrarth  Lav
Chitrarth Lav on 2 Aug 2015
I tried both your suggestions but it doesn't seem to give me the right answer. I am including the image. To give more clarity to the problem, in this image, the colors represent the concentration of a species, let's say c. The blue region represents c as 0 while the red region is 1 and green is around 0.5. The software where I generated the image calculates the SD for this image at 0.1486 while your suggestions for the same don't give me the expected result.
  5 Comments
Chitrarth  Lav
Chitrarth Lav on 2 Aug 2015
No. Based on a simulation I did on a CFD software, this represents the species concentration on a cross section. I need to validate the codes generated SD to one given by MATLAB. So what, you're suggesting is I generate a matrix for this image instead and then use that for the SD?
Image Analyst
Image Analyst on 2 Aug 2015
Yes. If you can export the matrix itself , rather than a pseudocolored version of it, that would of course be much much better because you'd have the actual values and there would be no need to "undo" the color map.

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 1 Aug 2015
std() always subtracts the mean so you do not need to shift the mean before you do std().
However, std() is sensitive to the range of values: multiplying the range by a factor of alpha multiplies the standard deviation by alpha.
  2 Comments
Chitrarth  Lav
Chitrarth Lav on 1 Aug 2015
Okay. But when I print the image and add the colorbar, the range goes from 0 to 60 ish whereas the place where I imported the image from had it from 0-1. How do I get the Matlab colorbar range to the one I need?
Walter Roberson
Walter Roberson on 1 Aug 2015
PNG files cannot store floating point, so you will find that the data read in is in the range 0 to 255 (or less.) im2double() will convert that to the 0 to 1 range.

Sign in to comment.


Image Analyst
Image Analyst on 2 Aug 2015
Are you saying that you have a PNG image that goes from blue to red, so that the green channel is always 0. And if the color is pure blue (red component = 0) then this represents a "0" and if the color is pure red (with a blue component = 0) then this represents a 1? So that the blue plus red components added together always give 255? If so, you can convert this image into a 0 to 1 image this way
rgbImage = imread(filename);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Create an image where blue goes to 0, red goes to 1
% and it's linearly scaled in between based on how much blue and red there is.
outputImage = double(redChannel) / 255;
% Now get the standard deviation
stDev = std(outputImage);

Community Treasure Hunt

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

Start Hunting!