I am trying to create a machine learning plug-in to help with the creation of training data. I find that GIMPs selection tools are so easy, simple and quick to use, therefore is there a way to export a selected region to a different image of the same size in the same position and then to block colour it? (this will be done procedurally, however I am not sure how to even do this through the GIMP interface) any help appreciated.
2 Answers
If the target image exists (with the same size)
- Create a selection in source image
- Save to channel (
Select ➤ Save to Channel
) - Open the Channels list
- Drag the thumbnail of the saved selection to the canvas of the target image where it will become a layer (white selection on black background)
If the target image doesn't exist yet
- Create a selection in the source image
- Save to channel (
Select ➤ Save to Channel
) - Open the Channels list
- Click the saved selection channel (this makes it the active "drawable"(*))
Select ➤ All
(Ctrl-A)Edit ➤ Copy
(Ctrl-C)Edit ➤ Paste as ➤ new image
(Ctrl-Shift-V). This creates a grayscale image.
Note: there is no one-to-one mapping between UI operations and the API, but the API can be simpler and you can likely duplicate the selection mask to a "drawable" in the other image, but this matter is better handled on StackOverflow.
(*) a "drawable" is an object on which you can alter pixels: layer, layer mask, or channel.
- Make a selection of something
- Edit > Copy
- Image > Duplicate
- Click on the tab for the new document
- Delete the existing image layer in the layers panel
- Edit > Paste in Place
- Select > None
- Choose a new foreground colour
- Engage the alpha lock (in the layers panel)
- Edit > Fill with FG colour