Help with structs. Using Regionprops output and ismember.

8 views (last 30 days)
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..?

Answers (1)

Image Analyst
Image Analyst on 22 Mar 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 Comments
Image Analyst
Image Analyst on 22 Mar 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
Image Analyst on 22 Mar 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!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!