Hi guys,
How can i do a 'color tracking' (means detect/locate a specific color in an image) using ImageMagick. Solutions on command-line or Magick++ or MagickWand for C can be very helpful for me.
Thanking you in advance,
I am a newbie
color tracking
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: color tracking
convert your color to transparent, then send the output to txt: and run grep or sed to filter only those lines that have your transparent color. the first part of each line will be the coordinates
convert logo: -depth 8 logo.png
convert logo: -transparent "rgb(255,0,0)" txt:- | grep "rgba(255,0,0,0)"
244,38: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
237,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
238,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
239,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
240,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
...
convert logo: -depth 8 logo.png
convert logo: -transparent "rgb(255,0,0)" txt:- | grep "rgba(255,0,0,0)"
244,38: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
237,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
238,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
239,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
240,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
...
Last edited by fmw42 on 2011-02-23T19:52:16-07:00, edited 1 time in total.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: color tracking
See IM examples, Color basics, Fuzz Distance
http://www.imagemagick.org/Usage/color_ ... z_distance
http://www.imagemagick.org/Usage/color_ ... z_distance
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: color tracking
Good evening,
Thanks fmw42 for your answer. It seems to me very interesting
Thanks anthony that's what i've been looking for, by introducing this fuzzy tolerance i'll detect perfectly my colored object.
I'll test this on command line tool first then i'll implement this in a C/C++ or java code.
Thanks fmw42 for your answer. It seems to me very interesting
Thanks anthony that's what i've been looking for, by introducing this fuzzy tolerance i'll detect perfectly my colored object.
I'll test this on command line tool first then i'll implement this in a C/C++ or java code.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: color tracking
Darkout wrote:Good evening,
Thanks fmw42 for your answer. It seems to me very interesting
Thanks anthony that's what i've been looking for, by introducing this fuzzy tolerance i'll detect perfectly my colored object.
I'll test this on command line tool first then i'll implement this in a C/C++ or java code.
I would have included the -fuzz in my suggestion, but you said you wanted a "specific color"
Re: color tracking
Yes that's right! i didn't specify that i'm working on true colors
thank you!
by the way it works fine on command line i should make an intelligent code in a way to adjust the fuzz value depending on the the image luminance and contrast.
thank you!
by the way it works fine on command line i should make an intelligent code in a way to adjust the fuzz value depending on the the image luminance and contrast.
Re: color tracking
Hello,fmw42 wrote:convert your color to transparent, then send the output to txt: and run grep or sed to filter only those lines that have your transparent color. the first part of each line will be the coordinates
convert logo: -depth 8 logo.png
convert logo: -transparent "rgb(255,0,0)" txt:- | grep "rgba(255,0,0,0)"
244,38: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
237,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
238,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
239,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
240,39: (255, 0, 0, 0) #FF000000 rgba(255,0,0,0)
...
How can i implement this on MagickWand or Magick++ (C/C++) or JMagick
Is there a tutorial to use IM convert programme in those programming tools?
thanks
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: color tracking
In MagickWand or Magic++, you are better off finding one of the 'loop though pixel example demo programs, and then looking at the pixels directly yourself.
Command line shell does not have that luxury (though it can do it with a -fx expression) and uses text processing tools on identify output. It is slower but it gets the job done.
Command line shell does not have that luxury (though it can do it with a -fx expression) and uses text processing tools on identify output. It is slower but it gets the job done.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: color tracking
can you explain a little bit more your contribution!anthony wrote:In MagickWand or Magic++, you are better off finding one of the 'loop though pixel example demo programs, and then looking at the pixels directly yourself.
Command line shell does not have that luxury (though it can do it with a -fx expression) and uses text processing tools on identify output. It is slower but it gets the job done.
did you meant that i should code in C instead of using MagickWand
and please tell me what MagickWand can offer to users?
Thanks anthony
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: color tracking
there should be some same code for this.
I myself don't program in magick wand, but looping through the pixels in an image is a standard thing.
Check the documentation for MagickWand.
I myself don't program in magick wand, but looping through the pixels in an image is a standard thing.
Check the documentation for MagickWand.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/