Mask usage
Mask usage
Hi,
this is my first post here, after looking around the web I couldn't find the answer to this issue, which most probably have a very basic solution.
I want to merge 2 images by using a mask so I will have :
1.- original image a.jpg ( background )
2.- new image b.jpg ( over the background)
3.- mask image mask.jpg
explained graphically would be something like :
Any code sample on how to get to point 4 ?
would that work equally with a mask that has a gradient ?
thanks in advance
this is my first post here, after looking around the web I couldn't find the answer to this issue, which most probably have a very basic solution.
I want to merge 2 images by using a mask so I will have :
1.- original image a.jpg ( background )
2.- new image b.jpg ( over the background)
3.- mask image mask.jpg
explained graphically would be something like :
Any code sample on how to get to point 4 ?
would that work equally with a mask that has a gradient ?
thanks in advance
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Mask usage
When you have a question here you need to give us more information. At the very least you should always let us know which version of IM you're using and what platform or OS you're working on. The answers can be a bit different – or a lot – depending on your set-up. Read the instructions at THIS link to learn how to form a proper question.jordi wrote: ↑2018-04-19T04:31:01-07:00I want to merge 2 images by using a mask so I will have :
1.- original image a.jpg ( background )
2.- new image b.jpg ( over the background)
3.- mask image mask.jpg
[...]
Any code sample on how to get to point 4 ?
would that work equally with a mask that has a gradient ?
That said, the simplest composition with a mask should work with a command like this...
Code: Select all
convert image1.png image2.png mask.png -composite result.png
Code: Select all
convert image1.png image2.png \( mask.png -blur 0x10 \) -composite result2.png
The command above is in *nix shell command syntax. To use the same command in Windows CMD you need to remove the backslashes that escape the parentheses. Change this "\(...\)" to this "(...)". If you're using ImageMagick v7, use "magick" instead of "convert".
The page at THIS link describes the usage of the "-composite" operator in detail.
Re: Mask usage
Thanks so much for the answer !
it works perfect !
sorry for not pointing my version, which is ImageMagick 7.0.7-14 Q16 x86_64 2017-12-07 working on mac.
I wanted to try the blur using a mask but, seems to works in a inverse way than what suggested above.
So I found a way to invert the colors of the mask
But I think there must be a way to avoid having to invert the mask, isn't it ?
Thanks again !
Kind regards
it works perfect !
sorry for not pointing my version, which is ImageMagick 7.0.7-14 Q16 x86_64 2017-12-07 working on mac.
I wanted to try the blur using a mask but, seems to works in a inverse way than what suggested above.
Code: Select all
convert original.jpg : -mask mask.jpg -alpha off \
-blur 0x8 +mask original_blured.jpg
Code: Select all
convert mask.jpg -colorspace HSI -channel B -level 100,0% +channel -colorspace sRGB mask_reversed.jpg
But I think there must be a way to avoid having to invert the mask, isn't it ?
Thanks again !
Kind regards
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Mask usage
The mask is doing something a bit different with "-mask" and "-composite". If your mask needs to be inverted to work in a particular command, you can read in the mask inside some parentheses and negate it, blur it, or whatever before continuing like this...
Code: Select all
... \( mask.jpg -alpha off -negate \) ...
Re: Mask usage
Hi, thanks and sorry because I did try code above merged with the one I was using to blur, and could not make it work
Code: Select all
convert original.jpg : \( mask.jpg -alpha off -negate \)
-blur 0x8 +mask original_blured.jpg
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Mask usage
That looks like a badly formed command. If you're using "-mask" you need to specify a file or a memory register "mpr:". The command would be assembled something like these...jordi wrote: ↑2018-04-20T02:07:45-07:00 Hi, thanks and sorry because I did try code above merged with the one I was using to blur, and could not make it work
Code: Select all
convert original.jpg : \( mask.jpg -alpha off -negate \) -blur 0x8 +mask original_blured.jpg
Code: Select all
convert input.jpg -mask mask.jpg -blur 0x8 +mask result.jpg
Code: Select all
convert input.jpg \( mask.jpg -negate -write mpr:test123 +delete \) -mask mpr:test123 -blur 0x8 +mask result.jpg
Re: Mask usage
GREAT !! thanks again !
Re: Mask usage
Just last question about masking, this time using polygons
I've seen this method which seems very interesting in some cases, I have been looking for a method to declare more than one polygon at a time, but could find any tip on the issue.
Is there some method top declare multiple polygon to operate some blur or fill ?
thanks again , and kind regards
Code: Select all
convert \
logo.jpg \
\( -clone 0 -fill white -colorize 100 -fill black \
-draw "polygon 332,180 427,105 481,238 399,279" \
-alpha off -write mpr:mask +delete \) \
-mask mpr:mask -blur 0x5 +mask logo_blur.jpg
Is there some method top declare multiple polygon to operate some blur or fill ?
thanks again , and kind regards
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Mask usage
Just draw multiple polygons to the same mask image. You can string different polygons in the same -draw or use multiple draws.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Mask usage
As Fred says, just draw as many polygons as you want, for example:jordi wrote:... a method to declare more than one polygon at a time
Code: Select all
-draw "polygon 332,180 427,105 481,238 399,279 polygon 0,0 0,200 200,0"
snibgo's IM pages: im.snibgo.com
Re: Mask usage
thanks great !