FW: Question on copy from selection
This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
FW: Question on copy from selection | hcabral@excite.com | 05 Oct 04:45 |
FW: Question on copy from selection | saulgoode@flashingtwelve.brickfilms.com | 05 Oct 09:08 |
FW: Question on copy from selection | hcabral@excite.com | 06 Oct 05:55 |
FW: Question on copy from selection
Apologies if people get this duplicated but I didn't receive my own message and thought it may have been lost.
----------------------------------------------------------
Hi there,
I have a question on copying a portion of an image in gimp. First, a little context. I needed to create a layer with only some features in an image. For that, I first selected a suitable area in the image using the "Free Select" tool. I then copied its contents (Edit -> Copy) and pasted it (Edit -> Paste) in a new layer (Layer -> New Layer). This creates a new layer with only the desired features, as can be verified making the new layer the only visible layer. Now, if I go to the "Channel Dialog", I can see the RGB and alpha channels looking right, with only the selected features there. However, if I make a copy of one of the RGB channels (right-click on the R channel, for example, and duplicate it), there is more than just those features, as can be verified by making it the only vi sible channel.
My question then is if this is a correct behavior and if so, how can I make a copy of a selection with only the contents of that selection? Thank you,
Hermano
FW: Question on copy from selection
Quoting "hcabral@excite.com" :
I have a question on copying a portion of an image in gimp. First, a little context. I needed to create a layer with only some features in an image. For that, I first selected a suitable area in the image using the "Free Select" tool. I then copied its contents (Edit -> Copy) and pasted it (Edit -> Paste) in a new layer (Layer -> New Layer). This creates a new layer with only the desired features, as can be verified making the new layer the only visible layer. Now, if I go to the "Channel Dialog", I can see the RGB and alpha channels looking right, with only the selected features there. However, if I make a copy of one of the RGB channels (right-click on the R channel, for example, and duplicate it), there is more than just those features, as can be verified by making it the only visible channel.
My question then is if this is a correct behavior and if so, how can I make a copy of a selection with only the contents of that selection? Thank you,
First it should be realized that layers are always rectangular in shape. The new layer you created, even though it might an oval or some freedrawn shape, will still be rectangular (the smallest rectangle aligned with the XY-axes that fits the shape). The regions that lie outside of your selection but within the layer bounds still contain RGB data; however, the alpha channel is set to make those areas transparent. (You probably know this already, I just want to lay the foundation.)
As to whether the behavior of the thumbnail previews for the RGBA components is correct: well, sort of. What you are seeing in the Channels Dialog is that the thumbnail previews of the RGB components have the Alpha channel applied to them; even though the actual contents of the RGB channels are still there (the corresponding alpha data renders it transparent).
Even though the preview of the components don't display the RGB data, when you Duplicate the channel, that data (which was obscured by the alpha channel) gets copied to the duplicate.
http://flashingtwelve.brickfilms.com/GIMP/Temp/GIMP-challenge.png is a sample image that will demonstrate this clearly. The RGB data of the image contains a photo of the Eiffel Tower, however, the alpha channel is black rendering the image completely transparent (and the previews in the Channels dialog will all be black). If you duplicate the Red channel (as you did for your selection) then the new channel will contain the original red data of the Eiffel Tower picture.
As to how to make a channel (or selection) out of the contents of the selection, there are a few different approaches.
Using your technique to produce the Red channel duplicate (which includes extraneous RGB data), go back to your new layer and perform an alpha to selection. Then invert the selection, activate your Red channel duplicate, and perform an "Edit->Fill with BG Color" (assuming your BG is black).
OR...
After copying your selection to a new layer, perform a "Layer->Layer to Image Size" and drag it over to the Channels window. (If you want just the red channel data, you should hide the green and blue components and do a "Copy visible" when creating your new layer; otherwise your channel will be the overall RGB value.)
OR...
I wrote a script a while ago which creates a selection from a layer
(or channel, or mask). It honors a selection if one exists (that is,
the contents of the selected region become the selection) so if I am
understanding you correctly, it might suit your needs. The file for
the script is located at
http://flashingtwelve.brickfilms.com/GIMP/Scripts/layer-select.scm and
includes two other commands (all three commands are added to the
"Select" menu), so I will just describe them briefly:
"Select->Layer bounds" -- simply selects the entire layer; sort of like Select->All but if you switch layers the selection stays the same.
"Select->To Layer" -- creates a new layer out of the selection using the FG and BG colors. Uses BG color to represent 'selected', so default colors generate a proper mask. The new layer has the same dimensions as the image.
"Select->From Drawable" -- creates a selection from the contents of the selected region.
FW: Question on copy from selection
Hi there,
I would like to thank saulgoode@flashingtwelve.brickfilms.com for his very thorough reply to my question on the contents of the RGB channels of a layer created from a selection. He managed at once to make my question more understandable, give an explanation on gimp's behavior in this case, and provide solutions to the problem.
For what I needed (run a plug-in that would use the layer created from the selection to perform some operations on the original layer), due to an error in the plug-in I really needed the RGB channels to have information only in the areas selected, and after much tweaking (I'm not exactly a Gimp expert) I found out about the decompose function (image -> mode -> decompose), operated on the individual layers, and then applied compose to put them together in a single layer. Maybe not the simplest way but it worked (I actually ended up doing a workaround that doesn't use selection to create the layer but that's another story).
Thanks again. Regards,
Hermano Cabral
PS: Thanks also for the tip with the script. I think that it is going to be useful in many other situations, too.