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.
Getting Standard Deviation for Image based on normalized color band
5 views (last 30 days)
Show older comments
Chitrarth Lav
on 1 Aug 2015
Commented: Image Analyst
on 2 Aug 2015
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?
0 Comments
Accepted Answer
Chitrarth Lav
on 2 Aug 2015
5 Comments
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.
More Answers (2)
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
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.
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);
0 Comments
See Also
Categories
Find more on Red in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!