Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Searching for python script islands to layers
#9
4) "num_channels, pixel = pdb.gimp_drawable_get_pixel(drawable, x_coord, y_coord)" will give you all four channels (so includes alpha). You can get all the pixels in an array using pixels regions. See this for an example (no, you don't need to use numpy).

7) The mask is a drawable and you can get it with "mask = pdb.gimp_layer_get_mask(layer)". Once you have it, you can fill the selection with "pdb.gimp_edit_fill(drawable, fill_type)"

8) "mean, std_dev, median, pixels, count, percentile = pdb.gimp_histogram(drawable, channel, start_range, end_range)" will tell you a lot of things about the contents of the selection.

However:
  • You are going to loop on the pixels. and even on a small 512x512 sheet this is 262K iterations... Of course you can optimize here and there, but you will still loop a lot.
  • By using just the bounding box, you will get pieces of objects that have overlapping bounding boxes (think of LT for instance).
The algorithm with paths is quick because the scanning of pixels is done by the native Gimp code. It can be improved by checking for near-empty selections:
  • compute an approximate area (in pixels) of the path stroke (using the path anchors as the summits of a polygon)
  • use the gimp_histogram() call to have an alpha-weighted count of the pixels in the stroke
  • compute the ratio of selected pixels/approximate area
  • if this is below some threshold (50%... depending on the relative size of holes in objects) then ignore it
Reply


Messages In This Thread
RE: Searching for python script islands to layers - by Ofnuts - 01-22-2018, 10:06 PM

Forum Jump: