Re: Optimizing border-like selection in python

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  On 27/09/2010 18:47, saulgoode@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx wrote:
> Quoting Ofnuts<ofnuts@xxxxxxxxxxx>:
>
>> My code needs to do a one-pixel-wide selection, at distance "x" from the
>> current selection.  This looks a lot like a border selection except that
>> the border selection creates at best a two-pixel wide ribbon and I only
>> want one (but if I'm wrong, please tell me how to :-)
>>
>> So far my code goes like this:
>>
>> # Selects pixels that are between x and x+1 pixels from
>> # the original selection. Bumping the selection by one
>> # each time doesn't work, a small circle degenerates into
>> # a square with rounded corners instead of a big circle.
>>       def select_ribbon(self,image,selection,dist):
>>           pdb.gimp_selection_load(selection)
>>           pdb.gimp_selection_grow(image,dist+1)
>>           outer=pdb.gimp_selection_save(image)
>>           pdb.gimp_selection_load(selection)
>>           pdb.gimp_selection_grow(image,dist)
>>           inner=pdb.gimp_selection_save(image)
>>           pdb.gimp_channel_combine_masks(outer,inner,CHANNEL_OP_SUBTRACT,0,0)
>>           pdb.gimp_selection_load(outer)
>>           image.remove_channel(outer)
>>           image.remove_channel(inner)
>>
>> That works, but can be slow (especially since it's at the core of a
>> loop). Is there any better way? Or useless code to jettison?
> There is no need to create (and later delete) the 'outer' channel.
> Just use the selection itself. In Script-fu, this would be done as
> follows:
>
>     (gimp-selection-load selection)
>     (gimp-selection-grow image dist)
>     (set! inner (car (gimp-selection-save image)))
>     (gimp-selection-load selection)
>     (gimp-selection-grow image (+ dist 1))
>     (gimp-channel-combine-masks (car (gimp-image-get-selection image))
>                                 inner
>                                 CHANNEL-OP-SUBTRACT 0 0)
>     (gimp-image-remove-channel image inner)

Implemented your code. It runs 10 to 20% faster, and uses only half the 
memory... So you have been duly credited in the V0.2 history. Thx.


_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux