extracting a colored pixel from an image
extracting a colored pixel from an image
can you please tell me, how a particular color pixels from a text file of an image?
that is,
when a text file is generated from an image, i want a command to extract the pixels of a particular in a text file.
that is,
when a text file is generated from an image, i want a command to extract the pixels of a particular in a text file.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: extracting a colored pixel from an image
are you on unix/mac or windows? what version of IM?
If on unix, use this with hex color values:
convert rose: txt: | grep "#38302D"
6,0: ( 56, 48, 45) #38302D rgb(56,48,45)
8,0: ( 56, 48, 45) #38302D rgb(56,48,45)
9,0: ( 56, 48, 45) #38302D rgb(56,48,45)
6,6: ( 56, 48, 45) #38302D rgb(56,48,45)
If on unix, use this with hex color values:
convert rose: txt: | grep "#38302D"
6,0: ( 56, 48, 45) #38302D rgb(56,48,45)
8,0: ( 56, 48, 45) #38302D rgb(56,48,45)
9,0: ( 56, 48, 45) #38302D rgb(56,48,45)
6,6: ( 56, 48, 45) #38302D rgb(56,48,45)
Last edited by fmw42 on 2011-07-16T11:39:14-07:00, edited 1 time in total.
Re: extracting a colored pixel from an image
fmw42 wrote:are you on unix/mac or windows? what version of IM?
If on unix, use this with hex color values:
convert rose: txt: | grep "#38302D"
6,0: ( 56, 48, 45) #38302D rgb(56,48,45)
8,0: ( 56, 48, 45) #38302D rgb(56,48,45)
9,0: ( 56, 48, 45) #38302D rgb(56,48,45)
6,6: ( 56, 48, 45) #38302D rgb(56,48,45)
I am using Windows.i want pixels of only one particular color (like pixels having only black color).
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: extracting a colored pixel from an image
What I provided does filter out only pixels of the hex color specified! However, it is for unix.
Perhaps windows has the same grep and pipe functions. So perhaps you should give it a try and see what happens. You lose nothing.
I am not a windows user. So hopefully one of the windows users can give you the equivalent if it does not work. Or look in the file http://www.imagemagick.org/Usage/windows/ and see if that helps.
If the color you want is in the list of colornames used by IM, then you can use that. However, you cannot specify all colors by their rgb values, since in the txt output format it substitutes names for rgb values when a name is available.
Perhaps windows has the same grep and pipe functions. So perhaps you should give it a try and see what happens. You lose nothing.
I am not a windows user. So hopefully one of the windows users can give you the equivalent if it does not work. Or look in the file http://www.imagemagick.org/Usage/windows/ and see if that helps.
If the color you want is in the list of colornames used by IM, then you can use that. However, you cannot specify all colors by their rgb values, since in the txt output format it substitutes names for rgb values when a name is available.
Re: extracting a colored pixel from an image
how can I get a black pixel using FUZZ from a normal image which has only white and RGB pixels??
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: extracting a colored pixel from an image
black is in hex #000000 -- so use that in my example above. Fuzz is not needed. If you want to do something else that requires fuzz, please clarify further.
This will convert all pixels that within 20% of black and leave the rest alone. Then the grep on #000000 will locate each black pixel.
convert rose: -black-threshold 20% txt: | grep "#000000"
Do you want to process the image, so that you see only near black pixels and what do you want with the rest?
This will show all black within XX% and the rest white:
convert image -threshold XX% resultimage
This will show all black within XX% and the rest will stay the same:
convert image -black-threshold XX% resultimage
This will make everything transparent except values within XX% of black
convert image -fuzz XX% +transparent black
Are any of these what you want to do?
This is unix syntax. For windows, I believe you need to double the % to %%. see http://www.imagemagick.org/Usage/windows/
This will convert all pixels that within 20% of black and leave the rest alone. Then the grep on #000000 will locate each black pixel.
convert rose: -black-threshold 20% txt: | grep "#000000"
Do you want to process the image, so that you see only near black pixels and what do you want with the rest?
This will show all black within XX% and the rest white:
convert image -threshold XX% resultimage
This will show all black within XX% and the rest will stay the same:
convert image -black-threshold XX% resultimage
This will make everything transparent except values within XX% of black
convert image -fuzz XX% +transparent black
Are any of these what you want to do?
This is unix syntax. For windows, I believe you need to double the % to %%. see http://www.imagemagick.org/Usage/windows/
Re: extracting a colored pixel from an image
fmw42 wrote:black is in hex #000000 -- so use that in my example above. Fuzz is not needed. If you want to do something else that requires fuzz, please clarify further.
This will convert all pixels that within 20% of black and leave the rest alone. Then the grep on #000000 will locate each black pixel.
convert rose: -black-threshold 20% txt: | grep "#000000"
Do you want to process the image, so that you see only near black pixels and what do you want with the rest?
This will show all black within XX% and the rest white:
convert image -threshold XX% resultimage
This will show all black within XX% and the rest will stay the same:
convert image -black-threshold XX% resultimage
This will make everything transparent except values within XX% of black
convert image -fuzz XX% +transparent black
Are any of these what you want to do?
This is unix syntax. For windows, I believe you need to double the % to %%. see http://www.imagemagick.org/Usage/windows/
actually that image doesn't have any black pixels. so i have to extract pixels that are near to black pixels. To do this I think with fuzz it is possible..!!!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: extracting a colored pixel from an image
Yes, that is what I demonstrated with the rose: image. It has no black, but by using -fuzz 20% it finds any pixel whose color is within 20% of black.actually that image doesn't have any black pixels. so i have to extract pixels that are near to black pixels. To do this I think with fuzz it is possible..!!!
Re: extracting a colored pixel from an image
how can i convert the existing black pixels into transparent or white??
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: extracting a colored pixel from an image
convert image -fuzz XX% -transparent black resultimage
or
convert image -fuzz XX% -fill white -opaque black resultimage
The above only works if your image is fully opaque. If you have other transparency (alpha channel), then it would need to be modified.
or
convert image -fuzz XX% -fill white -opaque black resultimage
The above only works if your image is fully opaque. If you have other transparency (alpha channel), then it would need to be modified.
Re: extracting a colored pixel from an image
fmw42 wrote:are you on unix/mac or windows? what version of IM?
If on unix, use this with hex color values:
convert rose: txt: | grep "#38302D"
6,0: ( 56, 48, 45) #38302D rgb(56,48,45)
8,0: ( 56, 48, 45) #38302D rgb(56,48,45)
9,0: ( 56, 48, 45) #38302D rgb(56,48,45)
6,6: ( 56, 48, 45) #38302D rgb(56,48,45)
Can you tell me how to write the same in Windows also.
grep is not working in windows
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: extracting a colored pixel from an image
sorry, I am not a Windows user, so I don't know what to tell you. see http://www.imagemagick.org/Usage/windows/
or perhaps some Windows user can help you further.
or perhaps some Windows user can help you further.