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
segment image according to colors in image
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: segment image according to colors in image
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.
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.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: segment image according to colors in image
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.
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.
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: segment image according to colors in image
Does not work!convert xc:red xc:black xc:blue color_map.png
convert image.png +dither -map color_map.png image_segments.png
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.
-
- Posts: 26
- Joined: 2009-08-26T02:17:36-07:00
- Authentication code: 8675309
- Location: India
- Contact:
Re: segment image according to colors in image
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: segment image according to colors in image
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.
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.
-
- Posts: 26
- Joined: 2009-08-26T02:17:36-07:00
- Authentication code: 8675309
- Location: India
- Contact:
Re: segment image according to colors in image
Thanks,
I am working on the same.
I am working on the same.
-
- Posts: 9
- Joined: 2015-07-01T00:07:41-07:00
- Authentication code: 6789
Re: segment image according to colors in image
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?
Now, what if I don't know the colors present in the image beforehand?
How can I do the same in this situation?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: segment image according to colors in image
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)
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)