script-fu invalid number of arguments - gimp

I want to create an image like notebooke paper,
and I thought it is easy if the section of drawing lines
is automated.
In order to make it, I decided to use gimp's function named
'gimp-rect-select' and specify the small height value.
I google-searched and wrote a scheme file,
but when I ran it from gimp's Script-Fu menu,
gimp showed me the message as below.
Error while executing FU01-multi-rect-select:
Error: ( : 1)
Invalid number of arguments for gimp-rect-select
(expected 8 but received 9)
I would like you to see my first script-fu and
point out where something wrong is involved.
To me, my custom function is defined so that
it has 8 parameters, not 9.
The folloing is my code
(define (FU01-multi-rect-select
image
drawable
x1
y1
w
h
p-offset
p-repeat
)
;definition of variables
(let*
(
(X nil)
(Y nil)
(width nil)
(height nil)
(offset nil)
(repeat nil)
;are they below necessary?
(theLayer nil)
(theImage nil)
)
;(gimp-context-push )
(gimp-image-undo-group-start image)
;(set! X (string->number x1))
;(set! Y (string->number y1))
;(set! width (string->number w))
;(set! height (string->number h))
;(set! offset (string->number p-offset))
;(set! repeat (string->number p-repeat))
(set! X x1)
(set! Y y1)
(set! width w)
(set! height h)
(set! offset p-offset)
(set! repeat p-repeat)
(gimp-image-set-active-layer image drawable)
(set! theLayer
(car (gimp-image-get-active-layer image) )
)
; select rectangle and after that,
; add it to current selection
; multiple times that is specified with 'repeat'
(while (> repeat 0)
(gimp-rect-select image X Y width height
CHANNEL-OP-ADD FALSE 0 0)
(set! Y (+ Y height offset))
(set! repeat (- repeat 1))
)
(gimp-image-undo-group-end image)
) ; end of let sentences
)
(script-fu-register "FU01-multi-rect-select"
"<Image>/Script-Fu/Select/multi rect select"
"add a rect selection to current selection multiple times\
each time a rect is selected it is moved\
in y axis by the value of offset"
"Masaaki Fujioka"
"copy right 2014 Masaaki Fujioka"
"August 3 2014"
"*"
SF-IMAGE "SF-IMAGE" 0
SF-DRAWABLE "SF-DRAWABLE" 0
SF-VALUE "start x" "0"
SF-VALUE "start y" "0"
SF-VALUE "width" "0"
SF-VALUE "height" "0"
SF-VALUE "offset" "0"
SF-VALUE "repeat" "0"
)

Just like the error message says, you have one extra parameter to the gimp-rect-select call - if you check the specs for the call on the procedure browser, after the "mode" parameter there should be one boolean to tell whether you want to use feathering, and another number to tell the feathering amount. You are passing two integers instead of just one number needed.
Also, pay attention that this call is marked as "deprecated" - which means that although it still works in gimp-2.8, for a series of reason, you should be calling gimp-image-select-rectangle instead of this. (note that the parameters for that call differ).

Related

Caffe - Concat layer input and output

I read about Concat layer on Caffe website. However, I don't know if my understanding of it is right.
Let's say that as an input I have two layers that can be described as W1 x H1 x D1 and W2 x H2 x D2, where W is the width, H is height and D is depth.
Thus, as I understand with Axis set to 0 output will be (W1 + W2) x (H1 + H2) x D, where D = D1 = D2.
With Axis set to 1 output will be W x H x (D1 + D2), where H = H1 = H2 and W = W1 = W2.
Is my understanding correct? If no I would be grateful for an explanation.
I'm afraid you are a bit off...
Look at this caffe.help.
Usually, data in caffe is stored in 4D "blobs": BxCxHxW (that is, batch size by channel/feature/depth by height by width).
Now if you have two blobs B1xC1xH1xW1 and B2xC2xH2xW2 you can concatenate them along axis: 1 (along channel dimension) to form an output blob with C=C1+C2. This is only possible iff B1==B2 and H1==H2 and W1==W2, resulting with B1x(C1+C2)xH1xW1

Geogebra plot range

I created this plot through the GeoGebra spreadsheet:
I would be interested in getting the same plot, but only in range between the first (1;3) and the last (3;4.5) point. How can I do this?
Thanks in advance
Ok this is my firs answer , you can type that in the input line below : If(1 < x < 3, f(x))
where f(x) is your function
For example, for f(x) = x^2, you can input like this: x² / (x < -1 ∨ x > 1)
(x < -1 ∨ x > 1) is a boolean value, True == 1, and False == 0. 0 as a denominator is meaningless, and this can be used to limit the display range in Geogebra.

Halfmanualy crop image

I have a few hundred photos. Each photograph is one object. And with each photo repeat the same steps:
Open, select the area; crop, resize, fix brightness, save.
My attempt to automate the process: write a script and hang it on a hotkey.
(define (script-fu-cut800 inText inFont inFontSize inTextColor)
; get the coordinates of allocation
(gimp-image-get-selection (image))
(let * (
(original-left (car (????)))
(original-top (car (????)))
(original-width (car (gimp-image-width image)))
(original-height (car (gimp-image-height image)))
(new-width (- original-width (+ right left)))
(new-height (- original-height (+ top bottom)))
)
; crop the selected image
(gimp-image-crop image new-width new-height left top)
; resize to 800 * 800
(gimp-image-resize image 800 800 0 0)
; open dialogue correction levels
(?????)
; save as JPG 80% compression of the same name
(file-jpeg-save ????)
))

