Python implementation of the laplacian of gaussian edge detection

I am looking for the equivalent implementation of the laplacian of gaussian edge detection.

In matlab we use the following function

   [BW,threshold] = edge(I,'log',...)

In python there exist a function for calculating the laplacian of gaussian. It is not giving the edges back definitely.


Any pointer to online implementation or the code



What matlab edge() do should be

  1. Compute LoG
  2. Compute zero crossings on LoG
  3. Compute a threshold for local LoG difference
  4. Edge pixels = zero crossing && local difference > threshold

The LoG filter of scipy only does step 1 above. I implemented the following snippet to mimic step 2~4 above:

import scipy as sp
import numpy as np
import scipy.ndimage as nd
import matplotlib.pyplot as plt

lena = sp.misc.lena()
LoG = nd.gaussian_laplace(lena, 2)
thres = np.absolute(LoG).mean() * 0.75
output = sp.zeros(LoG.shape)
w = output.shape[1]
h = output.shape[0]

for y in range(1, h - 1):
    for x in range(1, w - 1):
        patch = LoG[y-1:y+2, x-1:x+2]
        p = LoG[y, x]
        maxP = patch.max()
        minP = patch.min()
        if (p > 0):
            zeroCross = True if minP < 0 else False
            zeroCross = True if maxP > 0 else False
        if ((maxP - minP) > thres) and zeroCross:
            output[y, x] = 1


This of course is slow and probably not idiomatic as I am also new to Python, but should show the idea. Any suggestion on how to improve it is also welcomed.

Need Your Help

ASP.NET Custom resources fallback localization globalization cultureinfo culture

I have an application which define few cultures and I'd like it to fallback the way I want it. Here I have:

Reliable Way to Add Sound to UIButton

iphone ios audio avaudioplayer system-sounds

I am trying to add a tap-sound to a UIButton to play when it is pushed. So far, I've tried two methods, but none worked out quite as well as I hoped.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.