0
我想從我的二進制圖像中刪除拉長的輪廓,但我仍然獲得大部分。我試圖刪除它們,但考慮到緊湊性和偏心因素,但這在我的情況下不起作用。如何從二進制圖像中刪除細長結構(輪廓)
im=cv2.imread('thresh.png')
gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
cv2.imshow('thres',gray)
gray2 = gray.copy()
mask = np.zeros(gray.shape,np.uint8)
contours, hier = cv2.findContours(gray2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
area=cv2.contourArea(cnt)
if area>=5:
ellipse = cv2.fitEllipse(cnt)
# center, axis_length and orientation of ellipse
(center,axes,orientation) = ellipse
# length of MAJOR and minor axis
majoraxis_length = max(axes)
minoraxis_length = min(axes)
eccentricity = np.sqrt(1-(minoraxis_length/majoraxis_length)**2)
#############compactness################
area=cv2.contourArea(cnt)
equi_diameter = np.sqrt(4*area/np.pi)
compactness=equi_diameter/majoraxis_length
########################################
if(eccentricity<=0.6 or eccentricity >1) or (compactness <0.8):
cv2.drawContours(gray2,[cnt],0,(0,0,0),1)
cv2.drawContours(mask,[cnt],0,255,-1)
cv2.imshow('final',mask)
任何人都可以建議我一些方法來消除這些拉長的輪廓。
您能否展示一些示例圖片來幫助您查看「這些拉長的輪廓」的含義? – AldurDisciple 2014-08-31 07:31:28
我編輯了我的帖子。我想要從二進制圖像中刪除像(結構化)的靜脈(拉長)@AldurDisciple – user3778289 2014-08-31 09:11:02
您是否嘗試過使用morpho-maths?例如。 'erode' +'dilate'或'morphologyEx'? – AldurDisciple 2014-08-31 10:07:38