Hello all,
Say I have two points. Along the line between them most pixels are white but at a certain point there's a dark patch. How can I get the position of the peak of this dark patch ? Either in cartesian coordinates or expressed as a % along the segment.
All I can think of is to get many pixel values, convert them to text, then feed that to an external prog with a peak search algorithm.
Any pure IM idea ?!?
Thanks
Get position of min luminosity along a line
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Get position of min luminosity along a line
There are a number of possibilities. If the line is known to be vertical or horizontal, the process can be fairly simple. We crop to the line, auto-level so the darkest becomes black, make non-black pixels transparent, and list the non-transparent pixels by sparse-colors. These will be all the black ones. Just choose the first. A bit more work will find the middle of the darkest.
If all the input pixels were the same colour, not black, then auto-level will make none black, and sparse-colors will list none. Your script should check for this condition.
EDIT: Should be "sparse-color:" not "sparse-colors:". I assumed your input was greyscale. If it isn't, then we also need "-channel RGB" so that each channel auto-levels independently.
My suggestion will find the darkest pixel (or one of the darkest pixels) within a given rectangle. If your line is vertical or horizontal, that defines a thin rectangle. But if your line is at an angle, the problem is harder. One possibility is to rotate the image until the line is horizontal (or vertical), then apply the above method.
If all the input pixels were the same colour, not black, then auto-level will make none black, and sparse-colors will list none. Your script should check for this condition.
Code: Select all
convert in.png -crop WxH+X+Y -auto-level +transparent Black sparse-color:
Code: Select all
convert in.png -crop WxH+X+Y -channel RGB -auto-level +channel +transparent Black sparse-color:
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Get position of min luminosity along a line
What is your background color for the rest of the image.
If you can make the background color white. Then negate the image so that the background is black and your region that you want to find is bright, then you can use a feature of identify that will find the brightest value
identify -precision 5 -define identify:locate=maximum -define identify:limit=3 image.png
This will find up to 3 coordinates that all have the same maximum value. The limit can be changed.
see http://www.imagemagick.org/script/identify.php
But you need to be on IM 6.8.8-6 or higher, since this is a relatively new addition to identify
If you can make the background color white. Then negate the image so that the background is black and your region that you want to find is bright, then you can use a feature of identify that will find the brightest value
identify -precision 5 -define identify:locate=maximum -define identify:limit=3 image.png
This will find up to 3 coordinates that all have the same maximum value. The limit can be changed.
see http://www.imagemagick.org/script/identify.php
But you need to be on IM 6.8.8-6 or higher, since this is a relatively new addition to identify
Re: Get position of min luminosity along a line
Thanks for the ideas. I don't actually have a sample image yet ! I'm waiting to get one (it'll be a webcam image of a dial, and I need to find the position of the needle, a call to DePolar does the 1st part of the trick).