Page 1 of 1
segment image according to colors in image
Posted: 2009-09-03T03:58:14-07:00
by sanjeevk
Hi,
All
Can we segment an image in multiple images according to used color in that image.
I want to following things to do with an image.
1. Pick the used color in image using any tool like color piker.
2. supply all picked color to that command which segment the image.
OUTPUT
get segmented images according to color.
e.g.
Suppose we have an image with 3 color
1. red.
2. black.
3.blue.
then after segmentation of this image we need 3 new images. Each contain only one color rest part of this image must be transparent.
Any one can suggest on the same.
Thanks,
Sanjeev kumar
Re: segment image according to colors in image
Posted: 2009-09-03T08:31:09-07:00
by fmw42
convert image -channel rgba -alpha on -fuzz XX% -fill none +opaque red image_red.png
This will extract all colors within XX% of red (you could use XX=0 for an exact match) and make all the rest transparent.
Repeat for each of the other color.
Re: segment image according to colors in image
Posted: 2009-09-03T18:55:13-07:00
by anthony
convert xc:red xc:black xc:blue color_map.png
convert image.png +dither -map color_map.png image_segments.png
As you are using primary colors like red and blue, you could use -separate to get the
red and blue segment masks.
Re: segment image according to colors in image
Posted: 2009-09-03T19:47:40-07:00
by fmw42
convert xc:red xc:black xc:blue color_map.png
convert image.png +dither -map color_map.png image_segments.png
Does not work!
1) convert xc:red xc:black xc:blue color_map.png produces 3 images; color_map-0.png, etc
2) you only reference color_map.png which does not exist.
Not sure if you want to append the red,black,blue images or you want to reference the three color_map images
3) Also -map does not show a file option, do you mean -remap?
Anthony, please clarify.
Re: segment image according to colors in image
Posted: 2009-09-06T22:15:35-07:00
by sanjeevk
Hi fmw42,
I have use
" convert image -channel rgba -alpha on -fuzz XX% -fill none +opaque red image_red.png"
command for this it's working. You have any other idea for the same in which we does not use -fuzz factor.
Or we can get same result without using -fuzzXX%.
Please suggeat on the same.
Re: segment image according to colors in image
Posted: 2009-09-06T22:24:25-07:00
by fmw42
you can leave -fuzz XX% off or set to XX=0 and you get an exact match to make all colors but exactly red to transparent.
convert image -channel rgba -alpha on -fill none +opaque red image_red.png
This will change all colors but exactly red to transparent. If you don't have exactly red, then it will not work.
Re: segment image according to colors in image
Posted: 2009-09-07T03:51:06-07:00
by sanjeevk
Thanks,
I am working on the same.
Re: segment image according to colors in image
Posted: 2015-07-01T00:18:54-07:00
by loskiroama
Very helpful fmw42!
Now, what if I don't know the colors present in the image beforehand?
How can I do the same in this situation?
Re: segment image according to colors in image
Posted: 2015-07-01T08:55:22-07:00
by fmw42
You would have to use the Colormap or Histogram in the meta data to find all the colors and select the color you want to use. This could be scripted, but there is no single IM command to do this. You can find the colormap or histogram via
identify -verbose yourimage
The histogram also can be retrieved by
convert image -format "%c" histogram:info:
It may be necessary to reduce the number of colors in your image first (via -colors)