How to find the histogram of multiple images loaded from a single folder

Hi, I am using matlab R2010a. I have loaded 12 images from a folder . I am also able to display the images. But i find it difficult to further process the images. I have stored the images in a cell. How to find the histogram of the images ?

 Accepted Answer

My attached demo (below in blue text) does exactly that, and produces nice figures for every image in the folder:

10 Comments

Thanks . The histogram is nicely shown .But i am working with grayscale images. Can the histogram be plotted in the same manner for a thresholded image also?
Of course. But a thresholded image will have only two values, 0 and 1, in the histogram.
I need to further process the images. I.e Getting the variance , entropy,relative smoothness of all the images. But when i do so, i dont get the values in the command window.
Here is the code:
for k = 1 : numberOfImagesProcessed
baseFileName = imageFiles(k).name;
[pixelCounts GLs] = imhist(redChannel, 256);
numberOfPixels(k) = sum(pixelCounts);
meanGL(k) = sum(GLs(k) .* pixelCounts) / numberOfPixels;
% Get the variance, which is the second central moment.
% variational element of the histogram of the image
varianceGL(k) = sum((GLs - meanGL) .^ 2 .* pixelCounts) / (numberOfPixels(k)-1);
% Get the standard deviation.
sd(k) = sqrt(varianceGL(k));
% Get the skew.- level of relative inclination of the image
% histogram
skew(k) = sum((GLs(k) - meanGL(k)) .^ 3 .* pixelCounts) / ((numberOfPixels(k) - 1) * sd(k)^3);
% Get the kurtosis. -
kurtosis(k) = sum((GLs(k) - meanGL(k)) .^ 4 .* pixelCounts) / ((numberOfPixels(k) - 1) * sd(k)^4);
%Get the relative smoothness
rs(k)=1-(1/(1+sd(k).^2));
fprintf(1, '%24s %6.2f, %6.2f, %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n', ...
baseFileName, redChannel_Mean(k), greenChannel_Mean(k), blueChannel_Mean(k),redChannel_Entropy(k),meanGL(k),varianceGL(k),sd(k),skew(k),kurtosis(k),rs(k));
Are you saying that fprintf() is not working? Step through it with the debugger. What happens when you hit fprintf()? Nothing at all???
Does it even get into the loop? What is the value of numberOfImagesProcessed? Note that my code had numberOfImagesToProcess in the for statement, not numberOfImagesProcessed like you changed it to. numberOfImagesProcessed is probably zero so it won't enter the loop. Why did you change it?
No its not with fprintf(). And also i have changed it to numberOfImagesToProcess from numberOfImagesProcessed .But still i get an error that "Matrix Dimensions must agree".
When you step through with the debugger and get to the line where it errors, what are the matrix dimensions of all matrices on that line? Please give ALL THE RED TEXT, not just a small snippet from it.
I have attached the m file of it. The error is shown on the following line: [pixelCounts GLs] = imhist(redChannel, 256);
You have probably figured it out by now, but the code you added after mine is not correct. Especially this line:
[pixelCounts GLs] = imhist(redChannel, 256);
You're never changing redChannel so it is the same at each iteration of your loop, which means pixelCounts is always the same, standard deviation is always the same, and so on.
Ya. So how can i find the pixelcount and grayscale value for every image in the loop. Should i change the loop condition?
Well, I do that, in my code don't I? You can see the histograms (pixel counts) of every color channel in every image. Just look what I did.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!