醫學影象標籤和影象的重疊操作
阿新 • • 發佈:2021-01-19
技術標籤:影象處理opencv計算機視覺人臉識別深度學習影象識別
醫學影象標籤和影象的重疊操作
import cv2
#需要自己先建立好資料夾
def Edge_Extract(label,image):
img = cv2.imread(label)
image = cv2.imread(image)
cv2.imshow('imgshow', img) # 顯示返回值image,其實與輸入引數的thresh原圖沒啥區別
cv2.waitKey()
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(img, 127, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
cnt = contours[0]
res = cv2.drawContours(image, cnt, -1, (0, 0, 255), 2, cv2.LINE_AA)
cv2.imshow('image+mask', res)
cv2.waitKey()
cv2.imwrite('E:/Recursive/output4/seg_fixed_extract.png' , res)
return 0
if __name__ == '__main__':
root1 = 'E:/Recursive/output4/seg_fixed.png' # 修改為你對應的檔案路徑
root2 = 'E:/Recursive/output4/image_fixed.png'
Edge_Extract(root1, root2)