Page 1 of 1

Changing colors of an image

Posted: 2009-08-26T00:09:28-07:00
by bhattkrishna19
Hi ,

I am trying to change the colors of an image . following steps I am doing for the same:
1. Quantization of image color .
2 . then splitting images in all quantized colors.
3. now changing the colors
4. merging again to get the new image.

But image is not good as it was before.

Please suggest me the best way of changing the colors of an Image.


Regards
Krishna

Re: Changing colors of an image

Posted: 2009-08-26T09:30:05-07:00
by fmw42
please post examples of your process. it is hard to understand what you want and what does "not good" mean?

Re: Changing colors of an image

Posted: 2009-08-27T00:01:44-07:00
by bhattkrishna19
Hi Sir,

Thanks for reply.

I am summarizing all steps What we are trying to do :

Our goal is change the colors of an image .

Following steps we are doing :
1. We are manually finding that hows many prominent colors are in the image. and creating list of all used colors.
2. breaking image in all these used colors.
3. changing colors of these images and merging these images again to get the final image.
4. Final image contains many dots (due to some merging problem showing transparent space)

Please suggest me how we can achieve better result with excellent color quality.

Regards,
Krishna

Re: Changing colors of an image

Posted: 2009-08-27T08:08:57-07:00
by fmw42
I am not sure what you mean by "breaking image in all these used colors." Are you processing the image so that you have one color and then the rest is transparent and doing this repeatedly for all your selected colors.

I have a script called mapcolors that I think does what you want. You provide a file with the color translations you want and a safe color usually transparent and it processes the image to change each color in the image according to the translations (color mappings) in the file.

Re: Changing colors of an image

Posted: 2009-08-27T23:35:26-07:00
by bhattkrishna19
We have an image name rings.jpg Image

First we manually select used color from image(with the help of color picker) and put Hax value of color in an Array Like this.

$usedcolorArray = array("#FAF4DA","#B2CFBD","#449090","#82ABA5")


We are using this command to break original image in used colors

convert rings.jpg -matte \( +clone -fuzz 10% -transparent \ #FAF4DA \) -compose DstOut -composite rings_1.png


Now we run loop with this command to break images in used colors .

$name = "rings.jpg";
foreach ($usedcolorArray as $key => $val) {
$cmd = "convert $name -matte \( +clone -fuzz 10% -transparent \ $val \) -compose DstOut -composite rings_".$key.".png";
exec($cmd);
}

Now we get 4 png files according to used color.

Image
Image
Image
Image


Now we have following problem with this.

1. Segmented image are not good. There is some mixed or different colors come in other image.
e.g ( rings_1.png ).
Image

2. Now we changing color of selected image using following command.

convert ring_1.png -fuzz 50% -fill \#FF0000." -opaque \#B2CFBD ring_new.png

3. Now we combine all images one by one to create new image. But this image have some noise.
composite -geometry +0+0 rings_0.png rings_1.png Design.png

One more example we trying :
change the color of this Image
image based on input from the user means user will select any used color and color will changed :

Please suggest on these problems or if you have any other method for changing the colors of an image , please share with us.

Re: Changing colors of an image

Posted: 2009-08-28T08:52:45-07:00
by fmw42
You have a very difficult problem. You are trying to segment the image into 4 colors, but the issue comes from the antialiasing where the different colors are next to each other. Thus in the transition you have mixed colors that you will have a hard time separating in RGB color space.

Furthermore, you are using a jpg format which is lossy and will not keep constant colors, but will introduce variations in the colors.

Second, you have not shown the resulting image where you say there are defects showing. So we have no idea what the problem is. You also do not say or show what new colors you want to translate to.

You can see the issue by reducing the colors to 4.

Image

convert rings.jpg -quantize RGB +antialias -colors 4 ring4_rgb.gif
Image

or a slightly better job using HSL space

convert rings.jpg -quantize HSL +antialias -colors 4 ring4_hsl.gif
Image

So to start, can you generate your original images as gif or png rather than jpg? That would avoid a lot of noise.

Perhaps your use of fuzz will help that. But it will not avoid the issue of color blending near edges of different color.

Your concept is reasonable to use -fuzz, separate the image into its color components, change the colors, then composite. You need some kind of filtering of the component color images to remove the noise.

Re: Changing colors of an image

Posted: 2009-08-30T23:40:56-07:00
by bhattkrishna19
Hi,

We do the following steps as you know.

1. convert image in png.
2. segment image in 4 images according to used color.
3. change the color of image for selected color.
4. composite images to get new design.


Now I am giving you all images ( original and output after above process).

1. Original one.

Image

2.After changing color of one selected color.
newDesing1
Image


3. After changing color of second selected color.
newDesing2
Image


you can see in newDesign1 and in newDesing2. There is color blending near edges.
OR we can say that we are not able to generate expected result.
Can you suggest on the same.

Re: Changing colors of an image

Posted: 2009-08-31T00:11:51-07:00
by anthony
Use +dither with -colors 4

Re: Changing colors of an image

Posted: 2009-08-31T00:56:16-07:00
by bhattkrishna19
Hi,
When apply this original color of image is loosed.

Please suggest on the same.

Thanks

Re: Changing colors of an image

Posted: 2009-08-31T01:20:31-07:00
by anthony
It was as a adendum to Fwm43 methods. for the test image you will need to use HSL quantized space to get enough color seperation to generate 4 colors. In RGB space only three colors will be picked.!!

Code: Select all

convert rings.jpg -quantize HSL +dither -colors 4 rings_HSL.png
The +dither removes the speckling pattern which is 'dither noise'.

See IM Examples, Quantization for more information.
http://www.imagemagick.org/Usage/quantize/

You may also like to try color segmentation (-segment). though its arguments are different, and I have never had much success with it.

Re: Changing colors of an image

Posted: 2009-09-11T20:28:21-07:00
by fmw42
As per Anthony's example, convert to HSL with 4 colors.

convert rings.jpg -quantize HSL +dither -colors 4 -colorspace HSL -channel red -separate rings_HSL_color4_hue.png
identify -verbose rings_HSL_color4_hue.png
...
Histogram:
16453: ( 75, 75, 75) #4B4B4B rgb(75,75,75)
14900: ( 99, 99, 99) #636363 grey39
118378: (121,121,121) #797979 rgb(121,121,121)
22728: (126,126,126) #7E7E7E gray
...

So you see the histogram now has only 4 colors. You can assign each color to a new color value

convert rings_HSL_color4_hue.png \
-fill red -opaque "#4B4B4B" \
-fill green1 -opaque "#636363" \
-fill blue -opaque "#797979" \
-fill yellow -opaque "#7E7E7E" \
rings_new_colors.png

Unfortuntately, there seems to be some overlap that I don't understand.

Image

Re: Changing colors of an image

Posted: 2009-09-13T18:42:51-07:00
by anthony
this is suposedally where the difference between -color and -segment is.

-color works purely with the colors of the image without regard to their neighbourhood.

-segment is suposed to group nearby colors as well. But its arguemtns are so obtuse I have not really been able to make a good deal of sense to them. for one thing is it not a color limit but area and fuzz limits of some kind.

Re: Changing colors of an image

Posted: 2009-09-13T18:59:03-07:00
by fmw42
the best color segmentation routine that I have found (which is open source) is at http://www.caip.rutgers.edu/~comanici/segm_images.html

However, I have not tried it on this set of images or any others. So I cannot say other than from the examples they provide and the fact that they are using some of the latest techniques such as "mean shift"

Suggested future enhancement to IM would be to implement it in IM (if practical and does not violate any use limitations)