Page 1 of 1
How i apply a mask to a grayscale image ?
Posted: 2015-08-04T03:16:40-07:00
by nars
Hi,
I want apply a mask to an image. (image and mask have the same dimensions)
input.png (grayscale)
mask.png
I used the next code:
convert input.png mask.png -alpha off -compare CopyOpacity -composite out.png
The mask was applied correctly, but the out.png lost the grayscale (obviously), i think..
Suggestions for applying the mask and not lose the grayscale ?
thanks
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T05:18:36-07:00
by snibgo
Use "-compose" instead of "-compare":
Code: Select all
convert input.png mask.png -alpha off -compose CopyOpacity -composite out.png
If that doesn't help, upload inputs and output to somewhere like dropbox.com and paste the URLs here.
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T05:55:03-07:00
by nars
The same :/
Mask image:
Input image:
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T06:10:01-07:00
by snibgo
Code: Select all
convert 2z4er1s.png 14j5cmw.png -alpha off -compose CopyOpacity -composite outMasked.png
This is the result:
It looks fine to me. What result do you get? What is wrong with it?
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T08:19:48-07:00
by nars
yes, it looks fine.. Sorry, bad example :/
With the next images, you can see the differences.
input:
mask:
Thanks
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T08:27:09-07:00
by snibgo
Again, the result looks fine to me. What is wrong with it?
Code: Select all
convert elcqxy.jpg.png 2ueigev.jpg.png -alpha off -compose CopyOpacity -composite outMasked2.png
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T08:35:06-07:00
by nars
My result:
My code:
Code: Select all
convert input2.png mask2.png -alpha off -compose CopyOpacity -composite outMasked_2.png
Why is different?
Thanks
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T08:54:05-07:00
by fmw42
What version of IM and platform are you using?
Nothing is wrong with it. Your two examples are on different color backgrounds, which show through in the transparent areas.
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T09:18:30-07:00
by nars
Version: ImageMagick 6.7.7-10 2014-03-06
Platform: Linux - Ubuntu
Thanks
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T09:30:27-07:00
by snibgo
Your result is darker than mine, because your old version of ImageMagick 6.7.7-10 was confused between linear and non-linear grayscale. I suggest you upgrade to a recent version.
Re: How i apply a mask to a grayscale image ?
Posted: 2015-08-04T10:11:29-07:00
by nars
Yes, I update ImageMagick to a recent version and solved my problem.
Thanks