Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Resize used RIS.
#1
Hi all.

Question to experts from scripts.

Everything seems to be simple. I know how to do it, but how to organize in a script (SCM) - ???.

What are we doing?

We take a small image and upscaped with RIS (Reverse Interpolate Scale).

Sounds? And what about practice?

In practice, we open the image and make 3 copies of the layer (in fact 2, but for comparison we leave the original layer). Disconnect the original layer. Let it be "Lena" (512x512).

For the middle of the new 3 layers, we make a "layer" -> "layer size". To see the difference more, I choose a simple bicubic interpolation. And I put the right size for upscape, for example 3500x3500. After that, I will do the layer back: "layer" -> "layer size" -> 512x512.

All three layers are prepared. Now the application modes: on the upper (copies) "multiply", on average (subjected to upscape and downscape) "divide", on the latter "normal". I combine visible layers (the original is turned off).

Now we make an upscape of the entire image (the original layer and united of the three): "image" -> "image size" -> 3500x3500. Including/turning off the layers, we look at the difference.

And what is the actual question? Everything is simple, no?

And how to organize the initial dimensions in the dialog of the window? And even more optimal option is the use of the initial dialogue of "size change". But how to do this in the script?
Reply
#2
A script-fu script describes itself to Gimp using a call to script-fu-register.  Part of the declaration describes the arguments to the script. In most cases the first argument is an image (SF-IMAGE ), and usually the second argument is a layer/drawable (SF-DRAWABLE). When they are present, these two arguments are implicitly set to the active image and drawable. You can declare more arguments that are passed to your script, and Gimp will pop our a dialogue for these (for instance SF-SPINNER for an up-down number input widget). There are about 50 SCM scripts installed with Gimp so you have some examples already.

IMHO instead of asking for two dimensions, you can ask for a single scale factor.

There is no point in  setting the middle image to anything other than Normal if there is nothing visible below it.

If you really want to compare with the original, but the top two layers in a group. You can then set the group do Difference
Reply
#3
Something like this ?
https://github.com/ImageProcessing-Elect...plugin-ris
Reply
#4
(02-03-2025, 10:11 AM)denzjos Wrote: Something like this ?
https://github.com/ImageProcessing-Elect...plugin-ris

Absolutely true. Only for arbitrary scaling, as in https://github.com/ImageProcessing-Elect...resize-ris .
Only need to on Scheme and the question in the dialog, and not how to do it. The action itself is simple: "Defect" -> "Invert" -> "Scale".

The problem is the use of the initial sizes of the image in the dialogue and interpolation methods for scaling. How to organize this? There is no such scenario (SCM).
Reply
#5
Hi all.

Draft script:
Code:
(define (resize-ris image
                    drawable
                    newwidth
                    newheight)
    (let*
        (
            (drawable  (car (gimp-image-active-drawable image)))
            (oldwidth  (car (gimp-image-width image)))
            (oldheight (car (gimp-image-height image)))
            (new-layer-1 (car (gimp-layer-copy drawable TRUE)))
            (new-layer-2 (car (gimp-layer-copy drawable TRUE)))
            (new-layer-3 (car (gimp-layer-copy drawable TRUE)))
        )
    
        (gimp-image-undo-group-start image)
    
        (gimp-image-insert-layer image new-layer-1 0 -1)
        (gimp-image-insert-layer image new-layer-2 0 -1)
        (gimp-layer-set-mode new-layer-2 LAYER-MODE-MULTIPLY-LEGACY)
        (set! new-layer-1 (car (gimp-image-merge-down image new-layer-2 EXPAND-AS-NECESSARY)))

        (gimp-image-insert-layer image new-layer-3 0 -1)
        (gimp-layer-scale new-layer-3 newwidth newheight INTERPOLATION-CUBIC)
        (gimp-layer-scale new-layer-3 oldwidth oldheight INTERPOLATION-CUBIC)

        (gimp-layer-set-mode new-layer-3 LAYER-MODE-DIVIDE-LEGACY)
        (set! new-layer-1 (car (gimp-image-merge-down image new-layer-3 EXPAND-AS-NECESSARY)))
        (gimp-item-set-name new-layer-1 "RIS")

        (gimp-image-scale-full image newwidth newheight INTERPOLATION-CUBIC)

        (gimp-displays-flush)
        
        (gimp-image-undo-group-end image)
    )
)

(script-fu-register "resize-ris"
                    "_Resize RIS"
                    "Resize used RIS (Reverse Interpolate Scale)"
                    "zvezdochiot https://github.com/zvezdochiot"
                    "This is free and unencumbered software released into the public domain."
                    "2025-02-05"
                    "*"
                    SF-IMAGE       "Image"       0
                    SF-DRAWABLE    "Drawable"    0
                    SF-VALUE       "Width"       "1024"
                    SF-VALUE       "Height"      "1024"
)

(script-fu-menu-register "resize-ris" "<Image>/Image/Transform")
Reply
#6
Hi all.

