1

I m currently using canny edge det. for segmentation but i am getting little distortions inside the circles as seen in the first image (such as the ones marked as red)
--Distortions.

I tried to change threshold values, distortions are reduced but i started to lose some of the circles as well. how can i get rid of them?

thats the code i use:

 

import cv2 
import numpy as np

from matplotlib import pyplot as plt
from google.colab.patches import cv2_imshow


img = cv2.imread('t1.PNG',0)
#img = cv2.medianBlur(img,5)
#img = cv2.threshold(img,0 ,255,cv2.THRESH_OTSU + cv2.THRESH_BINARY)




cv2.waitKey(0)

img = np.array(img, dtype=np.uint8)



img_gray = img#cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2_imshow(img_gray)


img_blur = cv2.GaussianBlur(img_gray, (3,3), 0)

sigma=0.33
v = np.mean(img)
z= np.median(img)
l = int(max(0, (1.0 - sigma) * v))
#l=0.66*v

u = int(min(255, (1.0 + sigma) * v))
print(l)
print(u)
print(v)
print(z)
#u=1.33*v

edges = cv2.Canny(image=img_blur, threshold1=0, threshold2=10) # Canny Edge Detection
edges1 = cv2.Canny(image=img_blur, threshold1=l, threshold2=u/9, ) # Canny Edge Detection +++

edges12 = cv2.Canny(image=img_blur, threshold1=l*6, threshold2=u , L2gradient = True) # Canny Edge Detection

contours, hierarchy = cv2.findContours(edges12, 
    cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
  

cv2_imshow(edges1)

cv2.waitKey(0)
print("*-*-*")
cv2_imshow(edges12)

cv2.waitKey(0)
cv2.destroyAllWindows()
leleos
  • 11
  • 4

0 Answers0