> On Fri, 24 Jul 2009 20:06:14 +1000 (EST)
> "damien dunlop" <[email protected]> wrote:
>
> | Response to `Extract one colour'
> |
> | | Suppose a multi-coloured RGB image contains areas of
> | | a certain RGB value (within a small tolerance).
> | |
> | | Using ImageMagick, is it possible to change all other colours | | to
a background colour, leaving the image with just the specified | | colour
and the background colour.
> | |
> |
> | >>
> | >> -fill white +opaque red
> | >>
> | >> that will replace anything not pure red to white
> | >> Add a -fuzz factor if you want 'near pure red'.
> | >>
> | >> -fuzz XX% -fill backgroundcolor +opaque yourcolor
> |
> | Thanks to Fred and Anthony for the response above, it works!
> |
> | But to take it further, I want to
> |
> | a) Extract certain colours from a multi coloured image and
> | then combine the extracted areas in a composite image, with all |
other colours changed to a background colour.
> |
> | b) The same as a) but creating individual images (which may
> | be inspected and modified a little as individual images)
> | then combining the lot to achieve a composite image as in a). | | I
did try various command combinations but always ended up with | the final
image consisting of only the background.
> |
> | Damien
> |
>From Fred
>Not quite sure about what you want, but taking a stab -- use
>transparent for the background
>A)
>convert \( image -fuzz XX1% -fill none +opaque color1 \) \
> \( image -fuzz XX2% -fill none +opaque color2 \) \
> \( image -fuzz XX3% -fill none +opaque color3 \) \
> ...
> \( image -fuzz XXN% -fill none +opaque colorN \) \
> -background yourbackgroundcolor -flatten resultimage
>B)
>convert \( image -fuzz XX1% -fill none +opaque color1 -write image1 \) \
> \( image -fuzz XX2% -fill none +opaque color2 -write image2 \) \
\( image -fuzz XX3% -fill none +opaque color3 -write image3 \) \
...
> \( image -fuzz XXN% -fill none +opaque colorN -write imageN \) \
null:
>convert image1 image2 image3 ... imageN -background
>yourbackgroundcolor -flatten resultimage
********************************
> correction: seems that one has to add -channel rgba -alpha on after
"image" to enable the transparency.
Thanks Fred
With the correction these do work. Original.gif below consists of
horizontal lines of various colours including red, green blue. For
convenience I have used variables for the wanted colours and the
script runs in a Korn Shell. For the purposes of the test, the colours are
known exactly.
#Testcolours
red="rgb(255,0,0)"
green="rgb(0,255,0)"
blue="rgb(0,0,255)"
# A)
convert \( base.gif -channel rgba -alpha on -fuzz 0% -fill none \
+opaque 'rgb(236,135,14)' \) \
\( base.gif -channel rgba -alpha on -fuzz 0% -fill none \
+opaque 'rgb(180,155,31)' \) \
\( base.gif -channel rgba -alpha on -fuzz 0% -fill none \
+opaque 'rgb(0,172,75)' \) \
-background white -flatten result1.gif
# B)
convert \( original.gif -channel rgba -alpha on -fuzz 0% -fill none \
+opaque "$red" -write red.gif \) \
\( original.gif -channel rgba -alpha on -fuzz 0% -fill none \
+opaque "$green" -write green.gif \) \
\( original.gif -channel rgba -alpha on -fuzz 0% -fill none \
+opaque "$blue" -write blue.gif \) \
null:
convert red.gif green.gif blue.gif -background white -flatten result2.gif
>From Anthony
> See
> http://www.imagemagick.org/Usage/color/#fuzz
>
> Look for the example the produces a flower like image...
>
> convert colorwheel.png -channel A \
> -fuzz 25000 -transparent blue -transparent red -transparent
lime
> \
> -fuzz 11000 -transparent black -negate +channel \
> -background white -flatten opaque_multi_inv.png
>
> This uses a trick that first makes the selected color transparent But
only sets the transparency, it does not change the color itself.
>
> Then it negates the transparency so that the colors you were making
transparent, actually ends up opaque! and the unselected colors ended up
transparent.
>
> I then flatten a white background underneath.
>
> Basically it is exactly what you are wanting!!!!
Thanks Anthony.
This does work. Original.gif consists of horizontal lines of
various colours including red, green blue. For convenience I
have used variables for the wanted colours and the script
runs in a Korn Shell. For the purposes of the test, the colours
are known exactly.
# Test colours
red="rgb(255,0,0)"
green="rgb(0,255,0)"
blue="rgb(0,0,255)"
convert original.gif -channel A -fuzz 0% \
-transparent "$red" \
-transparent "$green" \
-transparent "$blue" \
-fuzz 0% -transparent black -negate +channel \
-background white -flatten result3.gif
Damien
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users