I have this image as shown below. It is a binary mask
I created this image using the below code. Basically I got the x_idx, y_idx for just those white pixels, and I know the actual image size, so I first create an empty array and filled those lines with the help of x_idx and y_idx
image = np.empty((x_shape, y_shape))
def line_to_img(linedf, image):
x_idx = linedf.x
y_idx = linedf.y
for i,j in zip(x_idx, y_idx):
image[i, j] = 1
return image
as you can see all pixels are the same except 2 lines, one on the left and one in right.
As you can see that the right line is not continuous and I want to make this line continuous by some interpolation method
I've tried to work on two different methods to achieve this, but no luck so far
1st Method using skimage
new_image = skimage.morphology.remove_small_holes(old_image, 40, connectivity=2, in_place=False)
Interpretation of output: Same image without any interpolation
2nd Method using cv2
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(3,3))
new_image = cv2.morphologyEx(old_image,cv2.MORPH_OPEN,kernel)
Interpretation of output: Line got removed for some reason
Please help me on how to achieve this task and interpolate the line in the image to get a continuous line
EDIT (Use-Case): Basically I got the x_idx, y_idx for just those white pixels, and I know the actual image size, so I first create an empty array and filled those lines with the help of x_idx and y_idx I don't have control of the data, this is what it is, now I want to join the line on the right size. Basically, I've to create segmentation labels, in which above the line is one label and below the line is one label, left side is fine, I can divide the image into two labels based on that line, while the middle portion will remain for class 1 i.e., Upper part, while I know for sure that right side is a single line, it's just that the data I got is degraded, so I want this interpolation to come into the picture






