I am working on medical images containing sub-images. I want to segment these image types into their component sub-images. I tried a lot of codes that do segmentation but nothing of segment the image into the sub-images parts. please help me to do that.
Original image and the sub-images that should be segmented
Trail code
def tile(filename, dir_in, dir_out, d):
name, ext = os.path.splitext(filename)
img = Image.open(os.path.join(dir_in, filename))
w, h = img.size
grid = product(range(0, h-h%d, d), range(0, w-w%d, d))
for i, j in grid:
box = (j, i, j+d, i+d)
out = os.path.join(dir_out, f'{name}_{i}_{j}{ext}')
img.crop(box).save(out)
dir_in="/content/drive/MyDrive/Images"
dir_out="/content/drive/MyDrive/output_segments"
filename='image 2.jpg'
d=100
output=tile(filename,dir_in,dir_out,d)
Any help would be appreciated.py