color tracking

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
Darkout
Posts: 5
Joined: 2011-02-23T08:27:42-07:00
Authentication code: 8675308

color tracking

Post by Darkout »

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 :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color tracking

Post by fmw42 »

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)
...
Last edited by fmw42 on 2011-02-23T19:52:16-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: color tracking

Post by anthony »

See IM examples, Color basics, Fuzz Distance
http://www.imagemagick.org/Usage/color_ ... z_distance
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Darkout
Posts: 5
Joined: 2011-02-23T08:27:42-07:00
Authentication code: 8675308

Re: color tracking

Post by Darkout »

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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: color tracking

Post by fmw42 »

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"
Darkout
Posts: 5
Joined: 2011-02-23T08:27:42-07:00
Authentication code: 8675308

Re: color tracking

Post by Darkout »

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 :D i should make an intelligent code in a way to adjust the fuzz value depending on the the image luminance and contrast.
Darkout
Posts: 5
Joined: 2011-02-23T08:27:42-07:00
Authentication code: 8675308

Re: color tracking

Post by Darkout »

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)
...
Hello,
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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: color tracking

Post by anthony »

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Darkout
Posts: 5
Joined: 2011-02-23T08:27:42-07:00
Authentication code: 8675308

Re: color tracking

Post by Darkout »

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.
can you explain a little bit more your contribution!
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 :)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: color tracking

Post by anthony »

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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply