extracting a colored pixel from an image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

extracting a colored pixel from an image

Post by sin »

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.
User avatar
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

Post by fmw42 »

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)
Last edited by fmw42 on 2011-07-16T11:39:14-07:00, edited 1 time in total.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: extracting a colored pixel from an image

Post by sin »

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).
User avatar
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

Post by fmw42 »

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.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: extracting a colored pixel from an image

Post by sin »

how can I get a black pixel using FUZZ from a normal image which has only white and RGB pixels??
User avatar
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

Post by fmw42 »

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/
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: extracting a colored pixel from an image

Post by sin »

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..!!!
User avatar
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

Post by fmw42 »

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..!!!
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.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: extracting a colored pixel from an image

Post by sin »

how can i convert the existing black pixels into transparent or white??
User avatar
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

Post by fmw42 »

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.
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: extracting a colored pixel from an image

Post by sin »

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
User avatar
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

Post by fmw42 »

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.
Post Reply