Find Coordinate location for solid color objects

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
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Find Coordinate location for solid color objects

Post by twaintwist »

In a graphic (non-modulated scene) that contains multiple large dots (30 dots) --- dots can be 4 colors (green, pink, black, yellow). I would like to find all the dots of a particular color and replace them with an object ---- perhaps the yellow dots would be converted to a picture of a daisy, the green dots converted to leaves, etc.... so that the converted graphic would not contain dots but would contain multiple daisies, leaves, etc...

So I need a way to find the coordinates of each dot so I can then compose the objects onto those coordinates.

thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Find Coordinate location for solid color objects

Post by fmw42 »

convert your image to txt format and list the results or filter using grep for only one color at a time.

see
http://www.imagemagick.org/Usage/files/#txt



convert rose: txt:- | grep "white"
61,11: (255,255,255) #FFFFFF white
62,15: (255,255,255) #FFFFFF white
62,16: (255,255,255) #FFFFFF white
63,16: (255,255,255) #FFFFFF white
14,37: (255,255,255) #FFFFFF white
12,38: (255,255,255) #FFFFFF white
13,38: (255,255,255) #FFFFFF white
23,39: (255,255,255) #FFFFFF white
12,40: (255,255,255) #FFFFFF white
24,40: (255,255,255) #FFFFFF white
25,40: (255,255,255) #FFFFFF white
11,41: (255,255,255) #FFFFFF white
12,41: (255,255,255) #FFFFFF white
21,41: (255,255,255) #FFFFFF white
26,41: (255,255,255) #FFFFFF white
20,42: (255,255,255) #FFFFFF white
28,42: (255,255,255) #FFFFFF white
29,43: (255,255,255) #FFFFFF white
18,44: (255,255,255) #FFFFFF white
30,44: (255,255,255) #FFFFFF white
31,44: (255,255,255) #FFFFFF white
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Find Coordinate location for solid color objects

Post by anthony »

Alturnative. Separate the various colors into 4 image masks (white on black), and use a color channel convolve method to expand each white dot with the appropriate image.

See Drawing Symbols, Other, Convolve
http://www.imagemagick.org/Usage/draw/#symbol_alts

WARNING: convolve will not handle overlapping images as it 'adds' the colors together!

It was developed from a IM forum Discussion
A Fun Experience with IM
viewtopic.php?t=17259&p=64696#p64696

there is two scripts that can be used to do this "image2kernel" and "convolve_image" from IM Examples scripts area
http://www.imagemagick.org/Usage/scripts/

You may also like to feed the TXT output like what Fred produced above to produce into a shell script loop, to create something like the final example shown in "Pins in a Map".
http://www.imagemagick.org/Usage/layers/#layer_pins

That is the pixel positions is used to place images, whcih are selected based on the color of that pixel.
Most of the background color pixels will of course need to be ignored.

If you like to provide a few small sample images, and the placement map, we can then 'try out' various soltuons
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Find Coordinate location for solid color objects

Post by twaintwist »

Thank you for your responses --- I was delayed in responding because my notifications weren't working.....

I will try out the suggestions --- thanks

Here is a link to the example image [img]https://picasaweb.google.com/lh/photo/1 ... ctlink[img] https://picasaweb.google.com/lh/photo/1 ... directlink you can download by selecting Actions > Download photos

thanks
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Find Coordinate location for solid color objects

Post by twaintwist »

I would like to know the actual coordinates/size of the dots to allow more flexibility in replacing the dots ---- in the future I'd like to replace some of the dots of the same color with the same object and other dots of that same color with different objects (i.e. not all the dots of a particular color will be replaced with the same object) --- a mask and convolve is useful for replacing all dots of same color with the same object -- correct? or I suppose with multiple iterations you could mask 'half the dots' to one object and the other half to another object --- but I'd really like random access to any dot to decide which object belongs on which dot...... I should have expressed this need in the first place....

The conversion to Text works great ---- now to figure out how to turn that into a contiguous dot object coordinate.... --- I believe the dot size will be the same for all images and all colors --- so maybe just finding the center coordinates is all I need and extrapolate for the size.....

thanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Find Coordinate location for solid color objects

Post by anthony »

This is something the morphology can use, A technique known as 'granularity'
http://www.imagemagick.org/Usage/morpho ... ranularity
Unfortunately I have not explored this aspect of morphology much (thus the minimal note about it)

It will (at least at this time) need to be looped in a shell script, to look and see when different objects disappear for different sized kernels (structuring elements). but essentially that is how to do it.

IMv7 will allow this to be done with a shell wrapped single IM command. But it is still in development.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Find Coordinate location for solid color objects

Post by twaintwist »

Anthony ---- thanks -----

I'll write the looping script --- and once identifying which pixels belong to each circle average the coordinates to find the center point.....

thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Find Coordinate location for solid color objects

Post by fmw42 »

As all the dots appear the same size. You can cut out one dot of a particular color with a little background as a square and use compare to get the match score image showing white dots where the matches are best. Then use my script, maxima, to locate the centers of each match. Then repeat for each of the other colors.

see
http://www.imagemagick.org/script/compare.php
http://www.imagemagick.org/Usage/compare/
viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076 (note the need to add -subimage-match in current version of IM for this example)
http://www.fmwconcepts.com/imagemagick/maxima/index.php
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Find Coordinate location for solid color objects

Post by twaintwist »

Fred --- very excellent ---- I'll give it a try
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Find Coordinate location for solid color objects

Post by fmw42 »

My only concern is what compare does with transparent images. I have not tested that. What is your background color. If black or white, you can remove the transparency and just use the non-transparent image. Just need the background to be constant and different from the color dots.

Edit: note your background is mostly black, but has some white stripe at the top and bottom. The one at the top may cause problems, so I would change all white to black. You may need a fuzz value to do that if the white is not uniform.
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Find Coordinate location for solid color objects

Post by twaintwist »

Fred ----

the image background is transparent (a .png file) --- so I can make it any color....
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Find Coordinate location for solid color objects

Post by fmw42 »

twaintwist wrote:Fred ----

the image background is transparent (a .png file) --- so I can make it any color....
Yes, just make it some other color (such as all white or all black) that is different from your dots. Then remove the transparency and try the recommendations above. Let me know if you have trouble.

see -alpha background -alpha off

http://www.imagemagick.org/Usage/maskin ... background
Post Reply