[SciPy-User] line/edge detection and output of coordinates.

David Baddeley david_baddeley@yahoo.com...
Thu Apr 15 15:21:24 CDT 2010


Hi Dharhas,

most traditional edge detection algorithms use some kind of gradient based filter - your image has two features which suggest that this approach might not be ideal. First it is noisy (which means that any gradient image will be even noisier) and second, you actually have relatively good contrast as to what is part of the object and what is not, and might not need gradient based edge detection per se. I'd take the following approach:

- low pass filter with scipy.ndimage.gaussian_filter to reduce the noise
- threshold the image to get a binary mask of your band (eg mask = image > threshold)
- potentially use a morphological operation such as binary closing (scipy.ndimage.binary_closing) or hole filling to tidy up the mask

from this mask you have a number of options to get the edges:
A - do a binary dilation and then subtract the original mask - this should give you a mask with all the edge pixels (both top and bottom). Applying ndimage.label to this mask might allow you to extract masks of both edges separately.

B - as you want to find the top and bottom edges (rather than edges which can fold back on themselves), you could take the difference between the mask and a copy of the mask which has been shifted vertically by one pixel (eg mask[:-1,:] - mask[1:,:]). This should give you an image in which the top edge pixels have a value of 1, the bottom edge has a value of -1, and all other pixels are zero. 

once you have an image in which the pixels of each edge have different values, you can find the coordinates using numpy.where.

cheers,
David



----- Original Message ----
From: Dharhas Pothina <Dharhas.Pothina@twdb.state.tx.us>
To: SciPy@yahoo.com
Sent: Fri, 16 April, 2010 6:54:58 AM
Subject: [SciPy-User] line/edge detection and output of coordinates.

Hi,

I'm trying to do some line/edge detection in python. I've done some googling and found some mailing list archives that talked about ways to do edge detection but they seem to mainly return an image with the edges highlighted. What I need is x,y coordinates of the pixels that make up the lines. I've attached an image that shows a dark band on a light background. The final output I need would be line definitions in terms of a series of x,y coordinates for the upper light to dark interface and the lower dark to light interface of the band.

Any pointers on packages to use or ways to do this are highly appreciated.

Thanks,

- dharhas


      


More information about the SciPy-User mailing list