Python OpenCV-Canny边界检测

问题描述 投票:0回答:1

我正在尝试提取样本的边框(请参见下图)。它与空气之间的梯度似乎很重要,因此我尝试使用OpenCV Canny函数,但结果不令人满意(第二个图)...如何改善结果?

您可以在这里找到图片:https://filesender.renater.fr/?s=download&token=887799f6-f580-4579-8f75-148be4270cb0

enter image description here

import numpy as np
import cv2
from scipy import signal

median_optic_decentre = cv2.imread('median_plot.tiff',0)

edges = cv2.Canny(median_optic_decentre,10,60,apertureSize = 3)
python opencv feature-extraction canny-operator
1个回答
0
投票

获得边缘的另一种方法是使用Laplacian运算符(在OpenCV文档here中进行了描述)。如果您应用Laplacian运算符后接一些morphological operations,特别是morphological opening,则结果看起来会更好一些(如果我正确理解了您的问题):

import cv2
import matplotlib.pyplot as plt


img = cv2.imread('median_plot.tiff')
laplacian = cv2.Laplacian(img,cv2.CV_64F)
S = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))
morph_opened_laplacian = cv2.dilate(cv2.erode(laplacian, S), S)
plt.subplot(1,3,1)
plt.gray()
plt.title("Original")
plt.imshow(img)
plt.subplot(1,3,2)
plt.title("Laplacian")
plt.imshow(laplacian)
plt.subplot(1,3,3)
plt.title("Opened Laplacian")
plt.imshow(morph_opened_laplacian)
plt.show()

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.