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?".
RyanBram
Posts: 30 Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789
Post
by RyanBram » 2014-02-06T11:28:12-07:00
Hi.
I need some help for removing image background using another image as mask. The image is as following:
The result that I prefer is the image which also has semi transparent area in each edge, so it will look nice to be placed in many background colors.
Regards.
Last edited by
RyanBram on 2019-06-17T10:42:51-07:00, edited 3 times in total.
OS: Windows 7 Ultimate, 32-Bit
CPU: Intel Core i3 2350M @ 2.30GHz
RAM: 2.00 GB Single-Channel DDR3 @ 665MHz
IM Version: 6.8.3-8 2013-03-04 Q16
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-02-06T11:36:02-07:00
try
convert image \( mask -negate \) -alpha off -compose copy_opacity -composite result.png
if on windows use (...) rather than \(...\) and note there must be spaces on each side of the ( and ).
The -negate is because the mask needs to be white where you want to keep the other image unchanged and black where you want the other image to be transparent. You need to save to PNG or TIFF to maintain transparency. JPG does not support transparency.
RyanBram
Posts: 30 Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789
Post
by RyanBram » 2014-02-06T11:54:50-07:00
Many thanks for fast reply.
It works like charm.
Is it also possible for ImageMagick to create transparent and semi transparent image with these two pictures:
By the way, I cannot find any way to spoil those images, which make this thread a little bit messy. Sorry.
Regards.
Last edited by
RyanBram on 2019-06-17T10:43:29-07:00, edited 2 times in total.
OS: Windows 7 Ultimate, 32-Bit
CPU: Intel Core i3 2350M @ 2.30GHz
RAM: 2.00 GB Single-Channel DDR3 @ 665MHz
IM Version: 6.8.3-8 2013-03-04 Q16
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Post
by snibgo » 2014-02-06T12:37:51-07:00
You can make a mask, eg:
Code: Select all
convert screenshot_1.png screenshot_2.png -compose Difference -composite -fill white +opaque black m.png
and then do whatever you want, eg turn the man into a ghost:
Code: Select all
convert screenshot_1.png screenshot_2.png ( m.png -evaluate Multiply 0.7 ) -compose over -composite f.png
RyanBram
Posts: 30 Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789
Post
by RyanBram » 2014-02-06T13:15:35-07:00
I want to remove the background, so only the character left.
snibgo wrote: You can make a mask, eg:
Code: Select all
convert screenshot_1.png screenshot_2.png -compose Difference -composite -fill white +opaque black m.png
and then do whatever you want, eg turn the man into a ghost:
Code: Select all
convert screenshot_1.png screenshot_2.png ( m.png -evaluate Multiply 0.7 ) -compose over -composite f.png
Thanks snibgo for the tips. By combining your technique, with one from
Fred , the result is this:
Not as smooth as my previous result, but still acceptable.
So there isn't a technique to make the bleeding edge to become semi-transparent with ImageMagick, is it?
Cheers.
Last edited by
RyanBram on 2019-06-17T10:44:05-07:00, edited 2 times in total.
OS: Windows 7 Ultimate, 32-Bit
CPU: Intel Core i3 2350M @ 2.30GHz
RAM: 2.00 GB Single-Channel DDR3 @ 665MHz
IM Version: 6.8.3-8 2013-03-04 Q16
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Post
by snibgo » 2014-02-06T13:22:02-07:00
That's called "anti-aliasing" or "feathering". See further down the link fmw gave.
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-02-06T13:52:09-07:00
try
convert screenshot_1.png screenshot_2.png \
\( -clone 0 -clone 1 -compose Difference -composite -fill white +opaque black -blur 0x1 \) \
-delete 1 -alpha off -compose copy_opacity -composite screenshot_1_masked.png
or on windows
convert screenshot_1.png screenshot_2.png ^
( -clone 0 -clone 1 -compose Difference -composite -fill white +opaque black -blur 0x1 ) ^
-delete 1 -alpha off -compose copy_opacity -composite screenshot_1_masked.png
Increase or decrease the blur value from 1 as desired.
RyanBram
Posts: 30 Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789
Post
by RyanBram » 2014-02-06T14:17:34-07:00
fmw42 wrote: Increase or decrease the blur value from 1 as desired.
Did you mean -blur 0x1, -blur 0x2, -blur 0x3, ...
or -blur 1x1, -blur 2x1, -blur 3x1, ...
or both.
Sorry for any inconvenience.
OS: Windows 7 Ultimate, 32-Bit
CPU: Intel Core i3 2350M @ 2.30GHz
RAM: 2.00 GB Single-Channel DDR3 @ 665MHz
IM Version: 6.8.3-8 2013-03-04 Q16
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
fmw42
Posts: 25562 Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Post
by fmw42 » 2014-02-06T15:33:25-07:00
-blur radiusxsigma where radius=0 and sigma is varied. Using radius 0 tells IM to calculate it automatically. Sigma can be fractional (down to about 0.5). See
http://www.imagemagick.org/script/comma ... s.php#blur
RyanBram
Posts: 30 Joined: 2013-03-25T22:55:10-07:00
Authentication code: 6789
Post
by RyanBram » 2014-02-07T04:17:40-07:00
Hooray, amazing. Thanks.
Problem Solved.
OS: Windows 7 Ultimate, 32-Bit
CPU: Intel Core i3 2350M @ 2.30GHz
RAM: 2.00 GB Single-Channel DDR3 @ 665MHz
IM Version: 6.8.3-8 2013-03-04 Q16
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib