How I could detect all coordinates of points like in this 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
diegomage
Posts: 205
Joined: 2017-03-08T10:12:28-07:00
Authentication code: 1151

How I could detect all coordinates of points like in this image

Post by diegomage »

this is the image

Image

and this is the point
Image



Please help me with this problem
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How I could detect all coordinates of points like in this image

Post by snibgo »

What version of IM? On what platform?

The solution is to use "compare" with "-subimage-search".
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How I could detect all coordinates of points like in this image

Post by fmw42 »

You can write to txt: format and exclude the black ones, assuming your image is not jpeg and has solid black for the background.

Code: Select all

convert image txt:- | grep -v "black"
This works on Unix and lists the coordinates and colors of all non-black pixels. I do not know if Windows has pipes or grep. One of the windows users can corroborate.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How I could detect all coordinates of points like in this image

Post by snibgo »

But the required "point" is an image, a subimage.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How I could detect all coordinates of points like in this image

Post by fmw42 »

snibgo wrote: 2017-06-01T17:10:33-07:00 But the required "point" is an image, a subimage.
Sorry, I misunderstood and did not notice the smaller image. Snibgo's solution is then the correct one. You can then find all the brightest points in the second output image from the subimage-search compare. If on Unix-like systems, see my script maxima.
diegomage
Posts: 205
Joined: 2017-03-08T10:12:28-07:00
Authentication code: 1151

Re: How I could detect all coordinates of points like in this image

Post by diegomage »

fmw42 wrote: 2017-06-01T18:20:11-07:00
snibgo wrote: 2017-06-01T17:10:33-07:00 But the required "point" is an image, a subimage.
Sorry, I misunderstood and did not notice the smaller image. Snibgo's solution is then the correct one. You can then find all the brightest points in the second output image from the subimage-search compare. If on Unix-like systems, see my script maxima.



very thankyou; could you send me the link of your script ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How I could detect all coordinates of points like in this image

Post by snibgo »

Again I ask: What version of IM? On what platform?
snibgo's IM pages: im.snibgo.com
diegomage
Posts: 205
Joined: 2017-03-08T10:12:28-07:00
Authentication code: 1151

Re: How I could detect all coordinates of points like in this image

Post by diegomage »

snibgo wrote: 2017-06-04T11:37:28-07:00 Again I ask: What version of IM? On what platform?

I use 6.9.8.3
Version: ImageMagick 6.9.8-3 Q16 x86_64
I use linux ubuntu
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How I could detect all coordinates of points like in this image

Post by snibgo »

Code: Select all

compare -metric RMSE -subimage-search aO4kz.png oe5pC.png x.png

convert x-1.png -define identify:locate=maximum -identify NULL:
The output is:

Code: Select all

  Channel maximum locations:
  Gray: 65535 (1) 52,3 52,50 51,81
This gives the three locations of the top-left corner of the location where the subimage is found.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How I could detect all coordinates of points like in this image

Post by fmw42 »

Adding slightly to snibgo reply, you can tell IM how many maxima you want to return using -define identify:limit=X. The default is 3 as he showed. See http://www.imagemagick.org/script/identify.php. However, if the peaks are broad, you can get many values around a single peak. So the better way is to find each, one at a time, then write a small round black area over that maxima. Then search for the next one. I have a bash unix script, maxima, that does that. See my link below.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How I could detect all coordinates of points like in this image

Post by snibgo »

The default is to find them all, eg:

Code: Select all

f:\web\im>%IM%convert -size 4x4 xc:White -define identify:locate=maximum -identify null:
  Channel maximum locations:
  Gray: 65535 (1) 0,0 1,0 2,0 3,0 0,1 1,1 2,1 3,1 0,2 1,2 2,2 3,2 0,3 1,3 2,3 3,3
In the OP's case, there were only three white pixels.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How I could detect all coordinates of points like in this image

Post by fmw42 »

snibgo wrote: 2017-06-04T12:58:57-07:00 The default is to find them all, eg:
I stand corrected. Thanks.
diegomage
Posts: 205
Joined: 2017-03-08T10:12:28-07:00
Authentication code: 1151

Re: How I could detect all coordinates of points like in this image

Post by diegomage »

snibgo wrote: 2017-06-04T12:16:23-07:00

Code: Select all

compare -metric RMSE -subimage-search aO4kz.png oe5pC.png x.png

convert x-1.png -define identify:locate=maximum -identify NULL:
The output is:

Code: Select all

  Channel maximum locations:
  Gray: 65535 (1) 52,3 52,50 51,81
This gives the three locations of the top-left corner of the location where the subimage is found.
very thankyou
Post Reply