I am currently working on a project that is needed to cut background and after all smooth it's borders
What I have as a input:
Input:
What I wnat to do :
Cut background:
Smooth edges:
The idea of code is that after background cut, edges are not perfect and it would be better if these edges have been smoothed
What I tried: I saves mask edges
img_path = 'able.png'
img_data = cv2.imread(img_path)
img_data = img_data > 128
img_data = np.asarray(img_data[:, :, 0], dtype=np.double)
gx, gy = np.gradient(img_data)
temp_edge = gy * gy + gx * gx
temp_edge
temp_edge[temp_edge != 0.0] = 255.0
temp_edge = np.asarray(temp_edge, dtype=np.uint8)
cv2.imwrite('mask_edge.png', temp_edge)
After all I get stuck