-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdilationconstant.py
More file actions
22 lines (20 loc) · 837 Bytes
/
dilationconstant.py
File metadata and controls
22 lines (20 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import cv2
from curve_fit import findCurveFit
#helper function to find the optimal kernel for dilation
def dilation_constant_selector(image):
'''
This is an helper function to find the optimal K for the dilation. it checks with a list of K values and once the curve is fitted the K is returned to here
'''
ContourCount =[]
kernel_value =0
for i in range (1,100):
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (i,i))
dilate = cv2.dilate(image,kernel,iterations=1)
contours = cv2.findContours(dilate,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
ContourCount.append(len(contours[1]))
if i >=4:
pixelC, trigg = findCurveFit(ContourCount)
if trigg == True:
kernel_value=i
break
return kernel_value