Good evening..
I hope someone can shed some light at my problem:
The image you see is part of a map which is created by my GIS server. You see different areas seperated by a grey border.
I would like to change the border color to the color of the surronding area. Should a border be between two different colors it doesnt really matter wether it become green or yellow.
At the end I would like not to see any border at all. Is this possible?
I tried to create a very large image before and hoped that after resizing the image to a smaller size would make the border vanish, but it didnt give me any good results.
Has anyone done this before, or could someone push me in the right direction?
before:
how it should look like after the operation:
complex color replacing for map
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: complex color replacing for map
Note that your histogram shows four colors! There are five odd colored pixels that appear to be more in the green area:
Histogram:
82796: (255,255, 0) #FFFF00 yellow
75818: ( 40,215, 97) #28D761 rgb(40,215,97) <- green
3669: (218,218,218) #DADADA rgb(218,218,218) <- gray roads
5: ( 19,224,124) #13E07C rgb(19,224,124) <- odd colored pixels
Here is one solution:
Change green and yellow to black and white and road gray to middle gray, then average 3x3, then threshold at 50%, then change black and white back to green and yellow
convert sample.gif \
-fill white -opaque yellow \
-fill black -opaque "rgb(40,215,97)" \
-fill black -opaque "rgb(19,224,124)" \
-fill "rgb(128,128,128)" -opaque "rgb(218,218,218)" \
-convolve "1,1,1,1,1,1,1,1,1" -threshold 50% \
-fill yellow -opaque white \
-fill "rgb(40,215,97)" -opaque black \
sample_new.gif
Histogram:
82796: (255,255, 0) #FFFF00 yellow
75818: ( 40,215, 97) #28D761 rgb(40,215,97) <- green
3669: (218,218,218) #DADADA rgb(218,218,218) <- gray roads
5: ( 19,224,124) #13E07C rgb(19,224,124) <- odd colored pixels
Here is one solution:
Change green and yellow to black and white and road gray to middle gray, then average 3x3, then threshold at 50%, then change black and white back to green and yellow
convert sample.gif \
-fill white -opaque yellow \
-fill black -opaque "rgb(40,215,97)" \
-fill black -opaque "rgb(19,224,124)" \
-fill "rgb(128,128,128)" -opaque "rgb(218,218,218)" \
-convolve "1,1,1,1,1,1,1,1,1" -threshold 50% \
-fill yellow -opaque white \
-fill "rgb(40,215,97)" -opaque black \
sample_new.gif
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: complex color replacing for map
Note however that this changes each border pixel to the largest number of green or yellow pixels that surround it on a case by case bases.
that is one border pixel could become yellow, while the neighbor border pixel could become green.
It is however probably the best and simplest solution, better than a similar but flawed solution I first thought of.
that is one border pixel could become yellow, while the neighbor border pixel could become green.
It is however probably the best and simplest solution, better than a similar but flawed solution I first thought of.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: complex color replacing for map
wow many thanks to you for your help. I nearly lost hope to find a solution for that. I really do owe you something.
My best wishes from switzerland.
My best wishes from switzerland.
Re: complex color replacing for map
dear all,
There is one more question regarding this issue i would like to bother you with:
The maps can have up to 5 fill colors:
white
green
yellow
orange
red
so in order to make your sample work, would i assign those colors different shades of grey to make the convolve command work?
many thanks again.
There is one more question regarding this issue i would like to bother you with:
The maps can have up to 5 fill colors:
white
green
yellow
orange
red
so in order to make your sample work, would i assign those colors different shades of grey to make the convolve command work?
many thanks again.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: complex color replacing for map
I am not sure that will work. You can try it, but then you have multiple thresholds to select. This gets very complicated. The solution I supplied earlier depended upon only two colors plus the gray road. I suspect that you may have to create transparency masks so that you can work on pairs of colors at a time and then repeat for each color combination.
Post an example and if I get some time, I will look at it further.
Post an example and if I get some time, I will look at it further.
Re: complex color replacing for map
I think I found a solution for that:
I produce the image with a width of 3072 pix
After that I am using the -median filter with a radius value of 2. Then I resize the image back to 1024pix.
The result is exactly what i need.
Many thanks again for your time!
I produce the image with a width of 3072 pix
After that I am using the -median filter with a radius value of 2. Then I resize the image back to 1024pix.
The result is exactly what i need.
Many thanks again for your time!
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: complex color replacing for map
That may not produce exact colors, but near ones.
After reducing the image back, use where "colors.gif" is a image only containg those 5 colors (only needs to be a 5 pixel image).
That will ensure that colors map back to the nearest given color in the colormap (in RGB color space distances).
See IM Examples, Quantization and Dithering
http://imagemagick.org/Usage/quantize/#map
After reducing the image back, use
Code: Select all
+dither -map colors.gif
That will ensure that colors map back to the nearest given color in the colormap (in RGB color space distances).
See IM Examples, Quantization and Dithering
http://imagemagick.org/Usage/quantize/#map
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/