我正在为计算机视觉 (CV) 课程生成材料,我想通过传统的 CV 技术计算这个突出显示部分的面积:
因此,我应用 Canny 来检测边缘,并使用 Circle Hough 变换试图找到相应的区域。这些是我的结果:
我尝试使用分水岭,将标记作为我找到的圆圈的中心,但没有成功。有谁知道我该如何继续或有其他想法?
这是代码:
import numpy as np
import matplotlib.pyplot as plt
import cv2 as cv
from skimage.feature import canny
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.draw import circle_perimeter
from skimage.segmentation import watershed
import urllib.request
urllib.request.urlretrieve("https://github.com/LAVI-USP/SEL0339-SEL5886/raw/master/imagens/pratica_07/head_CT.tif", "head_CT.tif")
# Read image
img = cv.imread("head_CT.tif",-1)
# Edge detector
edges = canny(img, sigma=2.0, low_threshold=19, high_threshold=57)
# Hough_circle
hough_radii = np.arange(29, 32, 1)
hough_res = hough_circle(edges, hough_radii)
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii,total_num_peaks=4, min_xdistance=200,min_ydistance=200, threshold=0.25)
# Remove false-posite circle
sortX = np.argsort(cx)
cx = cx[sortX[:-1]]
cy = cy[sortX[:-1]]
radii = radii[sortX[:-1]]
# Draw red circles
img_rgb = np.tile(np.expand_dims(img,axis=-1),(1,1,3),)
for center_y, center_x, radius in zip(cy, cx, radii):
circy, circx = circle_perimeter(center_y, center_x, radius,shape=img_rgb.shape)
img_rgb[circy, circx] = (220, 20, 20)
# Plot images
imgs = [img_rgb, edges]
r,c = 1,2
fig, axs = plt.subplots(r, c, figsize=(15,15))
for i in range(r):
for j in range(c):
axs[j].imshow(imgs[i*c+j], cmap='gray')
axs[j].axis('off')
这是head_CT.tif图像。
谢谢你的帮助。
*此图像来自 Gonzalez & Woods,数字图像处理一书。