I've got a program that users can upload images. The instructions say to always make the visual, background color 256 256 256; but they don't do so.
The images are simple street maps.
I'd like to be able to determine if the background is grey, light green, or whatever, and convert it to white.
Basically, I need the equivalent of the max bar on the histgram.
Anyone have a suggestion?
How can I determine the visual, background color?
-
- Posts: 2
- Joined: 2019-06-17T21:41:08-07:00
- Authentication code: 1152
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: How can I determine the visual, background color?
Please always provide your ImageMagick version and platform as syntax may vary. Also it is a good idea to provide what you have tried and an example image.
To determine the background color, one way is to simply measure it at some point that is background color, such as the top left corner, perhaps.
will return the color at the top left corner coordinate 0,0.
Then to change the color, you can either do a fuzzy replace of all colors similar to that everywhere or to flood fill the background starting at that point.
or
Another way might be to find the dominant (most frequent) color in the histogram.
For novices, see
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli
To determine the background color, one way is to simply measure it at some point that is background color, such as the top left corner, perhaps.
Code: Select all
convert image.suffix -format "%[pixel:u.p{0,0}]" info:
Then to change the color, you can either do a fuzzy replace of all colors similar to that everywhere or to flood fill the background starting at that point.
Code: Select all
convert image.suffix -fuzz XX% -fill white -opaque the_color_value result.suffix
Code: Select all
convert image.suffix -fuzz XX% -fill white -draw "color 0,0 flood fill" -alpha off result.suffix
Another way might be to find the dominant (most frequent) color in the histogram.
For novices, see
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli