Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
isolating areas of same colour
#3
(05-18-2019, 04:58 PM)Ofnuts Wrote:
(05-18-2019, 11:46 AM)dinasset Wrote: I do not remember whether this question was already discussed, hence I apologize in advance if so.
Assume an image has been "quantized" using mode indexed (then back to RGB).
The image shows -for example- areas of 8 different colors (if 8 was used while temporarily converting it to indexed).
But the number of separated color areas is often as expected greater than 8, because there are areas of the same color not contiguous, for example again we see 12 separated areas.
Interactively one may use the fuzzy select tool to work on each separated area, but from inside a script I don't see an easy way to do the same, because the gimp_image_select_color considers all together -as expected- the areas having the same colors, and the gimp_image_select_contiguous_color requires an x,y identifying a pixel position.
Is there a way to access separately each area without using a complex scan of pixels in the image to identify each of the 12 separated areas? 
Many thanks.

The answer is yes, just let Gimp do it for you:
  • Do a color select, and save to channel (because we will use it twice)(channel=pdb.gimp_selection_save(image)). This of course can select several non-contiguous areas.
  • Select->To path (in a script, pdb.plug_in_sel2path(image, drawable). This gives you a path with one stroke per area in the selection.
  • For each stroke in the path:
    • Copy it to a new temporary path
    • Make a selection from this path (pdb.gimp_select_item(image, CHANEL_OP_REPLACE,areapath)). You can find this result good enough, for a more accurate result if needed, add the next two steps
    • Select>Grow by one pixel: (pdb.gimp_selection_grow(image, steps))
    • Intersect this selection with the saved selection (pdb.gimp_image_select_item(image, CHANEL_OP_INTERSECT, channel))

Thanks a lot, Ofnuts !
I'll try your flow.
Reply


Messages In This Thread
isolating areas of same colour - by dinasset - 05-18-2019, 11:46 AM
RE: isolating areas of same colour - by Ofnuts - 05-18-2019, 04:58 PM
RE: isolating areas of same colour - by dinasset - 05-18-2019, 05:03 PM
RE: isolating areas of same colour - by Ofnuts - 05-18-2019, 07:17 PM
RE: isolating areas of same colour - by dinasset - 05-19-2019, 12:43 PM
RE: isolating areas of same colour - by Ofnuts - 05-19-2019, 05:10 PM
RE: isolating areas of same colour - by dinasset - 05-20-2019, 09:37 AM
RE: isolating areas of same colour - by Ofnuts - 05-20-2019, 12:06 PM
RE: isolating areas of same colour - by dinasset - 05-20-2019, 12:29 PM

Forum Jump: