Plotting the area of an object in grayscale against its intensity level in the grayscale image
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Image Analyst
le 13 Fév 2014
Do you mean how do you show the boxed area values over your original image in all 91 threshold cases? Try this:
img = rgb2gray(imread('W1\Writer1_01_02.jpg'));
figure;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
plotNumber = 1;
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'});
subplot(10,10,plotNumber);
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
plotNumber = plotNumber + 1; % Move to the next plot for next iteration.
end
2 commentaires
Image Analyst
le 13 Fév 2014
You can get the total area of all regions above the threshold simply by taking the cumulative distribution function of the histogram:
areaAboveThresh = cumsum(pixelCounts);
but that's the area of all regions summed together. If you want it by blob, then you need to decide what you're going to do when the blobs start merging together.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Image Processing Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!