matlab edge()应该做什么
- 计算LOG
- 计算LoG上的零交叉
- 计算本地LoG差异的阈值
- 边缘像素=零交叉&&局部差异>阈值
scipy的LoG过滤器仅执行上述步骤1。我实现了以下代码段来模仿上面的步骤2〜4:
import scipy as spimport numpy as npimport scipy.ndimage as ndimport matplotlib.pyplot as pltfrom skimage import data# lena = sp.misc.lena() this function was deprecated in version 0.17img = data.camera() # use a standard image from skimage insteadLoG = nd.gaussian_laplace(img , 2)thres = np.absolute(LoG).mean() * 0.75output = 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 else: zeroCross = True if maxP > 0 else False if ((maxP - minP) > thres) and zeroCross: output[y, x] = 1plt.imshow(output)plt.show()
这当然很慢,并且可能不是惯用的,因为我也是Python的新手,但应该可以证明这个想法。也欢迎任何有关如何改进它的建议。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)