Draft script with methods interpolation:
Code:
(define (resize-ris image
                    drawable
                    newwidth
                    newheight
                    method)
    (let*
        (
            (drawable  (car (gimp-image-active-drawable image)))
            (oldwidth  (car (gimp-image-width image)))
            (oldheight (car (gimp-image-height image)))
            (new-layer-1 (car (gimp-layer-copy drawable TRUE)))
            (new-layer-2 (car (gimp-layer-copy drawable TRUE)))
            (new-layer-3 (car (gimp-layer-copy drawable TRUE)))
        )
    
        (gimp-image-undo-group-start image)
    
        (gimp-image-insert-layer image new-layer-1 0 -1)
        (gimp-image-insert-layer image new-layer-2 0 -1)
        (gimp-layer-set-mode new-layer-2 LAYER-MODE-MULTIPLY-LEGACY)
        (set! new-layer-1 (car (gimp-image-merge-down image new-layer-2 EXPAND-AS-NECESSARY)))

        (cond
            ((= method 0)
                (gimp-context-set-interpolation INTERPOLATION-CUBIC)
            )
            ((= method 1)
                (gimp-context-set-interpolation INTERPOLATION-NONE)
            )
            ((= method 2)
                (gimp-context-set-interpolation INTERPOLATION-LINEAR)
            )
            ((= method 3)
                (gimp-context-set-interpolation INTERPOLATION-CUBIC)
            )
            ((= method 4)
                (gimp-context-set-interpolation INTERPOLATION-NOHALO)
            )
            ((= method 5)
                (gimp-context-set-interpolation INTERPOLATION-LOHALO)
            )
        )

        (gimp-image-insert-layer image new-layer-3 0 -1)
        (gimp-layer-scale new-layer-3 newwidth newheight TRUE)
        (gimp-layer-scale new-layer-3 oldwidth oldheight TRUE)

        (gimp-layer-set-mode new-layer-3 LAYER-MODE-DIVIDE-LEGACY)
        (set! new-layer-1 (car (gimp-image-merge-down image new-layer-3 EXPAND-AS-NECESSARY)))
        (gimp-item-set-name new-layer-1 "RIS")

        (gimp-image-scale image newwidth newheight)

        (gimp-displays-flush)
        
        (gimp-image-undo-group-end image)
    )
)

(script-fu-register "resize-ris"
                    "_Resize RIS"
                    "Resize used RIS (Reverse Interpolate Scale)"
                    "zvezdochiot https://github.com/zvezdochiot"
                    "This is free and unencumbered software released into the public domain."
                    "2025-02-06"
                    "*"
                    SF-IMAGE       "Image"       0
                    SF-DRAWABLE    "Drawable"    0
                    SF-VALUE       "Width"       "1024"
                    SF-VALUE       "Height"      "1024"
                    SF-OPTION      "Method"      '("Cubic" "None" "Linear" "Cubic" "NoHalo" "LowHalo")
)

(script-fu-menu-register "resize-ris" "<Image>/Image/Transform")
Reply
#7
Hi all.

Draft script used SUBTRACT-MODE:
Code:
(define (resize-ris image
                    drawable
                    newwidth
                    newheight
                    method)
    (let*
        (
            (drawable  (car (gimp-image-active-drawable image)))
            (oldwidth  (car (gimp-image-width image)))
            (oldheight (car (gimp-image-height image)))
            (layer-copy (car (gimp-layer-copy drawable TRUE)))
            (layer-defect (car (gimp-layer-copy drawable TRUE)))
            (new-layer-1 (car (gimp-layer-copy drawable TRUE)))
            (new-layer-2 (car (gimp-layer-copy drawable TRUE)))
            (new-layer-3 (car (gimp-layer-copy drawable TRUE)))
        )
    
        (gimp-image-undo-group-start image)
    
        (gimp-context-set-interpolation method)

        (gimp-image-insert-layer image layer-copy 0 -1)
        (gimp-image-insert-layer image layer-defect 0 -1)
        (gimp-layer-scale layer-defect newwidth newheight TRUE)
        (gimp-layer-scale layer-defect oldwidth oldheight TRUE)

        (set! new-layer-1 (car (gimp-layer-copy layer-copy TRUE)))
        (set! new-layer-2 (car (gimp-layer-copy layer-copy TRUE)))
        (set! new-layer-3 (car (gimp-layer-copy layer-defect TRUE)))
        (gimp-image-insert-layer image new-layer-1 0 -1)
        (gimp-image-insert-layer image new-layer-2 0 -1)
        (gimp-image-insert-layer image new-layer-3 0 -1)
        (gimp-layer-set-mode new-layer-1 SUBTRACT-MODE)
        (set! layer-defect (car (gimp-image-merge-down image new-layer-1 EXPAND-AS-NECESSARY)))
        (gimp-layer-set-mode new-layer-3 SUBTRACT-MODE)
        (set! new-layer-2 (car (gimp-image-merge-down image new-layer-3 EXPAND-AS-NECESSARY)))
        (gimp-layer-set-mode layer-defect SUBTRACT-MODE)
        (set! layer-copy (car (gimp-image-merge-down image layer-defect EXPAND-AS-NECESSARY)))
        (gimp-layer-set-mode new-layer-2 ADDITION-MODE)
        (set! layer-copy (car (gimp-image-merge-down image new-layer-2 EXPAND-AS-NECESSARY)))
        (gimp-item-set-name layer-copy "RIS")

        (gimp-image-scale image newwidth newheight)

        (gimp-displays-flush)
        
        (gimp-image-undo-group-end image)
    )
)

(script-fu-register "resize-ris"
                    "_Resize RIS"
                    "Resize used RIS (Reverse Interpolate Scale)"
                    "zvezdochiot https://github.com/zvezdochiot"
                    "This is free and unencumbered software released into the public domain."
                    "2025-02-06"
                    "*"
                    SF-IMAGE       "Image"       0
                    SF-DRAWABLE    "Drawable"    0
                    SF-VALUE       "Width"       "1024"
                    SF-VALUE       "Height"      "1024"
                    SF-ENUM        "Method"      '("InterpolationType" "cubic" "none" "linear" "cubic" "nohalo" "lohalo")
)

(script-fu-menu-register "resize-ris" "<Image>/Image/Transform")
The code is published in https://github.com/ImageProcessing-Elect...resize-ris .
Reply


Forum Jump: