Help with structs. Using Regionprops output and ismember.
Ältere Kommentare anzeigen
Hello everyone, I have the basic idea but I've struggling to finish this part. I'm using the Area and Perimeter output of regionprops to determine the ratio of Area to Perimeter for each object. I then want to only keep the objects above a certain threshold of this ratio. The below code works but I'm only receiving one value for my ratio. If I change it to '
Ratio{i}=Perimeter{i}./Area{i};'
Then I get the ratio correctly, for all objects but then the last section doesnt work correctly. I think the issue is that I'm not saving it correctly and I'm confused if I need a struct, cell etc.
Any help is greatly appreciated
Many thanks
groupdata=regionprops(CC,RoadClusterBinary,'Centroid','Eccentricity','Pixellist','Area','Perimeter');
Area=[]; Perimeter=[]; Ratio=[];
for i=1:CC.NumObjects;
Area{i}=(groupdata(i).Area(1));
Perimeter{i}=(groupdata(i).Perimeter(1));
Ratio=Perimeter{i}./Area{i};
end
AllowableRatio= (Ratio >=0.03);
keeperindex=find(AllowableRatio);
keeping=ismember(IL,keeperindex);
new=bwlabel(keeping);
figure, imshow(new, []);
EDIT:
Incase; IL is the output from;
CC = bwconncomp(RoadClusterBinary,8);
IL = bwlabel(RoadClusterBinary);
Maybe best for me to add my 'ratio' as a field to output struct from regionprops..? How would I do that..?
Antworten (1)
Image Analyst
am 22 Mär. 2014
Looks like you could really benefit from my Image Segmentation Tutorial: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Basically you want to do this:
allAreas = [groupdata.Area];
allPerimeters = [groupdata.Perimeter];
allRatios = allAreas ./ allPerimeters; % Calculate some strange ratio.
Not sure what the ratio represents - I've never seen that one before. I don't know how to interpret that. It has units of length but I don't know what length it's supposed to represent. Much much more common is to calculate the circularities :
allCircularities = (allPerimeters .^ 2) ./ (4*pi*allAreas);
which will = 1 for a circle and get bigger the more tortuous the shape or boundary is.
5 Kommentare
Image Analyst
am 22 Mär. 2014
Yes, you'd want to use the circularities, not the ratio you thought of. If you knew that the blobs were rectangles then you could divide the area by the length to get the width (which should be a small number) but dividing by both the length and width added together doesn't make sense, at least not to me.
Not exactly sure what you mean by "that is apart of the object" - I don't understand the grammar. Do you mean separate from the object or "a part" of the object? Is the noise a completely separate regions that is all noise, or is there some part of the object that is noise and was not well segmented and you still need to exclude or detach it? To get rid of small, separate noise, try getting the area's of all of them and using ismember, like in my tutorial, to get rid of small blobs. This is essentially what bwareaopen() does - you can use that if you want - it calls regionprops() internally.
Ian
am 22 Mär. 2014
Image Analyst
am 22 Mär. 2014
It's hard to give image processing advice without seeing an image, don't you think? Attach images and code to illustrate what you are talking about.
Image Analyst
am 22 Mär. 2014
If you want something that is robust, and doesn't just work on this one photo, then you're going to have to look into the robust algorithms published here: http://iris.usc.edu/Vision-Notes/bibliography/contentscartog.html#Cartography,%20Aerial%20Images,%20Remote%20Sensing,%20Buildings,%20Roads,%20Terrain,%20ATR No simple 2 or 3 hundred line long program is going to be robust enough to handle lots of pictures like this. You're going to need to put some work into it, which those people already have so just do what they did!
Kategorien
Mehr zu Image Arithmetic finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!