Reputation: 1
I am working on a project in which I have to complete the broken lines in the image below and then calculate the area. Is there any way to complete the broken lines in the image below using python?
Upvotes: 0
Views: 1779
Reputation: 3260
Do you mean something like this?
This can be done with simple morphology; however, it is subject to two conditions:
import matplotlib.pyplot as plt
import numpy as numpy
from skimage import io
from skimage import morphology
img = io.imread("test.png", as_gray=True)
# fill horizontal gaps
selem_horizontal = morphology.rectangle(1,50)
img_filtered = morphology.closing(img, selem_horizontal)
# fill vertical gaps
selem_vertical = morphology.rectangle(80,1)
img_filtered = morphology.closing(img_filtered, selem_vertical)
plt.imshow(img_filtered, cmap="gray")
plt.gca().axis("off")
plt.show()
Upvotes: 3