Changing colors of an image
Changing colors of an image
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Changing colors of an image
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
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Changing colors of an image
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.
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
We have an image name rings.jpg
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.
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 ).
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 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.
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.
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 ).
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 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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Changing colors of an image
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.
convert rings.jpg -quantize RGB +antialias -colors 4 ring4_rgb.gif
or a slightly better job using HSL space
convert rings.jpg -quantize HSL +antialias -colors 4 ring4_hsl.gif
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.
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.
convert rings.jpg -quantize RGB +antialias -colors 4 ring4_rgb.gif
or a slightly better job using HSL space
convert rings.jpg -quantize HSL +antialias -colors 4 ring4_hsl.gif
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
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.
2.After changing color of one selected color.
newDesing1
3. After changing color of second selected color.
newDesing2
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.
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.
2.After changing color of one selected color.
newDesing1
3. After changing color of second selected color.
newDesing2
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Changing colors of an image
Use +dither with -colors 4
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Changing colors of an image
Hi,
When apply this original color of image is loosed.
Please suggest on the same.
Thanks
When apply this original color of image is loosed.
Please suggest on the same.
Thanks
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Changing colors of an image
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.!!
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.
Code: Select all
convert rings.jpg -quantize HSL +dither -colors 4 rings_HSL.png
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Changing colors of an image
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.
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Changing colors of an image
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.
-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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Changing colors of an image
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)
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)