You are here

Diagonal selection in Script-Fu using gimp-free-select?

Is it possible to create a one-pixel diagonal selection using gimp-free-select?

That is, for a 100 x 100 pixel image, the following pixels would be selected:


I've attached a simple test case in which I attempt to create such a selection over a white image and fill the selection in black, but it appears nothing is being selected, as the whole image turns out black. I expected a jagged diagonal line from the upper left corner to the lower right corner.

I'm guessing I'm misunderstanding something about the floatarray, as supposedly gimp-free-select can accept a minimum of 2 points.

The attached script-fu goes into a new Debug menu when registered.

but two points can't define a selection. There is no "inside". playing with the free select (lasso) tool, you can't get a valid selection with only two points. you need 3 (to get a triangular selection) or 4 (for a rectangular selection). -Rob A>

GIMP allows selecting a single row or column, so there doesn't necessarily have to be an inside. And if we can't define a path by two points, then why does gimp-free-select allow for a minimum of two points to define a selection? From parameters: num-segs INT32 Number of points (count 1 coordinate as two points) (num-segs >= 2) Anyway, if I replace the two points with four points my test case does work, so thanks. I've added a second test case diagonal-select4b.scm "Test diagonal gradient with 4 points (alternative B)" (also in the Debug menu) which works as I want it. I've also added diagonal-select4a.scm "Test diagonal gradient with 4 points (alternative)" which almost works except that 1 point in the middle is missing. The only difference with the 4b file is that the selected line is 1 pixel shorter. I've filed a bug concerning this missing pixel. But in any case, now I've got working code so I'm happy.

because the free select tool (and the lasso tool) allow for points defining their selection at the fractional pixel level. So to define a 1 px horizontal or vertical selection with free select I would expect you need to use 4 points where the y or x respectively has a delta of 1 px between the two pairs of points. -Rob A>

Just paint directly on the selection channel in white and those pixels will be selected.

(gimp-selection-none image) ; fill selection with black 
(gimp-context-set-foreground '(255 255 255)) ; white = fully selected
(set! selection (car (gimp-image-get-selection image))) ; the selection is a channel
(gimp-context-set-brush "Circle (01)") ; one-pixel brush
(set! stroke (make-vector 4 0))
(vector-set! stroke 0 0) ; x1 = 0
(vector-set! stroke 1 0) ; y1 = 0
(vector-set! stroke 2 100) ; x2 = 100
(vector-set! stroke 3 100) ; y2 = 100
(gimp-pencil selection 4 stroke) ; draw a one-pixel white line from x1,y1 to x2,y2

Note that if you are just using numeric constants for the coordinates (not variables), you can reduce the last six lines to just:

(gimp-pencil selection 4 #(0 0 100 100))

I left out the grunt work.

EDIT: fixed up code formatting using 'pre' tags.

Subscribe to Comments for "Diagonal selection in Script-Fu using gimp-free-select?"