Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a mask from a selection?
#8
(02-08-2026, 03:23 PM)Scallact Wrote:
(02-08-2026, 02:15 PM)ersc57 Wrote: Hi Scallact,

This is what I am thinking of...

Purpose: select an aera of a layer which should be filled with a new background by IOPaint.

what I am intending to do is:
copy the active layer to a new image (using edit_copy & edit_paste_as_new_image)
save this image to pass it on to IOPaint lateron
make the new image background black (using ?)
copy the selection to the new image (using image_get_selecten & save_selection)
make the selection white (using ?)
so then we have created a mask.
save this mask to disk (using an image)
Then feed the new image saved earlier and the mask to IOPaint
Insert the returned layer in the current image above the active layer
Set the original active layer to non-visible.

I don't know if this will work. Sometimes GIMP does not allow copying items from one image to another.
And how to make a selection white?

Ok, I think you will have to clear up some terms used here. Also, I don't fully understand the logic behind your steps yet, and I've got the feeling that you're over complicating it. So I can't give you detailed commands for every step, because you might just not end up anywhere. ;-)

First, terminology: 
What do you mean by "mask"? Apparently, it's not about a GIMP layer mask. Is it a mask that you pass to IOPaint ? Can you describe what this mask looks like? Is it a typical black/white layer that serves as mask (but still a layer for GIMP)?
"Make the selection white". You don't make a selection white, you fill it with white, on a specific drawable (a drawable can be a layer, a layer mask, a channel, etc...)

Steps:
If I understood the mask thing right, why not create it on the first image, where you already have the selection active? This would save you the transfer of the selection to another image.
Even more simplification: since apparently you must save an image to the disk (and the mask I guess?), why not do it from the original image as well? I don't know, just suggestions.

Hi Scallact,

thank you for thinking with me. You may be right that I overcomplicate things. That's why I was looking for some help.

Terminology: 
You are right, by mask I mean an image with one layer that is pure black with a selection that is pure white. This is one of the input files for IOPaint inpaint.
The selection should indeed be filled with white.

Purpose:
The intention is to perform the 'inpaint with IOPaint' command in GIMP on the active layer of the active image. This layer should contain a selection. IOPaint will fill the selection with a generated background and I want the new layer with this filled selection to be inserted just above the current layer, while setting the visibility of the current layer to False. The newly inserted layer becomes the active layer.

Limitations:
Saving files to disk is needed to pass them on to IOPaint, as IOPaint is running in a sandboxed Conda environment.
The active image should not be altered in any way, expect for inserting the new layer in the end.
This command should only affect the active layer of the active image (in fact even not that, as the original layer will stay in place, see Purpose).
In GIMP a layer can only belong to one image, so we will have to duplicate a layer to get the same layer in another image. But maybe we can do something different using selections?

Steps:
1 Save active layer from the active image to a PNG temp file
  This already works.

2 Make a "mask" from the selection and save this as second temp file.
  This is the tricky part for me.
  Can I do this from the original image without changing this original image?

3 Feed both temp files to IOPaint
  I know how to do this.

4 Insert resulting layer in original image
  I know how to do this.

5 Toggle visibility of original active layer
  I know how to do this.

Most steps are (almost) equal to the steps I needed for Remove_Background with IOPaint.
That plugin works.
The only issue for me is step 2 - Making the black & white "mask" temp file. 

Is this more clear?


P.S. Rich2005 has directed me to an example plugin. I appreciate that and am looking into it, but it needs some studying as it is a very structured but also complex plugin. I would be very happy with some other input on this matter. :-)
Reply


Messages In This Thread
How to make a mask from a selection? - by ersc57 - 02-07-2026, 08:54 AM
RE: How to make a mask from a selection? - by ersc57 - 02-09-2026, 04:33 PM

Forum Jump: