keep color instead of replace color

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?".
Post Reply
luckyluca
Posts: 12
Joined: 2011-10-04T13:25:21-07:00
Authentication code: 8675308

keep color instead of replace color

Post by luckyluca »

Hello,

This is my first post, I hope to be as concise as I can :)
I've got a few small points that I got stuck with and will need your help. I took a look at examples unsuccessfully.

1)
I need to select a color from an image and replace everything else with black.
It's pretty much similar to
convert FILE -fuzz 60% -fill black -opaque green FILEOUT
except that instead of replacing the color, I want to keep it and replace everything else.

2)
Is there a nice way to pixelate ( similarly to mode or median ) by limiting the operation on a given color?

Thanks
Luca
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: keep color instead of replace color

Post by anthony »

luckyluca wrote:1)
I need to select a color from an image and replace everything else with black.
It's pretty much similar to
convert FILE -fuzz 60% -fill black -opaque green FILEOUT
except that instead of replacing the color, I want to keep it and replace everything else.
Use the + form of the option. EG: -fill black -fuzz 25% +opaque blue

If you IM is not modern enough for +opaque (added IM v6.3.7-10) there is a masking method that will also let you do this.

For this and more see
color Basics, Replace a Specific Color (invert color selection example)
http://www.imagemagick.org/Usage/color_basics/#opaque
Color Basics, Fuzz Factor Distance
http://www.imagemagick.org/Usage/color_ ... z_distance
Is there a nice way to pixelate ( similarly to mode or median ) by limiting the operation on a given color?
Not directly. For that you will need to generate a mask, and then either use that mask as a 'write mask' or a compose mask for the pixelated form of the image.

For example... Protect Someone's Anonymity -- fuzzing out some part of a photo
http://www.imagemagick.org/Usage/photos/#anonymity

Pixelation can be performed in a number of ways, such as Basically anything that removes detail, used over a much larger area than normal, could be used!
Thanks
Luca
your welcome! 8)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
luckyluca
Posts: 12
Joined: 2011-10-04T13:25:21-07:00
Authentication code: 8675308

Re: keep color instead of replace color

Post by luckyluca »

Thanks Anthony, I'm on windows and can't seem able to find any binary newer than 6.729 though.

In the case of planB (use of older versions of imagemagick) how would the following look like with the old masking method?
convert FILEIN -fill black -fuzz 95% +opaque 'rgb(255, 255,255)' FILEOUT

I now am quite close but I'm not sure where to place -fuzz and whether I need -matte and -transparent in:
convert FILEIN ( +clone -matte -transparent white -fill black -colorize 100% ) -composite FILEOUT

Sorry I'll have to sit down with the example html properly. Thanks for the pixelate headsup I'll look into it.

Thanks
Luca
anthony wrote:
luckyluca wrote:1)
I need to select a color from an image and replace everything else with black.
It's pretty much similar to
convert FILE -fuzz 60% -fill black -opaque green FILEOUT
except that instead of replacing the color, I want to keep it and replace everything else.
Use the + form of the option. EG: -fill black -fuzz 25% +opaque blue

If you IM is not modern enough for +opaque (added IM v6.3.7-10) there is a masking method that will also let you do this.

For this and more see
color Basics, Replace a Specific Color (invert color selection example)
http://www.imagemagick.org/Usage/color_basics/#opaque
Color Basics, Fuzz Factor Distance
http://www.imagemagick.org/Usage/color_ ... z_distance
Is there a nice way to pixelate ( similarly to mode or median ) by limiting the operation on a given color?
Not directly. For that you will need to generate a mask, and then either use that mask as a 'write mask' or a compose mask for the pixelated form of the image.

For example... Protect Someone's Anonymity -- fuzzing out some part of a photo
http://www.imagemagick.org/Usage/photos/#anonymity

Pixelation can be performed in a number of ways, such as Basically anything that removes detail, used over a much larger area than normal, could be used!
Thanks
Luca
your welcome! 8)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: keep color instead of replace color

Post by fmw42 »

6.729 is the most current version

It should support all the features Anthony mentioned.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: keep color instead of replace color

Post by anthony »

luckyluca wrote:Thanks Anthony, I'm on windows and can't seem able to find any binary newer than 6.729 though.

In the case of planB (use of older versions of imagemagick) how would the following look like with the old masking method?
convert FILEIN -fill black -fuzz 95% +opaque 'rgb(255, 255,255)' FILEOUT

I now am quite close but I'm not sure where to place -fuzz and whether I need -matte and -transparent in:
convert FILEIN ( +clone -matte -transparent white -fill black -colorize 100% ) -composite FILEOUT
Fred is right that is the latest, so +opaque should work direct. The addition was a VERY long time ago.

Explanation of alternative method (as a FYI)...

The operator -transparent is similar to opaque. In this case make the matching color transparent. As this is what uses -fuzz the -fuzz should be just before it. The -matte is built in to -transparent so is not needed.
The non-transparent colors are then set to 'black' (the -fill for no-match) and the result composed onto the original image to make non-match black and restore the match colors to there original values.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply