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

David Baddeley david_baddeley@yahoo.com...
Tue Apr 20 16:43:06 CDT 2010


Hi Dharhas,

it's a bit hard to tell without playing with the data, but I suspect that the best point to get rid of the noise would be in the thresholded image, before you take the difference between the two shifted copies. I suspect that a ndimage.binary_fill_holes, potentially preceeded by a binary_closing might remove some of the clutter you're getting off the lower edge of the band. I'd then try running ndimage.label on the resulting image, which should give you connected regions. You could then throw away all the connected regions smaller than a certain cuttoff using logic such as:

#label connected regions
labels, numObjects = scipy.ndimage.label(thresholded_image) 

#find the number of pixels in each object (alternatively use ndimage.measure)
nPixels, bins = scipy.histogram(labels, scipy.arange(numObjects) + 1)

newMask = scipy.zeros(labels.shape)

#loop over objects
for i in range(numObjects):
    #and add back into mask if larger than the cutoff
    if nPixels[i] > sizeCutoff:
        newMask += (labels == (i+1))

hope this helps,
David


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

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?

thanks,

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

cheers,
David


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

David,

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.

thanks,

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

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


      
_______________________________________________
SciPy-User mailing list
SciPy-User@scipy.org 
http://mail.scipy.org/mailman/listinfo/scipy-user 


      


More information about the SciPy-User mailing list