Separating touching objects in binary image

Thank you for respose Steve!
0. Here is resized input image. I used u-net to segment it.


Predicted mask looks like this: https://i.imgur.com/RxYMTe4.jpeg

  1. I used function to process the following mask (aim was to remove all the noise):
def mask_preprocessing(mask):
    gray = cv2.imread(mask)                                                   #read mask

    #---mask preprocessing stage
    ret,thresh = cv2.threshold(gray,150,255,0)                                #apply threshhold to remove any noise
    kernel_1 = np.ones((5,5), np.uint8)                                       #dilation kernel
    kernel_2 = np.ones((4,4), np.uint8)                                       #erosion kernel
    dilation = cv2.dilate(thresh,kernel_1, iterations=1)                      #apply dialation
    erosion = cv2.erode(dilation, kernel_2, iterations=1)                     #apply erosion
    preprocessed = cv2.cvtColor(erosion, cv2.COLOR_BGR2GRAY)
    
 
    return preprocessed

Yes, you are right. In original image and processed mask there is a gap. But in some cases even in original images there are almost no visible gaps, so I need to make my code robust and universal for all the situations. I will definitely consider your advice. Maybe you have any exaple codes for the simillar situation?