I am generating material for a computer vision (CV) class and I would like to calculate the area of this highlighted part through conventional CV techniques:
So, I have applied Canny to detect edges and a Circle Hough transform trying to find the respective area. These are my results:
I tried to use Watershed, with the markers as the center of the circles I found, but I had no success. Does anyone have any idea how can I continue or have other ideas?
Here is the code :
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')
Here is the head_CT.tif image.
Thanks for any help.
*This image is from Gonzalez & Woods, Digital Image Processing book.