Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selecting one pixel from each blob in a binary image
#4
I see two ways to do this.

Both start by selecting the white in A then getting a path form the selection, as explained previously (because this is the most practical way to separate the blobs in A). Once you have a path you can construct separate paths each with a copy of one stroke from the original (so one path per blob in A).

Then:
  • The first technique is to use each of these paths in turn to create a selection (so you have a selection mask which is one of the blobs in A) and use the pdb.gimp_drawable_histogram(...) on layer B to check for white (or non-black) pixels (the histogram applies to the selection).
  • A second technique is to extract path strokes from B (as you did for A) and check if any of these strokes intersects a stroke in A. Technically, you only need to find an anchor of the stroke of B which is inside a stroke of A. You can very quickly eliminate most candidates by checking that their bounding boxes don't intersect. If you want a bit more accuracy instead of the anchors you can use pdb.gimp_vectors_stroke_interpolate(...) to get a polygon with more summits.
Once you have determined if a stroke of A covers a blob in B using either method, you can either use the selection from the stroke to copy/recreate the blob on another layer, or grow it by one pixel and fill with black to obliterate a blob of A that doesn't overlap anything in B.

My ofn-path-edits script contains many examples of path extraction/splitting and checking nesting.
Reply


Messages In This Thread
RE: Selecting one pixel from each blob in a binary image - by Ofnuts - 10-25-2024, 12:18 AM

Forum Jump: