Switch to full style
Ask all general Gimp related questions here
Post a reply

Clipping and Alpha using two generated source images

Sat May 30, 2020 2:34 pm

GIMP Version: 2.8.14
Operating System: Windows
GIMP Experience: Basic Level



So I have a open-source tool that extracts images from pdf files that I own for my own personal, non-commercial purposes. Two files of interest are generated (see attached), image and mask.

I'd like to use the mask file to delimit the image file, just the image area under the white mask will make it through. After that process, the area corresponding to black on (another duplicate copy of ?) the mask will be converted to alpha and saved.

The end result will be a nicely cleaned up image with an alpha channel background, stored as a png... all without manually brushing or erasing anything with a mouse. Just menu/button selections.

Re: Clipping and Alpha using two generated source images

Sat May 30, 2020 3:09 pm

Just add a layer mask to your image and copy and paste your mask image into the layer mask, then save as a png.

mask.png
mask.png (505.9 KiB) Viewed 3079 times

Re: Clipping and Alpha using two generated source images

Sat May 30, 2020 5:48 pm

racer-x wrote:Just add a layer mask to your image and copy and paste your mask image into the layer mask, then save as a png.

mask.png


Mystrzy: GIMP has changed the way we save files, so actually use the Export As option is the same as saving the file as... it takes a little getting used to, just so you know.

Re: Clipping and Alpha using two generated source images

Sat May 30, 2020 6:55 pm

Your image looks good. However, there is a lot going on in that one sentence description.
"Just add a layer mask to your image and copy and paste your mask image into the layer mask, then save as a png."
I've opened the image, it shows as one layer labeled as {the filename}. I right-click on the layer, select "Add layer mask...", and 1/2 a shton of options appear.. which one to choose?
let's pick the alpha one ..continuing on..
Now the layer has two boxes on it, the image and the layer-mask.
"Just add a layer mask to your image and copy and paste your mask image into the layer mask, then save as a png."
So I can't just drag the mask-file into the layers.. I open the mask-file into a separate session/window so its by itself. I "Select> All" and then "Edit> Copy", it's now in the clipboard. Now.. "into the layer mask". How the heck do I paste into just the layer-mask portion of that layer?
Hmmm, I click on the the layer-mask box on the right of the two boxes on that layer, it's now got a white outline. Then I paste into what looks like a sea of alpha (because of my earlier choice)... and BAM! there it is! Now I exported as png. Done.
(I tried a few times and I actually didn't have this done and working until I went thru the exercise of recording this step by step.)

Thank You for stepping up and your help! There are so many options and capabilities in GIMP that it can be hard to know which to use and in what order and/or options. Again, Thank You.

Re: Clipping and Alpha using two generated source images

Sat May 30, 2020 8:15 pm

Glad you figured it out, I knew you would. I'm good at doing, but not so much at explaining.

Re: Clipping and Alpha using two generated source images

Sun May 31, 2020 2:33 am

The small print: "File comment: Image file to be cleaned up by mask file, and alpha added.. eventually automated."

Easy enough one at a time....eventually automated ...is less easy.

It should be possible to write a Gimp script that will batch process pairs of images but a better tool for this is commandline Imagemagick (IM).

Still needs wrapping in a batch / bash file with file names replaced by variables, the basic command is

Code:
magick image-0007.png  image-0008.png -alpha Off -compose CopyOpacity -composite masked.png


gives this:

masked.jpg
masked.jpg (124.22 KiB) Viewed 3009 times


see: http://www.imagemagick.org/Usage/masking/#masks note: IM6 uses convert IM7 uses magick

Re: Clipping and Alpha using two generated source images

Sun May 31, 2020 5:15 am

That's an interesting way to do it Rich. I'll bet that ffmpeg can do it too with the proper script. I still think its a lot easier to do it in Gimp, especially if you need to edit the mask.

Re: Clipping and Alpha using two generated source images

Sun May 31, 2020 5:21 am

Agreed if you want to do one at a time.

There is a script that helps with the layer mask: One of Saul Goodes scripts copy-mask-from-above.scm

http://chiselapp.com/user/saulgoode/rep ... from-above

Does what it says. Saves having to - add layer mask / copy / paste / anchor
Post a reply