python - Image processing issues with blood vessels -
i'm trying extract blood vessels image, , so, i'm first equalizing image, applying clahe histogram obtain following result:
clahe = cv2.createclahe(cliplimit=100.0, tilegridsize=(100,100)) self.cl1 = clahe.apply(self.result_array) self.cl1 = 255 - self.cl1
and i'm using otsu threshold extract blood vessels, failing well:
self.ret, self.thresh = cv2.threshold(self.cl1, 0,255,cv2.thresh_binary + cv2.thresh_otsu) kernel = np.ones((1,1),np.float32)/1 self.thresh = cv2.erode(self.thresh, kernel, iterations=3) self.thresh = cv2.dilate(self.thresh, kernel, iterations=3)
here's result:
obviously there's lot of noise. i've tried using median blur, clusters noise , makes blob, in places. how go removing noise blood vessels?
this original image i'm trying extract blood vessels:
getting results difficult problem (you'll have somehow model structure of blood vessels , noise) can still better filtering.
one technique addressing kind of problems, inspired canny edge detector, using 2 thresholds - [hi,low]
, classifying pixel p
response r
belonging blood vessel v
if r > hi
|| (r > lo
&& 1 of p
's neighbors in v
).
also, when comes filtering, both bilateral filtering , meanshift filtering noisy images.
kernel3 = cv2.getstructuringelement(cv2.morph_ellipse,(3,3)) kernel5 = cv2.getstructuringelement(cv2.morph_ellipse,(5,5)) kernel7 = cv2.getstructuringelement(cv2.morph_ellipse,(7,7)) t_lo = 136 t_hi = 224 blured = cv2.pyrmeanshiftfiltering(img, 3, 9) #blured = cv2.bilateralfilter(img, 9, 32, 72) clahe = cv2.createclahe(cliplimit=128.0, tilegridsize=(64, 64)) cl1 = clahe.apply(blured) cl1 = 255 - cl1 ret, thresh_hi = cv2.threshold(cl1, t_hi, 255, cv2.thresh_tozero) ret, thresh_lo = cv2.threshold(cl1, t_lo, 255, cv2.thresh_tozero)
low threshold image hi threshold image
preparations , cleanup:
current = np.copy(thresh_hi) prev = np.copy(current) prev[:] = 0 current = cv2.morphologyex(current, cv2.morph_open, kernel5) iter_num = 0 max_iter = 1000
not efficient way that... easy implement:
while np.sum(current - prev) > 0 , iter_num < max_iter: iter_num = iter_num+1 prev = np.copy(current) current = cv2.dilate(current, kernel3) current[np.where(thresh_lo == 0)] = 0
remove small blobs:
contours, hierarchy = cv2.findcontours(current, cv2.retr_list, cv2.chain_approx_simple) contour in contours: area = cv2.contourarea(contour) if area < 256: cv2.drawcontours( current, [contour], 0, [0,0,0], -1 )
morphological cleanup:
opening = cv2.morphologyex(current, cv2.morph_open, kernel7) cl1[np.where(opening == 0)] = 0
this no means optimal, think should provide enough tools start.
Comments
Post a Comment