Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
linking a image with its mask
#1
I have tried script for linking a image with its mask but its not working. I need it to be worked urgently. Kindly help.


Code:
(define  (script-fu-auto-mask-image Mask InImage OutImage)
 (let* (
     Image (car (file-tiff-load RUN-NONINTERACTIVE InImage InImage)) ImgW (car (gimp-image-width Image)) ImgH (car (gimp-image-height Image))
     PrimeLayer (car (gimp-image-get-active-layer Image))
     (gimp-layer-add-alpha PrimeLayer))
     (gimp-layer-new Image ImgW ImgH RGB-IMAGE MaskLayer 0 LAYER-MODE-NORMAL)
     (gimp-file-load-layer RUN-NONINTERACTIVE Image Mask)
     (gimp-image-set-active-layer Image MaskLayer)
     (gimp-image-select-color mask CHANNEL-OP-ADD drawable (0 0 0))
     (gimp-image-set-active-layer Image PrimeLayer)
     ;(gimp-edit-clear drawable)
     (gimp-drawable-edit-clear drawable)
     (gimp-image-remove-layer Image MaskLayer)
     (file-png-save-defaults RUN-NONINTERACTIVE Image drawable OutImage OutImage)
   )
 (gimp-displays-flush)
 (gimp-quit TRUE)
)

I am trying to execute it through this command.
gimp -i -c -b '(script-fu-auto-mask-image  "Pictures/test/mask.png" "Pictures/test/DSC00805.tif" "test.png")' -b '(gimp-quit 0)
Reply
#2
This is a straight copy / paste of this question from 8 months ago.  https://stackoverflow.com/questions/6923...ith-a-mask

Are you the same poster ? Give a good reason for asking again, preferably in your own words.

----
Edit: Is the problem you are using Windows and the command is set up for linux Some adjustment to quotes maybe needed for Windows see: https://www.gimp-forum.net/Thread-Script...3#pid18873
Reply
#3
I don't understand your code:

Code:
(gimp-layer-new Image ImgW ImgH RGB-IMAGE MaskLayer 0 LAYER-MODE-NORMAL)
(gimp-file-load-layer RUN-NONINTERACTIVE Image Mask)
(gimp-image-set-active-layer Image MaskLayer)

I looks like you are expecting gimp-file-load-layer to "fill" MaskLayer. In any case, gimp-file-load-layer creates a new layer and returns it, so if you don't set a variable with whatever is returned from gimp-file-load-layer you will  have trouble accessing the loaded layer.

Also, in Gimp 2.10, instead of using a mask, it could be simpler to use a layer in Erase blend mode.
Reply
#4
My main aim is to create a PSD file from list of images(Original image, background removed image and binary mask of original image). I am able to create a PSD file with 3 layes, one for original image, one for mask and one for background removed image. But I want to create a PSD with only 2 layers, One having background removed image and one with original image and mask linked  to original image. I used following code to create PSD from list of input image. I also attached my expected PSD layers image and image of what I am getting.

Can anyone please help in making changes in below code so that I can get PSD as per above mentioned condition. If not then kindly guide in making changes in above mentioned script of linking mask with its image. Its urgent, I will be thankful to the gimp community.
My code
(define (layers-to-psd image-paths psd-path)
  (define (add-layers image image-paths)
    (when (not (null? image-paths))
      (let*
        (
          (img-path (car image-paths))
          (layer (car (gimp-file-load-layer RUN-NONINTERACTIVE image img-path)))
        )
        ;; (display img-path) (newline)
        (gimp-image-insert-layer image layer 0 -1)
        (add-layers image (cdr image-paths))
      )
    )
  )
  (let*
    (
      (base-path (car image-paths))
      (image (car (gimp-file-load RUN-NONINTERACTIVE base-path base-path)))
      (drawable (car (gimp-image-get-active-layer image)))
    )
    ;; (display base-path) (newline)
    (add-layers image (cdr image-paths))
    ;; LZW compression (1), MSB to LSB fill order (0)
    (file-psd-save RUN-NONINTERACTIVE image drawable psd-path psd-path 1 0)
    (gimp-image-delete image)
  )
)

Command

gimp -i -c -b '(layers-to-psd(list "original_image.png" "mask.png" "removed_background.png" ) "final.psd")' -b '(gimp quit 0)'

Output -  [Image: view?usp=sharing]

Image illustration of what i want to do
[Image: view?usp=sharing]

(05-26-2022, 11:37 AM)rich2005 Wrote: This is a straight copy / paste of this question from 8 months ago.  https://stackoverflow.com/questions/6923...ith-a-mask

Are you the same poster ? Give a good reason for asking again, preferably in your own words.

