Help with structs. Using Regionprops output and ismember.

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
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

Ian
Ian am 22 Mär. 2014
Bearbeitet: Ian am 22 Mär. 2014
I'm building a road extraction program, which I've managed to do through thresholding and K-means methods, and now I'm attempting to improve the results by elimainating objects detected that are not roads. I was thinking along the lines of 'roads are long and thin' and the noise I've detected (such as carparks) are usually rounder/squarer. I've decided using extent with regionprops is probably a better idea. From what you've said it sounds like Circularities will do something similar so I'll give that a go and compare. Do you have any suggestions on how to remove noise that is apart of the object? Would I erode the image and then do more work with regionprops?
Thanks for the response
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
Ian am 22 Mär. 2014
No, the noise is 'a part' of the object, as you said. I have already removed small, unconnected noise. I've used ismember already and I've managed to correctly identify all the roads but have also retained some noise. I'm going to repeat my thresholding process again I think and see if that will bring any joy. Any suggestions? Thanks a lot.
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.
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!

Melden Sie sich an, um zu kommentieren.

Gefragt:

Ian
am 21 Mär. 2014

Kommentiert:

am 22 Mär. 2014

Community Treasure Hunt

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

Start Hunting!

Translated by