Remove 'anomalous' blobs in a polygon (polyshape).

2 views (last 30 days)
Dear all,
I have several polygons. Some of them have some 'anomalous' (for the purpose of my task) blobs which I'd like to remove. In the example below (see p5 to p10 files attached for reproducibility), I highlighted the regions I'd like to exclude with the red X, while the red lines represent the vertices I would, roughly, like to join, if possible. Can you suggest any approach to accomplish this task?
Pname = {'p5', 'p6', 'p7', 'p8', 'p9', 'p10'};
figure
for i = 1:length(Pname)
Pn = eval(Pname{i});
subplot(2, 3, i)
plot(Pn, 'FaceColor', 'none', 'EdgeColor', 'k', 'LineWidth', 2)
axis square
title(Pname{i})
end
Please note, I am only interested on the blobs located on the upper bound of the polygon. The ones at the bottom make no difference for my task, so can be either removed or kept, if that makes any difference.
Any help would be grately appreciated!
Thanks in advance
  7 Comments
Simone A.
Simone A. on 5 Oct 2023
Hi @Matt J, you are right, as I stated on the comment above, p9 would have 'no blobs' to delete following this criterion, but the other ones would. Finding 5 blobs out of 6 is enough for the purpose of my work. How could that be achieved?
Steven Lord
Steven Lord on 5 Oct 2023
What's your rule for how much of the shape to remove?
In p6, for example, the cut that you've indicated you want to draw is from about x=284, y = 286 to x = 286, y = 287. [All coordinates given here are estimated by eye; don't take them as measured by a surveyor's instruments or something else precise.] Why draw that cut line instead of the line from x = 284, y = 286 to x = 288, y = 282? That would eliminate that dangling piece on the right side as well. Or why not move that cut line up to around (284, 287) and (285, 288) to make the cut shorter?
In p10 it looks like you could chop off a "narrower waist" by moving up to around y = 292 and cutting across with a horizontal line. [The bottom arms of the X obscure the actual boundary a bit, so I'm extrapolating based on what we can see of the boundary entering the X.] Why did you go down to around y = 290? What rule or rules are you following that gave preference to the lower line instead of the higher line? This is a similar question to the second part of my p6 question, and the same question looks like it applies to p8 too.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 5 Oct 2023
First of all, don't use eval:
Secondly, I agree with @John D'Errico that there is no obvious reason that those particular protrusions would be snipped off and not some of the others. You could smooth the boundaries but that would affect everything, not just those particular regions.
So I think you're left to manually snip them off by drawing a line across them. There are several ways to do it depending on if you're dealing with digital images or a list of coordinates or polygon/polyshape objects. For example you could use ginput.
I'm attaching some demos that may (or may not) be useful to you.
  2 Comments
Simone A.
Simone A. on 5 Oct 2023
Hi @Image Analyst thanks for taking the time to reply. I provided some further information about the criterion for a blob to be detected in the reply to Matt's and John's comments. Does that help?
Image Analyst
Image Analyst on 5 Oct 2023
It helps but there is still the problem of where to draw the red splitting line. There are many places on the outline that could potentially be the endpoints of that line.
I have almost infinitely more experience with digital images than with polyshapes. If it were an image, then it might be easier. Maybe you could convert the polyshapes to an image. Then use watershed to split apart the blob at the narrowest points. Then identify the one blob that contained the highest y (lowest line/row). Then use that blob to erase it from the original/full image. Then get boundaries back (if you want them) using bwboundaries.

Sign in to comment.

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!