Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
-
chaoscarnage
- Posts: 93
- Joined: 2012-12-31T15:56:29-07:00
- Authentication code: 6789
Post
by chaoscarnage » 2012-12-31T16:05:09-07:00
I've been using the composite command to mask images and have run into a strange issue where an image I have is not being masked properly. I have tested the mask with other images and the mask has worked fine. Because of this, I think the issue lies with the source item being masked. I cannot for the life of me figure out why I get a blank image on output with this combination.
The command I'm using to test
Code: Select all
composite item.png canvas.png mask.png out.png
Any help would be greatly appreciated as I have no clue as to why it is failing. Thank you for your time.
Last edited by
chaoscarnage on 2013-01-01T08:38:50-07:00, edited 1 time in total.
-
snibgo
- Posts: 12431
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2012-12-31T18:00:23-07:00
"Item" has a mean alpha of < 1%, and canvas has alpha=0. So you are compositing a very nearly transparent image over an entirely transparent image. I would expect the output to be almost entirely transparent.
-
chaoscarnage
- Posts: 93
- Joined: 2012-12-31T15:56:29-07:00
- Authentication code: 6789
Post
by chaoscarnage » 2012-12-31T18:34:05-07:00
How can you tell and how can I fix it?
-
snibgo
- Posts: 12431
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2012-12-31T18:45:44-07:00
I know because I read your verbose listings. For example, near the top of "Item", "Alpha" mean is 1.84609 (out of 255). The colours are about 253. So the image is nearly white, but also close to totally transparent.
"Canvas" is a very boring image. All the pixels are rgba(255,255,255,0). (I can tell by looking at the min and max of the four channels.) Every pixel is transparent white.
How can you fix it? Well, I don't know what you are trying to do.
-
chaoscarnage
- Posts: 93
- Joined: 2012-12-31T15:56:29-07:00
- Authentication code: 6789
Post
by chaoscarnage » 2012-12-31T19:34:09-07:00
snibgo wrote:I know because I read your verbose listings. For example, near the top of "Item", "Alpha" mean is 1.84609 (out of 255). The colours are about 253. So the image is nearly white, but also close to totally transparent.
"Canvas" is a very boring image. All the pixels are rgba(255,255,255,0). (I can tell by looking at the min and max of the four channels.) Every pixel is transparent white.
How can you fix it? Well, I don't know what you are trying to do.
The desired result is the boot with a little of its edge clipped by the mask. Right now I am getting a blank image. Thank you for the quick response and explanation.
-
snibgo
- Posts: 12431
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2012-12-31T21:00:26-07:00
I rarely use the "composite" command; only when "convert" won't do the job I want. In this case, convert may do what you want:
Code: Select all
convert canvas.png item.png mask.png -composite out.png
(Note the order of canvas and item are inverted, compared to the "composite" command.)
This makes the top-left corner (about 3 pixels) of the boot transparent.
-
chaoscarnage
- Posts: 93
- Joined: 2012-12-31T15:56:29-07:00
- Authentication code: 6789
Post
by chaoscarnage » 2013-06-14T13:11:42-07:00
This works for strict on off masking. What about gradient masking? Ie Instead of black and white for 0 or 100% I want to include gray for the inbetweens(alpha) like 33%, 27%, 77% etc. That Way we could accomplish something similar to this post
Here but in command line.
-
chaoscarnage
- Posts: 93
- Joined: 2012-12-31T15:56:29-07:00
- Authentication code: 6789
Post
by chaoscarnage » 2013-06-14T13:57:12-07:00
Code: Select all
convert canvas.png item.png mask.png -composite out.png
We already have a mask in place but it does not account for graysacle in the mask image only strict on or off.
-
GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Post
by GreenKoopa » 2013-06-14T14:04:14-07:00
The method needed would depend on the images you are working on. Looking at that stackoverflow post, there is a source/background image in RGB and a alpha/mask image in RGBA. The mask image is entirely black, only the alpha channel varies. Are these images the actual ones you are trying to combine? Knowing the character of all input images is necessary to give advice.
-
chaoscarnage
- Posts: 93
- Joined: 2012-12-31T15:56:29-07:00
- Authentication code: 6789
Post
by chaoscarnage » 2013-06-14T14:14:45-07:00
GreenKoopa wrote:The method needed would depend on the images you are working on. Looking at that stackoverflow post, there is a source/background image in RGB and a alpha/mask image in RGBA. The mask image is entirely black, only the alpha channel varies. Are these images the actual ones you are trying to combine? Knowing the character of all input images is necessary to give advice.
Either way is fine we're just trying to get one that works, currently we use a RGB source and a black and white only image as the mask. If possible we would like to use a white->black gradient or transparent to black mask. We would prefer whichever way works or is better.
-
GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Post
by GreenKoopa » 2013-06-14T14:33:48-07:00
Since you didn't provide input images, I'll generate my best understanding of them.
Code: Select all
convert rose: -resize 300x200! source.png
convert -size 400x400 radial-gradient:white-black -gravity center -crop 300x200+0+0 mask.png
convert source.png mask.png -compose CopyOpacity -composite result.png
-
chaoscarnage
- Posts: 93
- Joined: 2012-12-31T15:56:29-07:00
- Authentication code: 6789
Post
by chaoscarnage » 2013-06-14T14:56:16-07:00
GreenKoopa wrote:Since you didn't provide input images, I'll generate my best understanding of them.
Code: Select all
convert rose: -resize 300x200! source.png
convert -size 400x400 radial-gradient:white-black -gravity center -crop 300x200+0+0 mask.png
convert source.png mask.png -compose CopyOpacity -composite result.png
Will it still work if we keep the canvas.png or is that not possible?
-
GreenKoopa
- Posts: 457
- Joined: 2010-11-04T17:24:08-07:00
- Authentication code: 8675308
Post
by GreenKoopa » 2013-06-14T15:10:31-07:00
canvas.png is a background? I am assuming that all of these input images are the same size.
Code: Select all
convert -size 300x200 gradient:silver-blue canvas.png
convert rose: -resize 300x200! source.png
convert -size 400x400 radial-gradient:white-black -gravity center -crop 300x200+0+0 mask.png
convert source.png mask.png -compose CopyOpacity -composite canvas.png +swap -compose Over -composite result.png
-
snibgo
- Posts: 12431
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2013-06-14T15:35:13-07:00
A grey-scale mask should work, eg:
Code: Select all
convert -size 100x100 xc:red xc:green gradient: -composite c.png
The result should be a gradient from red to green.