Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1D non-maximum suppression in Python/scipy

Do you happen to have a 1D non-maximum suppression algorithm written in Python. I need it for making a Canny edge detector in Python using scipy that takes as input a 1D intensity vector.

I've looked around on the web and there is a lot of information describing the behavior of the Canny edge detector and some examples written in Java but they all describe edge detection in 2D.

However scipy does support the other algorithms needed for the Canny edge detection, namely the Gaussian filtering and differentiation for 1D.

Thanks in advance.

like image 822
citn Avatar asked Aug 29 '11 13:08

citn


People also ask

What is non maxima suppression?

Non Maximum Suppression is a computer vision method that selects a single entity out of many overlapping entities (for example bounding boxes in object detection). The criteria is usually discarding entities that are below a given probability bound.

What is non maximum suppression in Opencv?

June 2, 2021 By Leave a Comment. Non Maximum Suppression (NMS) is a technique used in numerous computer vision tasks. It is a class of algorithms to select one entity (e.g., bounding boxes) out of many overlapping entities.

What is non maximum suppression in Canny edge detection?

Non-maximum supression is often used along with edge detection algorithms. The image is scanned along the image gradient direction, and if pixels are not part of the local maxima they are set to zero. This has the effect of supressing all image information that is not part of local maxima.


1 Answers

Do you just mean a maximum filter? If so, have a look at scipy.ndimage.maximum_filter1d

As a quick example:

import numpy as np
import scipy.ndimage as ndimage

input = np.sin(np.linspace(0, 4*np.pi, 20))
input = (input * 10).astype(np.int) # Makes it easier to read
output = ndimage.maximum_filter1d(input, 4)

print 'In: ', input
print 'Out:', output

This yields:

In:  [ 0  6  9  9  4 -1 -7 -9 -8 -3  3  8  9  7  1 -4 -9 -9 -6  0]
Out: [ 6  9  9  9  9  9  4 -1 -3  3  8  9  9  9  9  7  1 -4  0  0]
like image 68
Joe Kington Avatar answered Sep 30 '22 00:09

Joe Kington