How to get Areas of Specified Objects in an Image?
10 views (last 30 days)
Show older comments
I have been trying to take an image and divide it up into regions, and then calculate various properties of those regions. A sample image is linked: <http://tinypic.com/view.php?pic=esq2it&s=7>
I have been running the following code:
close all;
clear all;
RGB = imread('vir1036.tif');
threshold = graythresh(RGB);
BW = im2bw(RGB,threshold);
L = bwlabel(BW);
imshow(BW)
figure
imagesc(L)
I am new at MATLAB and still learning about all of these commands. As you can see, there is some noise, but bwlabel has identified most of the regions I was targeting (the regions in various colors of blue). I would like to be able to find the area of each of those regions separately. Is there a way to clean up this image so that it find all of the regions I was targeting, and do you have any suggestions for how to find the areas of each of those regions?
Thank you in advance for any help!
0 Comments
Accepted Answer
Sean de Wolski
on 20 Jul 2011
Edit Per Comments
%%Answers 7/21
I = imread('coins.png');
Ibw = I>100;
Edited Again
Ibw = bwareaopen(Ibw,20); %remove eveyr object with less than 20px.
CC = bwconncomp(Ibw);
imshow(Ibw);
H = msgbox('Click on Object of Interest');
uiwait(H);
while 1
[x y] = ginput(1);
Pxidx = sub2ind(size(Ibw),round(y),round(x)); %pixel linear index
Objidx = cellfun(@(x)any(x==Pxidx),CC.PixelIdxList); %what object?
if ~any(Objidx)
H = errordlg('Doh! You didn''t select a valid object');
uiwait(H);
H = msgbox(sprintf('Let''s try again\nClick on Object of Interest'));
uiwait(H);
else
break;
end
end
ObjArea = numel(CC.PixelIdxList{Objidx}); %get area
msgbox(sprintf('Area is %i Px',ObjArea)); %show area
14 Comments
Sean de Wolski
on 21 Jul 2011
In my image none of the areas were below 800!!! They were the sizes that I showed you four comments ago.
More Answers (2)
MUHAMMED EROL
on 4 Jan 2020
PERİMETER?
2 Comments
Image Analyst
on 4 Jan 2020
In short
props = regionprops(binaryImage, 'Perimeter');
allPerimeters = [props.Perimeter]
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!