python中不完整的圆检测

时间:2019-05-28 05:19:20

标签: python opencv image-segmentation

我现在有一个分段的光盘,我想检测它的中心。请帮我解决一下这个。我正在使用python。我想检测中心,但是无法使用霍夫变换。

分段光盘

segmented disc

原始图片

original image  `

image = cv2.imread('as1.png', cv2.IMREAD_COLOR)
Abo,Ago,Aro = cv2.split(image)  #splitting into 3 channels
#Aro = clahe.apply(Aro)
Ago = clahe.apply(Ago)
M = 60    #filter size
filter = signal.gaussian(M, std=6) #Gaussian Window
filter=filter/sum(filter)
STDf = filter.std()  #It'standard deviation
Ar = Aro - Aro.mean() - Aro.std() #Preprocessing Red  
Mr = Ar.mean()                           #Mean of preprocessed red
SDr = Ar.std()                           #SD of preprocessed red
Thr = 0.5*M-STDf -Ar.std()            #Optic disc Threshold
#print(Thr)
Ag = Ago - Ago.mean() - Ago.std()        #Preprocessing Green
Mg = Ag.mean()                           #Mean of preprocessed green
SDg = Ag.std()                           #SD of preprocessed green
Thg = 0.5*Mg +2*STDf + 2*SDg + Mg        #Optic Cup Threshold
#print(Thg)  
hist,bins = np.histogram(Ag.ravel(),256,[0,256])   #Histogram of preprocessed green channel
histr,binsr = np.histogram(Ar.ravel(),256,[0,256]) #Histogram of preprocessed red channel
smooth_hist_g=np.convolve(filter,hist)  #Histogram Smoothing Green
smooth_hist_r=np.convolve(filter,histr) #Histogram Smoothing Red   
r,c = Ag.shape
Dd = np.zeros(shape=(r,c)) #Segmented disc image initialization
Dc = np.zeros(shape=(r,c)) #Segmented cup image initialization
#Using obtained threshold for thresholding of the fundus image
for i in range(1,r):
    for j in range(1,c):
        if Ar[i,j]>Thr:
            Dd[i,j]=255
        else:
            Dd[i,j]=0
for i in range(1,r):
    for j in range(1,c): 
        if Ag[i,j]>Thg:
            Dc[i,j]=1
        else:
            Dc[i,j]=0        
#Saving the segmented image in the same place as the code folder    cv2.imwrite('disk.png',Dd)
plt.imsave('cup.png',Dc)

`

0 个答案:

没有答案