Numpy 高特征值始终用于边缘检测
我试图通过解释来理解哈里斯探测器。根据解释,我理解,如果我们计算本征值 然而,当我试图计算本征值时,本征值总是很高。下面是我的主要图像,我从中提取部分来计算特征值 对于没有可见特征的平坦区域,我得到了这个分布(在最右边),这很好,但特征值很大 260935.70201362434796.29798638 对于线性边,我也得到了较高的特征值:16290305.45393251 567780.54606749 对于角点,预计会得到高值,但由于上述情况,我怀疑这些高值是否正确 8958127.80563239 10986758.19436761 这里是我的方法,翻译自matlab代码。这是我直接从numpy的线性代数库中得到的VAL值Numpy 高特征值始终用于边缘检测,numpy,linear-algebra,edge-detection,eigenvalue,corner-detection,Numpy,Linear Algebra,Edge Detection,Eigenvalue,Corner Detection,我试图通过解释来理解哈里斯探测器。根据解释,我理解,如果我们计算本征值 然而,当我试图计算本征值时,本征值总是很高。下面是我的主要图像,我从中提取部分来计算特征值 对于没有可见特征的平坦区域,我得到了这个分布(在最右边),这很好,但特征值很大 260935.70201362434796.29798638 对于线性边,我也得到了较高的特征值:16290305.45393251 567780.54606749 对于角点,预计会得到高值,但由于上述情况,我怀疑这些高值是否正确 8958127.
def plot_derivatives_1(img_rgb, mode=1):
'''
img_rgb = image in rgb color space (3 channeled)
'''
img_1c = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
if mode == 1: # method 1 derivative
Ix = cv2.Sobel(img_1c, cv2.CV_64F, 1, 0, ksize=3)
Iy = cv2.Sobel(img_1c, cv2.CV_64F, 0, 1, ksize=3)
else:
# another method of derivatives
dx = np.array([
[-1, 0, 1],
[-1, 0, 1],
[-1, 0, 1]
]);
dy = np.transpose(dx)
Ix = signal.convolve2d(img_1c, dx, mode='valid')
Iy = signal.convolve2d(img_1c, dy, mode='valid')
Ix, Iy = Ix.astype(np.float64), Iy.astype(np.float64) # else gaussian blur later is failing
# yet to solve why we need A and eigen outputs
A = np.array([
[ np.sum(Ix*Ix), np.sum(Ix*Iy) ],
[ np.sum(Ix*Iy), np.sum(Iy*Iy) ]
])
vals, V = linalg.eig(A)
lamb = vals/np.max(vals)
print('lambda values:{}'.format(vals))
fig, ax = plt.subplots(1,4, figsize=(20,5))
ax[0].imshow(img_rgb);ax[0].set_title('Input Image')
ax[1].imshow(Ix, cmap='gray');ax[1].set_title('$I_x = \dfrac{\partial I}{\partial x}$')
ax[2].imshow(Iy, cmap='gray');ax[2].set_title('$I_y = \dfrac{\partial I}{\partial y}$')
ax[3].scatter(Ix, Iy);ax[3].set_xlim([-200,200]);ax[3].set_ylim([-200,200]);
ax[3].set_aspect('equal');ax[3].set_title('Derivatives Distribution');
ax[3].set_xlabel('Ix');ax[3].set_ylabel('Iy')
ax[3].axvline(x=0, color = 'r');ax[3].axhline(y=0, color ='r')
plt.tight_layout();plt.show()
return Ix, Iy
一个案例的示例调用(此处显示的是拐角处)
我使用jupyter笔记本,代码是在我试图理解这个概念时生成的
在所有情况下,我总是获得较高的本征值,这有什么错
可以找到用于上述情况的样本图像您的梯度似乎已重新缩放。它们应该是有符号的值,以原点为中心。你的渐变看起来被重新缩放了。它们应该是以原点为中心的有符号值。
img = cv2.imread(SRC_FOLDER + 'checkersandbooksmall_sample_6.jpg')
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
Ix, Iy = plot_derivatives_1(img_rgb, mode=1)