Plotting the area of an object in grayscale against its intensity level in the grayscale image
Show older comments
Basically what I am trying to produce is the histogram of the image at varying grayscale intensities showing me the area of the connected components in the image.
Let me explain further, I plan on finding the areas of all the connected components of the image at varying threshold levels. Then combine them all in a graphical way and show them plotted against the intensity level of a grayscale image i.e. 0 - 255.
I hope my code will explain what I am trying to do.
img = rgb2gray(imread('W1\Writer1_01_02.jpg'));
for k = 1:-0.01:0.1
bw_normal = im2bw(img, k);
bw = imcomplement(bw_normal);
[label,n] = bwlabel(bw);
stats = regionprops(label,img, {'Area', 'Centroid'});
plot([stats.Area],k,'o');
axis([0 1000 0.1 1])
hold on;
end
As you can tell I used a for loop to produce a the varying threshold level, calculate the areas of the CC and plot them against the selected threshold level. This is what it produces:

this is not what I want. I am trying to replicate this result. It does not have to look exactle like this but anything closely similar would do

I then found out that I can find the properties of CC from the grayscale image directly using
STATS = regionprops(..., I, properties)
So I wrote this:
img = rgb2gray(imread('W1\Writer1_01_02.jpg'));
for k = 1:-0.01:0.1
bw_normal = im2bw(img, k);
bw = imcomplement(bw_normal);
[label,n] = bwlabel(bw);
stats = regionprops(label,img, {'Area', 'Centroid'});
% plot([stats.Area],k,'o');
% axis([0 1000 0.1 1])
imshow(img);
hold on;
for j = 1:numel(stats)
text(stats(j).Centroid(1),stats(j).Centroid(2), ...
sprintf('%2.1f', stats(j).Area), ...
'EdgeColor','b','Color','r');
end
end
This produced the following:

So now I have found the areas of the connected components in grayscale. How do I plot them to show as my desired output (the blue one I showed above)?
thank you for reading
Accepted Answer
More Answers (0)
Categories
Find more on Contrast Adjustment in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!