Composit 3 images using a single RGB mask
Composit 3 images using a single RGB mask
Is that possible to do with imagemagick? If so how?
basically I have three images which I want to composit together - image1.png, image2.png and image3.png.
And I have an extra RGB mask image that contains three masks - the red, the green and the blue channels are each used as a mask - rgbMask.png
so 4 images in total!
Out of that I want to create a result - Result.png that is composited of the three images like this:
image1.png uses the red channel of rgbMask.png
image2.png uses the blue channel of rgbMask.png
image3.png uses the green channel of rgbMask.png
How do I go about doing that?
The examples of the website show only how to do it with a single black and white mask
http://www.imagemagick.org/Usage/compose/#mask
basically I have three images which I want to composit together - image1.png, image2.png and image3.png.
And I have an extra RGB mask image that contains three masks - the red, the green and the blue channels are each used as a mask - rgbMask.png
so 4 images in total!
Out of that I want to create a result - Result.png that is composited of the three images like this:
image1.png uses the red channel of rgbMask.png
image2.png uses the blue channel of rgbMask.png
image3.png uses the green channel of rgbMask.png
How do I go about doing that?
The examples of the website show only how to do it with a single black and white mask
http://www.imagemagick.org/Usage/compose/#mask
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Composit 3 images using a single RGB mask
try (unix syntax)
If order is important arrange them appropriately. Last image will be composited over the previous ones or use -swap or -reverse to switch images.
Code: Select all
convert \
\( rgbmask.png -channel r -separate +channel image1.png \
+swap -alpha off -compose copy_opacity -composite \) \
\( rgbmask.png -channel g -separate +channel image2.png \
+swap -alpha off -compose copy_opacity -composite \) \
\( rgbmask.png -channel b -separate +channel image3.png \
+swap -alpha off -compose copy_opacity -composite \) \
-flatten result.png
Re: Composit 3 images using a single RGB mask
Hi,
Is it possible to do this in normal windows CMD terminal?
I cant use unix terminal on this system.
The syntax doesnt work here
Is it possible to do this in normal windows CMD terminal?
I cant use unix terminal on this system.
The syntax doesnt work here
Re: Composit 3 images using a single RGB mask
Probably but you would need to convert it. I would try this and see what happens:
This is all one long line; from memory you can use ^ to concate lines if you want to?
Code: Select all
convert ( rgbmask.png -channel r -separate +channel image1.png +swap -alpha off -compose copy_opacity -composite ) ( rgbmask.png -channel g -separate +channel image2.png +swap -alpha off -compose copy_opacity -composite ) ( rgbmask.png -channel b -separate +channel image3.png +swap -alpha off -compose copy_opacity -composite ) -flatten result.png
Re: Composit 3 images using a single RGB mask
@Bonzo That worked and actually produced a file - but the file was an empty white canvas instead of what I expected.
Also there was an error message:
I do feel like we are getting closer to this
Also there was an error message:
Code: Select all
convert: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG `
result.png' @ warning/png.c/MagickPNGWarningHandler/1683.
Re: Composit 3 images using a single RGB mask
I am afraid any more is out of my area of expertise !
There is a thread here which may help: viewtopic.php?t=27056 Possibly the mask is the wrong format of png? Although snibgo and fmw42 both say it is a warning and should work.
I think you will have to post some links to your images.
There is a thread here which may help: viewtopic.php?t=27056 Possibly the mask is the wrong format of png? Although snibgo and fmw42 both say it is a warning and should work.
I think you will have to post some links to your images.
Re: Composit 3 images using a single RGB mask
I dont think its a colorspace issue. I tried saving it as result.jpg and got no errors, however instead of composite I got a white empty canvas again.
So the syntax must be wrong, or the files that I am mixing must be difficult for imagemagick
So the syntax must be wrong, or the files that I am mixing must be difficult for imagemagick
Re: Composit 3 images using a single RGB mask
Here are the images:
http://imgur.com/a/d8eAR
http://imgur.com/a/d8eAR
Re: Composit 3 images using a single RGB mask
The images were created in Krita and saved as png with the default settings!
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Composit 3 images using a single RGB mask
So you have three images (colour or grayscale?), also three masks (in a single RGB image). You want to composite the three images according to the masks, but you haven't said what the rules are. What should happen where the mask image is exactly red? Or black? Or white?
Is your third image your mask? Is it smaller than the three images? Why? What should the output look like?
Also say what version of IM you are using.
Is your third image your mask? Is it smaller than the three images? Why? What should the output look like?
Also say what version of IM you are using.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Composit 3 images using a single RGB mask
Please post your images (to some place such as dropbox.com and put the URLs here). Also always provide your IM version and platform, since as you see syntax differs. See http://www.imagemagick.org/Usage/windows/
Try this fix. I think I know what the issue is. We need to reset the compose method before the -flatten. My mistake.
Try this fix. I think I know what the issue is. We need to reset the compose method before the -flatten. My mistake.
Code: Select all
convert ( rgbmask.png -channel r -separate +channel image1.png +swap -alpha off -compose copy_opacity -composite ) ( rgbmask.png -channel g -separate +channel image2.png +swap -alpha off -compose copy_opacity -composite ) ( rgbmask.png -channel b -separate +channel image3.png +swap -alpha off -compose copy_opacity -composite ) -compose over -flatten result.png
Re: Composit 3 images using a single RGB mask
That did it - however the result was messed up a bit because the mask image had a different size in pixels.
Can I equalize the size of all images to the same size of the first image somehow? I was wondering if imagemagick has a command for that!
Can I equalize the size of all images to the same size of the first image somehow? I was wondering if imagemagick has a command for that!
Re: Composit 3 images using a single RGB mask
Thank you guys - I learned a couple of valuable tricks in imagemagick.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Composit 3 images using a single RGB mask
It can be done, but you need to tell us what version of IM and platform you have. Are all the images and mask different sizes. If so, which ones differ? Are the aspect ratios different?blurymind wrote:That did it - however the result was messed up a bit because the mask image had a different size in pixels.
Can I equalize the size of all images to the same size of the first image somehow? I was wondering if imagemagick has a command for that!
However, if it is not just a scaling difference, then just resizing may still not allow the mask to composite the images aligned properly. You may have to pick control points and do -distort SRT to get them properly aligned.
Best if you can provide you input images so we can test with them. See my comments above about how to do that.
Re: Composit 3 images using a single RGB mask
I'm on windows, but also linux. The images have the same aspect ratio, but different sizes.
I guess this time I am looking for a separate command that takes the first specified image's pixel size and sets all the next images to that size
I guess this time I am looking for a separate command that takes the first specified image's pixel size and sets all the next images to that size