How to remove entries form a struct array?

1 view (last 30 days)
Hi,
so I'm trying to remove certain entries from a struct array that I created using regionprops for extracting features from a segmentation.
[labeled, numObjects]= bwlabel(Iopenned, 4);
stats= regionprops(labeled, 'Eccentricity', 'Area', 'BoundingBox');
So 'Iopenned' is my segmented image which shows a binary image of circles. Due to the orignal image some areas of my segmentation (the circles) are connectet and therefore counted as one big circle (outer ring in the segmentation attachment). I would like to sort these kind of 'mistakes' out. Something like every identified circle with an area bigger than 300 will be removed from the struct array. So if e.g. the area of the first entry (like in the attachment) in the array is to big, I would like to remove the whole column so that after all I have an array with one less entry. Maybe it's possible to create a new struct array in which I could just copy the entries that pass my criteria?
Thanks in advance!

Accepted Answer

sloppydisk
sloppydisk on 7 Jun 2018
Logical indexing should work, just note that you need brackets around s.area.
field1 = 'area'; value1 = num2cell(1:10) ;
field2 = 'eccentricity'; value2 = num2cell(41:50);
s = struct(field1,value1, field2, value2);
sReduced = s([s.area] > 5);

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!