It is currently Fri Sep 25, 2026 11:25 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: BORDER SELECTION (?)
PostPosted: Mon May 18, 2015 6:36 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
GIMP Version: 2.8.14
Operating System: Windows
GIMP Experience: Basic Level



Hi,
I hope this help request is not wrong as the last I posted.
I was trying to use in a script the PDB function gimp-selection-border, which I previously tested successfully interactively, but it seemed to me not be working.
Hence I created a specific small script which only tests the border selection, using two different methods:
1-gimp-selection-all, then gimp-selection-border
2-gimp-selection-all, then gimp-selection-shrink, then gimp-selection-invert
The second method works as expected (IMO), while the first not.
In fact the subsequent gimp-edit-fill in case 1 fills the entire layer, in case 2 the created selection
Because I don't know whether I did something wrong in the use or this effect happens only on my system, I attach here the full (small) script, just in case someone wants to give it a try.


(define (script-fu-test-select
    theOldImage
    theOldLayer
    theMethod
;  doFlatten
   )

; Initialize an undo, so the process can be undone with a single undo
    (gimp-image-undo-group-start theOldImage)

; Variable init
    (let*
   (
            (imageWidth (car (gimp-image-width theOldImage)))
            (imageHeight (car (gimp-image-height theOldImage)))
            (theDuplicatedLayer)
   )

     (gimp-message-set-handler 2)
     (set! theDuplicatedLayer (car (gimp-layer-new-from-drawable theOldLayer theOldImage)))
     (gimp-image-add-layer theOldImage theDuplicatedLayer 0)
     (gimp-image-set-active-layer theOldImage theDuplicatedLayer)

     (case theMethod
      ((0)
        (gimp-selection-all theOldImage)
        (gimp-selection-border theOldImage 20)
        (gimp-edit-fill theDuplicatedLayer FOREGROUND-FILL)
       )
      ((1)
        (gimp-selection-all theOldImage)
        (gimp-selection-shrink theOldImage 20)
        (gimp-selection-invert theOldImage)
        (gimp-edit-fill theDuplicatedLayer BACKGROUND-FILL)
       )
     )
   
    ;Ensure the updated image is displayed now
     (gimp-displays-flush)

     (gimp-image-undo-group-end theOldImage)
   
    ) ; end let*
) ; end define

(script-fu-register
            "script-fu-test-select"
            "test selection methods"
            "test selection methods"
            "me"
            "Copyright"
            "gg/mm/aaaa"
            "RGB*"
            SF-IMAGE        "Image"     0
            SF-DRAWABLE     "Drawable"  0
            SF-OPTION       "Selection method" '("Border" "Shrink" )
;          SF-TOGGLE       "Flatten Image"     
)
(script-fu-menu-register
"script-fu-test-select"
"<Image>/DNscripts/Test/"
)



Any suggestion?

_________________
"Where am I ?"


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: BORDER SELECTION (?)
PostPosted: Mon May 18, 2015 7:39 am  (#2) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
The border of a selection is defined as the point where the pixels of the selection mask transition from values below 127 to above 128 (black/darkgray to lightgray/white). So how does one treat this border at the edges of the image? Inside of the edge we have the value of the selection but what value should be used for the outside of the edge -- where there is no pixel?

There are basically three options:
  • Assume the outside value is "0"
  • Assume the outside value is "255"
  • Assume the outside value is equal to the inside value (the value of the pixel at the edge)

If you've performed a "Select->All" then the values of all of the inside pixels are "255"; therefore the second and third options result in effectively no border existing (i.e., there is no transition from less than 127 to greater than 127 because both inside and outside are 255). Unfortunately, the 'gimp-selection-border' PDB does not let you choose the first option (it assumes the last option).

The dialog for the menu command "Select->Border..." does allow the first option -- that is what "Lock selection to image borders" does -- but it is not exposed in the PDB. There is no easy way (to my knowledge) of achieving the same result with a script, though one could accomplish it by growing the image by 1 pixel all around and filling the selection mask of those added pixels with black before running 'gimp-selection-border' and then restoring the original image size, but typically there are simpler solutions for specific cases.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: BORDER SELECTION (?)
PostPosted: Mon May 18, 2015 8:10 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
in other words (mine!):
- the PDB function SHOULD be adjusted to work AT LEAST BY DEFAULT (i.e. even w/o implementing the parameters list) as the equivalent interactive function (interactively simply applying the "select border" after the "select all" one GETS the selection).
IMO an inconsistency!

_________________
"Where am I ?"


Top
 Post subject: Re: BORDER SELECTION (?)
PostPosted: Mon May 18, 2015 10:34 am  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
dinasset wrote:
in other words (mine!):
- the PDB function SHOULD be adjusted to work AT LEAST BY DEFAULT (i.e. even w/o implementing the parameters list) as the equivalent interactive function (interactively simply applying the "select border" after the "select all" one GETS the selection).
IMO an inconsistency!


No real reason for consistency between the GUI (where ease of use matters, even if not always logical) and API (where logic matters). You can alway define selection_border(x) as selection_grow(x/2)-selection_shrink(x/2).

_________________
Image


Top
 Post subject: Re: BORDER SELECTION (?)
PostPosted: Mon May 18, 2015 12:33 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 20, 2013
Posts: 14835
Location: roma, italy
as I said, I use (in the script) shrink then reverse (after selection all);
easy to do;
nevertheless I maintain my INCONSISTENCY opinion, and again not in relation to the options (parameters = ease of use) but as far as the default is concerned (no chance to use it, as it is! while -if the default were the same- it COULD be used, even without parameters)

_________________
"Where am I ?"


Top
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group