----
Edit: Is the problem you are using Windows and the command is set up for linux Some adjustment to quotes maybe needed for Windows see: https://www.gimp-forum.net/Thread-Script...3#pid18873

No, I am not the same poster but I want things to be exactly done as per the motive of this script. But there are some issues with this script. Can you please help. Its very urgent here.
Reply
#5

  1. Your links to images don't work
  2. If it's urgent then it is professional?
  3. Did you first check that you can create the image "manually" using Gimp? Compatibility with Photoshop is far from complete, Gimp is not a Photoshop clone.
  4. What layer structure are you trying to achieve in Gimp? AFAIK there are no "linked masks", just "masks"
  5. Why 3 files? If you have the full image and the extraction, the mask can be deduced from the extraction
  6. And why two layers? The PSD could be just the original image and the mask to produce the extraction.
Reply
#6
I agree with Ofnuts, it is all a bit weird and along the lines of the commercial PS clipping path makers but for Gimp Wink  These are your clips. What you have to what you require.

   

I am no code writer, especially script-fu which to me is a clear as Sanskrit. Thus as a user step-by-step

"manually" using some existing scripts

1. Why the different size layers ? Ofnuts has a good python plugin for layer > image size but sticking with a script-fu sg-scale-to-selection.scm to correct that
2. Duplicate base layers and apply the mask to the visible layer using sg-copy-mask-to-layers.scm
3. Apply the layer mask to one of the layers with the script sg-apply-layer-mask-all-layers.scm

Obviously there is some user intervention between these steps, deleting layers, selecting layers. How to batch that I do not know. The scripts attached, zipped. Unzip and put in your scripts folder. Maybe you can use bits of the code to re-draft your batch procedure.

I can just get that into 1 minute for imgur:  https://i.imgur.com/ghBxhvm.mp4

best of luck.


Attached Files
.zip   3-mask-scripts.zip (Size: 2.95 KB / Downloads: 119)
Reply
#7
Quote:I am no code writer, especially script-fu which to me is a clear as Sanskrit.

Since years, I searched the good expression to clearly express my coder inability to deal with Scheme language. Now it's done Big Grin
Reply
#8
(05-27-2022, 03:48 PM)rich2005 Wrote: I agree with Ofnuts, it is all a bit weird and along the lines of the commercial PS clipping path makers but for Gimp Wink  These are your clips. What you have to what you require.



I am no code writer, especially script-fu which to me is a clear as Sanskrit. Thus as a user step-by-step

"manually" using some existing scripts

1. Why the different size layers ?  Ofnuts has a good python plugin for layer > image size but sticking with a script-fu sg-scale-to-selection.scm to correct that
2. Duplicate base layers and apply the mask to the visible layer using sg-copy-mask-to-layers.scm
3. Apply the layer mask to one of the layers with the script sg-apply-layer-mask-all-layers.scm

Obviously there is some user intervention between these steps, deleting layers, selecting layers. How to batch that I do not know. The scripts attached, zipped. Unzip and put in your scripts folder. Maybe you can use bits of the code to re-draft your batch procedure.

I can just get that into 1 minute for imgur:  https://i.imgur.com/ghBxhvm.mp4

best of luck.

Thank you alot everyone for your kind suggestions. Rich2005,can you please help me in commands executing those 3 scripts in zipped folders shared by you.
Reply
#9
Quote: Thank you alot everyone for your kind suggestions. Rich2005,can you please help me in commands executing those 3 scripts in zipped folders shared by you.

I can not help with the code you posted, I thought you might look at those script-fu and incorporate into your code. Maybe that is not possible.

The scripts can only process a single file at a time. Unzip and put the three in C:\Users\"yourname"\AppData\Roaming\GIMP\2.10\scripts

Then apply one at a time as the example I posted https://i.imgur.com/ghBxhvm.mp4

one-image-at-a-time is the best I can suggest and because of that script #3 not really required since you can apply a layer mask from Layer > Mask menu to get to your two layer example
Reply
#10
(05-31-2022, 11:16 AM)rich2005 Wrote:
Quote: Thank you alot everyone for your kind suggestions. Rich2005,can you please help me in commands executing those 3 scripts in zipped folders shared by you.

I can not help with the code you posted, I thought you might look at those script-fu and incorporate into your code. Maybe that is not possible.

The scripts can only process a single file at a time. Unzip and put the three in C:\Users\"yourname"\AppData\Roaming\GIMP\2.10\scripts

Then apply one at a time as the example I posted https://i.imgur.com/ghBxhvm.mp4

one-image-at-a-time is the best I can suggest and because of that script #3 not really required since you can apply a layer mask from Layer > Mask menu to get to your two layer example

Thankyou, but now my question is how to process single file into these scripts from command line. i meant to say what will be the command to run these files individually through ubuntu  terminal.
Reply


Forum Jump: