Histogram operations with Color-based image analysis.

6 views (last 30 days)
So I am working on a multi=image analyzer hat will be able to analyze color images. what needs to be done is to generate a histogram and determine (1) the peak frequency(RGB Value) of absorption, (2) the range of frequencies(RGB Values where the pixel value > 0), and (3) the area under the histogram curve (AUC). Here is what I have so far:
% this doesnt matter
fontSize = 24;
% Read in standard MATLAB color demo image.
rgbImage = imread('1.jpg');
[rows columns numberOfColorBands] = size(rgbImage);
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original Color Image', 'Fontsize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
redPlane = rgbImage(:, :, 1);
greenPlane = rgbImage(:, :, 2);
bluePlane = rgbImage(:, :, 3);
% Let's get its histograms.
[pixelCountR grayLevelsR] = imhist(redPlane);
subplot(2, 2, 2);
plot(pixelCountR, 'r');
findpeaks(imhist(redPlane))
%{
mingrayLevelsR = find(pixelCountR > 0, 1, 'first');
maxgrayLevelsR = find(pixelCountR > 0, 1, 'last');
minCounts = min(pixelCountR(:));
maxCounts = max(pixelCountR(:));
%}
Rmax = max(pixelCountR)
%rangeR = (max(grayLevelsR) - min(grayLevelsR))
%Y = prctile(pixelCountR,80)
title('Histogram of red plane', 'Fontsize', fontSize);
xlim([0 grayLevelsR(end)]); % Scale x axis manually.
[pixelCountG grayLevelsG] = imhist(greenPlane);
subplot(2, 2, 3);
plot(pixelCountG, 'g');
findpeaks(imhist(greenPlane))
Gmax = max(pixelCountG)
title('Histogram of green plane', 'Fontsize', fontSize);
xlim([0 grayLevelsG(end)]); % Scale x axis manually.
[pixelCountB grayLevelsB] = imhist(bluePlane);
subplot(2, 2, 4);
plot(pixelCountB, 'b');
findpeaks(imhist(bluePlane))
Bmax = max(pixelCountB)
title('Histogram of blue plane', 'Fontsize', fontSize);
xlim([0 grayLevelsB(end)]); % Scale x axis manually.
message = sprintf('Peak Red = %.3f\nPeak Green = %d\nPeak Blue = %.2f\n', ...
Rmax, Gmax, Bmax );
msgbox(message);
Rmax, Gmax, and Bmax denotes the maximum peak of pixels I have within each color band (I think). What I need to do now is to (1) Generate the coordinates for Rmax...etc. This would show what pixel intensity it is. (155 or 200. Something similar to that) (2) Generate a range where where the pixel value > 0 (if you dont do > 0 then it comes back with 255) (3) Generate a curve from the histogram (4) Find the area under the curve.
How can I accomplish these tasks?
P.S. Is it possible to generate Vl frequencies from an image? It is almost essential

Answers (1)

Image Analyst
Image Analyst on 6 Sep 2015
There's a lot of wasted code there. Like calling findpeaks(), find(), computing minCounts, etc. Anyway, if you simply want to find the gray level where the mode (most frequently occuring gray level, which will have the highest peak in the histogram) occurs, call mode:
modeRed = mode(redPlane(:));
modeGreen = mode(greenPlane(:));
blueRed = mode(bluePlane(:));
Then if you want to find the first and last gray level:
minRed = min(redPlane(:));
maxRed = max(redPlane(:));
minGreen = min(greenPlane(:));
maxGreen = max(greenPlane(:));
minBlue = min(bluePlane(:));
maxBlue = max(bluePlane(:));
If you still want the histogram, then you can find those from the histogram. For red, you'd do this:
[greatestCountR, modeRedIndex] = max(pixelCountR);
modeRedGrayLevel = grayLevelsR(modeRedIndex);
Same for green and blue.
  2 Comments
John Conson
John Conson on 6 Sep 2015
What about finding the curve and the area under the curve?
Image Analyst
Image Analyst on 6 Sep 2015
What curve? The histogram? That's simply the count of the number of pixels. You can use sum().

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!