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

Dharhas Pothina Dharhas.Pothina@twdb.state.tx...
Tue Apr 20 12:42:40 CDT 2010

David & Others,

Using the method similarto 'B' outlined by David below, I managed to get to an array of x,y coordinates that define the edge. I've attached the image to this email. As you can see,  I still have noise that needs to be removed. Any suggestions on how to do this?


- dharhas

>>> David Baddeley <david_baddeley@yahoo.com.au> 4/19/2010 5:51 AM >>>
Hi Dharhas,

I think the best approach would probably be trial and error - I'd start with a sigma of around 2-3 (all the other parameters can be left as their defaults ) and either decrease of increase it depending on whether you're blurring too much, or not enough. You might also want to take a look at ndimage.median_filter (again I'd experiment, this time with the size parameter), as there is a chance that this will let you smooth more without loosing edge definition.


----- Original Message ----
From: Dharhas Pothina <Dharhas.Pothina@twdb.state.tx.us>
To: David Baddeley <david_baddeley@yahoo.com.au>
Sent: Sat, 17 April, 2010 5:32:45 AM
Subject: Re: [SciPy-User] line/edge detection and output of coordinates.


Can you give any guidance (or point me to documentation) on how to specify parameters for scipy.ndimage.gaussian_filter to remove the noise in my image? I don't have enough background in this area for the docstring to be useful.


- dharhas

>>> David Baddeley <david_baddeley@yahoo.com.au> 4/15/2010 3:21 PM >>>
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.


----- 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.


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.


- dharhas

SciPy-User mailing list

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test1_small.jpg
Type: image/jpeg
Size: 12304 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20100420/e8d4af9b/attachment.jpg 

More information about the SciPy-User mailing list