使用OpenCV Python进行图像的边缘检测和直方图匹配。
我需要用OpenCV的Python库来检测医学图像的边缘。请问哪种边缘检测器最适合我的工作?我试过使用Canny边缘检测器。我想找到医学图像的边缘,并且想要比较两幅图像之间的直方图匹配。谢谢大家的帮助!:)
1 个回答
1
你能把你正在处理的图片发上来吗?那样会更好。
另外,你可以试试这段代码。它让你可以调整Canny滤波器的参数,Threshold 1和Threshold 2,这样你就能大致了解如何将Canny滤波器应用到图片上。
import cv2
import numpy as np
def nothing(x):
pass
#image window
cv2.namedWindow('image')
#loading images
img = cv2.imread('leo-messi-pic.jpg',0) # load your image with proper path
# create trackbars for color change
cv2.createTrackbar('th1','image',0,255,nothing)
cv2.createTrackbar('th2','image',0,255,nothing)
while(1):
# get current positions of four trackbars
th1 = cv2.getTrackbarPos('th1','image')
th2 = cv2.getTrackbarPos('th2','image')
#apply canny
edges = cv2.Canny(img,th1,th2)
#show the image
cv2.imshow('image',edges)
#press ESC to stop
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
至于直方图比较,你可以在这里找到所有与直方图相关的cv2 API。
http://docs.opencv.org/modules/imgproc/doc/histograms.html
希望这对你有帮助。