【问题标题】:How to apply the non-maximum suppression for the corner detection如何应用非最大抑制进行角点检测
【发布时间】:2021-03-10 19:23:35
【问题描述】:

最后我有一个工作代码,可以检测图像中矩形的角。但问题是代码在同一个角检测多个点。现在我试图在我的代码中引入非最大抑制,但它不起作用。我以前尝试过一个建议,但它也不起作用。如何正确进行这种非极大值抑制。

import numpy as np
import matplotlib.pyplot as plt  
import matplotlib.image as im   
from scipy import ndimage


# 1. Before doing any operations convert the image into gray scale image

img = im.imread('OD6.jpg')
plt.imshow(img)
plt.show()

# split
R=img[:,:,0]
G=img[:,:,1]
B=img[:,:,2]


M,N=R.shape

gray_img=np.zeros((M,N), dtype=int);

for i in range(M):                     
        for j in range(N):
            gray_img[i, j]=(R[i, j]*0.2989)+(G[i, j]*0.5870)+(B[i, j]*0.114);

plt.imshow(gray_img, cmap='gray')
plt.show()

# 2. Applying sobel filter to find the gradients in x and y direction respectively and remove noise
# using gaussian filter with sigma=1 

imarr = np.asarray(gray_img, dtype=np.float64)
ix = ndimage.sobel(imarr, 0)
iy = ndimage.sobel(imarr, 1)
ix2 = ix * ix
iy2 = iy * iy
ixy = ix * iy
ix2 = ndimage.gaussian_filter(ix2, sigma=1)
iy2 = ndimage.gaussian_filter(iy2, sigma=1)
ixy = ndimage.gaussian_filter(ixy, sigma=1)
c, l = imarr.shape
result = np.zeros((c, l))
r = np.zeros((c, l))

rmax = 0 # initialize the maximum value of harris response
for i in range(c):
        for j in range(l):
            m = np.array([[ix2[i, j], ixy[i, j]], [ixy[i, j], iy2[i, j]]], dtype=np.float64)
            r[i, j] = np.linalg.det(m) - 0.04 * (np.power(np.trace(m), 2))
            if r[i, j] > rmax:
                rmax = r[i, j]

# 3. Applying non maximum supression
for i in range(c - 1):
        for j in range(l - 1):
            if r[i, j] > 0.01 * rmax and r[i, j] > r[i-1, j-1] and r[i, j] > r[i-1, j+1]\
                                     and r[i, j] > r[i+1, j-1] and r[i, j] > r[i+1, j+1]:
                result[i, j] = 1


xy_coords = np.flip(np.column_stack(np.where(result==1)), axis=1)
print (xy_coords)

pc, pr = np.where(result == 1)
plt.plot(pr, pc, "b.")  
plt.imshow(img, 'gray')
plt.show()  

【问题讨论】:

    标签: image image-processing computer-vision filtering


    【解决方案1】:

    角落检测有很多可用的材料。 StackOverflow中也解决了这个问题,请看here

    【讨论】:

    • Goswami 我看过所有这些。事实上,我已经从其中一个答案中提取了一部分代码,但它不起作用。
    猜你喜欢
    • 1970-01-01
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 2011-10-19
    • 2014-07-22
    • 1970-01-01
    相关资源
    最近更新 更多