replace color in images
-
- Posts: 38
- Joined: 2010-12-14T03:56:10-07:00
- Authentication code: 8675308
replace color in images
i want to replace the color in image with another color in the image.
Like i want to replace white color with another color like red.
please help me in solving this problem....
Like i want to replace white color with another color like red.
please help me in solving this problem....
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: replace color in images
convert image -fuzz XX% -fill red -opaque white result
where -fuzz XX% allows the match to white to get colors within XX% of white. If you want a perfect match remove the -fuzz XX% or set XX% to 0
see
http://www.imagemagick.org/Usage/color_basics/#replace
see color definitions at http://www.imagemagick.org/script/color.php
where -fuzz XX% allows the match to white to get colors within XX% of white. If you want a perfect match remove the -fuzz XX% or set XX% to 0
see
http://www.imagemagick.org/Usage/color_basics/#replace
see color definitions at http://www.imagemagick.org/script/color.php
Last edited by fmw42 on 2011-03-01T20:05:38-07:00, edited 2 times in total.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: replace color in images
The bigger question... Is it just red, or all shades of red to shades of some other color?
That is a much harder problem and may need a look at a small example of the image you are processing.
That is a much harder problem and may need a look at a small example of the image you are processing.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: replace color in images
I have a similar problem. The PNG images generated by ditaa have an invariable background and margin of rgb(254,254,254) which I want to crop off. The tools I have tried (converting to PDF and using pdfcrop, or converting to PNM and using pnmcrop) fail because the background and margin are not rgb{255,255,255). I have tried to convert the pixels, but this fails:
I am testing the result by opening the output in GIMP and using the eyedropper to pick the top right pixel: it remains rgb(254,254,254).
I have obviously misunderstood how to do this: does anyone have the necessary incantation?
I then want to crop off all margin: is there an argument to -crop that will simply remove all margin in the background color, in the same way as pdfcrop or pnmcrop do, without having to measure each image and specify how much to crop off?
Code: Select all
convert $NAME.png -fuzz 0% -fill 'rgb(254,254,254)' -opaque 'rgb(255,255,255)' foo.png
I have obviously misunderstood how to do this: does anyone have the necessary incantation?
I then want to crop off all margin: is there an argument to -crop that will simply remove all margin in the background color, in the same way as pdfcrop or pnmcrop do, without having to measure each image and specify how much to crop off?
Re: replace color in images
A sample image would help and you can use -trim to remove a border.
Code: Select all
convert $NAME.png -trim foo.png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: replace color in images
If your background is not a constant value, then increase the fuzz value. But if you just want to crop off the border, then as Bonzo suggests, useconvert $NAME.png -fuzz 0% -fill 'rgb(254,254,254)' -opaque 'rgb(255,255,255)' foo.png
convert $NAME.png -fuzz X% -trim +repage foo.png
The +repage is needed to clear the larger virtual canvas. Choose X% as small a possible such that it trims the way you want. 0 may not be enough as that requires a perfectly constant background color.
-
- Posts: 2
- Joined: 2015-12-24T05:48:54-07:00
- Authentication code: 1151
Re: replace color in images
Unable to replace red color with green which is not exactly red i.e. shade of red ( #484848 )
-
- Posts: 2
- Joined: 2015-12-24T05:48:54-07:00
- Authentication code: 1151
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: replace color in images
Your red color is #C62529. (#484848 is gray)
This works for me:
Why does your image have two suffixes .jpg and .png?
This works for me:
Code: Select all
convert 15nnfhk.jpg.png -fuzz 10% -fill green1 -opaque "#C62529" result.png
Re: replace color in images
It looks to me as though you've got it backwards. Your command changes all pure white pixels to 254,254,254.frisket wrote:I have a similar problem. The PNG images generated by ditaa have an invariable background and margin of rgb(254,254,254) which I want to crop off. The tools I have tried (converting to PDF and using pdfcrop, or converting to PNM and using pnmcrop) fail because the background and margin are not rgb{255,255,255). I have tried to convert the pixels, but this fails:I am testing the result by opening the output in GIMP and using the eyedropper to pick the top right pixel: it remains rgb(254,254,254).Code: Select all
convert $NAME.png -fuzz 0% -fill 'rgb(254,254,254)' -opaque 'rgb(255,255,255)' foo.png
I have obviously misunderstood how to do this: does anyone have the necessary incantation?
I then want to crop off all margin: is there an argument to -crop that will simply remove all margin in the background color, in the same way as pdfcrop or pnmcrop do, without having to measure each image and specify how much to crop off?