Fun with sobel - Neon Effect - Thick Edge Detection

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fun with sobel - Neon Effect - Thick Edge Detection

Post by fmw42 »

# ORIENTED HOUGH TRANSFORM
def orientedHoughTransform(edges,sobelX,sobelY,accumulator):
maxtheta = pi
maxrho = hypot(edges.width, edges.height)
maxacc = -1000000
for x in range(0,edges.width):
for y in range(0,edges.height):
#print x,y, edges.width,edges.height
if edges[y,x]>0:
theta = atan2(sobelY[y,x],sobelX[y,x])
rho = x*cos(theta) + y*sin(theta)
t=int(round ((theta/maxtheta/2 +0.5) * (accumulator.width-1) ))
r=int(round ((rho /maxrho /2 +0.5) * (accumulator.height-1)))
acc=accumulator[r,t]
acc+=1
accumulator[r,t]=acc
if acc>maxacc: maxacc=acc
#print theta,sobelY[y,x],sobelX[y,x]
cvConvertScale(accumulator,accumulator,100000/maxacc)
Just curious about your python code for creating the hough transform. I don't read code that well, but it looks like you need openCV to create the accumulator? or am I mistaken? can that be done simply in a python or shell script without openCV?
HugoRune
Posts: 90
Joined: 2009-03-11T02:45:12-07:00
Authentication code: 8675309

Re: Fun with sobel - Neon Effect - Thick Edge Detection

Post by HugoRune »

fmw42 wrote: Just curious about your python code for creating the hough transform. I don't read code that well, but it looks like you need openCV to create the accumulator? or am I mistaken? can that be done simply in a python or shell script without openCV?
For the accumulator itself I do not need openCv per se. I simply need a 2D matrix of integers to store the accumulator values.
This could be done in pure python, but would probably be slower.
I am considering switching to the numPy library for this.

However OpenCV has a class for 2D matrices, and also methods for displaying them as images, and loading and saving them in common image formats, so this saved a lot of time
and I am using openCv for several other things like fast sobel filter and canny edge detection anyway.

(the last line "cvConvertScale(accumulator,accumulator,100000/maxacc)" is not part of the hough transform, just a quick hack. I multiplied each value with 1000000 to enhance the contrast for displaying.)


Currently I am using openCV for the following:

- reading the input image file into a 2d matrix
this could probably be done with PIL, the Python image library
possibly with the Imagemagick python interface too.

-displaying the matrixes as images, saving them as images

- canny edge detection
edge detection could be done with imagemagick, but the canny filter is really superiour for this problem.

-sobel filter
much faster than with imagemagick, but not essential

- mean, morphological grayscale open, dilate.
I am experimenting with these for noise filtering and non-maximum supression
much faster than the equivalent commands in imagemagick, but not essential

By the way, my current method for finding the local maxima in hough space:
dilate the hough space image ~3 times, then compare the dilated image with the original and set all pixels with differing values to zero. The remaining pixels are local maxima
Works very well.

edit:
I stumbled upon this implementation of a classic hough transform, which uses numpy instead of opencv, and apparently uses some numpy and python tricks to speed it up
http://mail.scipy.org/pipermail/scipy-u ... achment.py
Post Reply