Page 1 of 1

complex color replacing for map

Posted: 2008-02-27T11:16:22-07:00
by Riticulus
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:
Image

how it should look like after the operation:

Image

Re: complex color replacing for map

Posted: 2008-02-28T21:55:11-07:00
by fmw42
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

Re: complex color replacing for map

Posted: 2008-03-02T23:29:59-07:00
by anthony
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.

Re: complex color replacing for map

Posted: 2008-03-03T01:50:01-07:00
by Riticulus
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.

Re: complex color replacing for map

Posted: 2008-03-03T02:06:59-07:00
by Riticulus
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
Image
green
Image
yellow
Image
orange
Image
red
Image

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.

Re: complex color replacing for map

Posted: 2008-03-03T13:39:48-07:00
by fmw42
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.

Re: complex color replacing for map

Posted: 2008-03-03T14:58:00-07:00
by Riticulus
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!

Re: complex color replacing for map

Posted: 2008-03-03T19:46:11-07:00
by anthony
That may not produce exact colors, but near ones.

After reducing the image back, use

Code: Select all

   +dither -map colors.gif
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