经过图像处理、fft、过滤器和阈值处理后,我获得了以下图像:
所以,我想知道如何提取这些中心。 OpenCV 是否存在任何功能? (例如用于检测圆圈的 HoughCircles?)或者我是否需要使用聚类方法?
也许了解我使用的代码对您有用:
import cv2
import numpy as np
import scipy.ndimage as ndimage
from scipy.ndimage import maximum_filter
img = cv2.imread("pic.tif",0)
s = np.fft.fftshift(np.fft.fft2(img))
intensity = 20 * np.log(np.abs(s))
maxs = maximum_filter(intensity, 125)
maxs[maxs < intensity] = intensity.max()
ret, thresh = cv2.threshold(maxs.astype('uint8'),0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
imshow(thresh)
PS:所以我还有一个问题,它可能对你们中的一些人有用。 maximum_filter
函数给了我“3 个正方形”(然后我将通过使用阈值来更好地可视化它们),那么有没有办法使用 maximum_filter
函数并获得“3圈”?然后我们可以使用HoughCircles
来获取3个中心圆。
最佳答案
您可能需要使用 Image Moments .
作为预处理步骤,threshold创建正方形掩码的源,然后传递给 findcontours .
关于python - 从图片中找到正方形中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24337892/