Format string to number with minimum length in lua

For example I need number with minimum 3 digit
"512" --> 512
"24" --> 24.0
"5" --> 5.00
One option is write small function. Using answers here for my case it will be something like this
function f(value, w)
local p = math.ceil(math.log10(value))
local prec = value <= 1 and w - 1 or p > w and 0 or w - p
return string.format('%.' .. prec .. 'f', value)
end
print(f(12, 3))
But may be it is possible just using string.format() or any other simple way?
Ok, it seems this case beyond the string.format power. Thanks to #Schollii, this is my current variant
function f(value, w)
local p = math.ceil(math.log10(value))
local prec = value <= 1 and w - 1 or p > w and 0 or w - p
return string.format('%.' .. prec .. 'f', value)
end
print(f(12, 3))
There is no format code specifically for this since string.format uses printf minus a few codes (like * which would hace simplified the solution I give below). So you have to implement yourself, for example:
function f(num, w)
-- get number of digits before decimal
local intWidth = math.ceil(math.log10(num))
-- if intWidth > w then ... end -- may need this
local fmt='%'..w..'.' .. (w-intWidth) .. 'f'
return string.format(fmt, num)
end
print(f(12, 4))
print(f(12, 3))
print(f(12, 2))
print(f(512, 3))
print(f(24, 3))
print(f(5, 3))
You should probably handle case where integer part doesn't fit in field width given (return ceil or floor?).
You can't. Maximum you can reach - specify floating point precision or digit number, but you can't force output to be like your example. Lua uses C like printf with few limitations reference. Look here for full specifiers list link. Remember unsupported ones.
Writing a function would be the best and only solution, especially as your task looks strange, as it doesn't count decimal dot.

Create a path in a grid in prolog

I have to create a path between two given points in a grid in Prolog. The code I have so far is:
createPath(GridSize, BeginPosition, EndPosition, VisitedPoints, Path):-
nextStep(BeginPosition, NextStep, GridSize),
(
NextStep \== EndPosition,
->
nonmember(NextStep, VisitedPoints),
add(NextStep, VisitedPoints, NewVisitedPoints),
add(NextStep, Path, NewPath),
createPath(GridSize, NextStep, EndPosition, NewVisitedPoints, NewPath)
;
???
).
A little bit of explanation of my code:
GridSize is just an integer. If it is 2, the grid is a 2x2 grid. So all the grids are square.
The BeginPosition and EndPosition are shown like this: pos(X,Y).
The function nextStep looks for a valid neigbor of a given position. The values of X and Y have to be between 1 and the grid size. I've declared 4 different predicates of nextStep: X + 1, X - 1, Y + 1 and Y - 1.
This is the code:
nextStep(pos(X,Y),pos(X1,Y),GridSize):-
X1 is X + 1,
X1 =< GridSize.
nextStep(pos(X,Y),pos(X1,Y),_):-
X1 is X - 1,
X1 >= 1.
nextStep(pos(X,Y),pos(X,Y1),GridSize):-
Y1 is Y + 1,
Y1 =< GridSize.
nextStep(pos(X,Y),pos(X,Y1),_):-
Y1 is Y - 1,
Y1 >= 1.
nonmember returns true if a given element doesn't occur in a given list.
add adds an element to a given list, and returns the list with that element in it.
Another thing to know about VisitedPoints: Initially the BeginPosition and EndPosition are stored in that list. For example, if I want to find a path in a 2x2 grid, and I have to avoid point pos(2,1), then I will call the function like this:
createPath(2, pos(1,1), pos(2,2), [pos(1,1),pos(2,2),pos(2,1)], X).
The result I should get of it, should be:
X = [pos(1,2)]
Because that is the point needed to connect pos(1,1) and pos(2,2).
My question is, how can I stop the code from running when NextStep == EndPosition. In other words, what do I have to type at the location of the '???' ? Or am I handling this problem the wrong way?
I'm pretty new to Prolog, and making the step from object oriented languages to this is pretty hard.
I hope somebody can answer my question.
Kind regards,
Walle
I think you just placed the 'assignment' to path at the wrong place
createPath(GridSize, BeginPosition, EndPosition, VisitedPoints, Path):-
nextStep(BeginPosition, NextStep, GridSize),
(
NextStep \== EndPosition,
->
nonmember(NextStep, VisitedPoints),
add(NextStep, VisitedPoints, NewVisitedPoints),
% add(NextStep, Path, NewPath),
% createPath(GridSize, NextStep, EndPosition, NewVisitedPoints, NewPath)
createPath(GridSize, NextStep, EndPosition, NewVisitedPoints, Path)
;
% ???
% bind on success the output variable, maybe add EndPosition
Path = VisitedPoints
).
Maybe this is not entirely worth an answer, but a comment would be a bit 'blurry'

Resources