0

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

enter image description here

enter image description here

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

Eda
  • 565
  • 1
  • 7
  • 18
  • This seems to be a duplicate of your previous question: [Split labelling image parts into sub labelled images using python](https://stackoverflow.com/questions/75202868/split-labelling-image-parts-into-sub-labelled-images-using-python) Please do not duplicate questions. If you are not receiving the answers you want, consider improving your question instead. See [What should I do if no one answers my question?](https://stackoverflow.com/help/no-one-answers) – beaker Jan 23 '23 at 18:25
  • @beaker it is not the same Question nor duplicate. it is another Question on the same images. – Eda Jan 23 '23 at 21:07
  • Can you clarify what you're looking for, then? The images are the same, the code is the same, the only difference I can see in the question is that this time you don't mention splitting the image according to the labelled letter. But if the same code that you used to "perform general segmentation according to a specific tile not according to the labelled letter found in the original image", why is this code now not working for your current task? – beaker Jan 23 '23 at 21:20
  • @beaker I want to segment the original image into sub images. The same code because the code is a general segmentation so I can perform a general segmentation for any part in the image but I don't how to do any segmentation or extraction on this image. In the first Question is to perform segmentation according to the labelled letter. – Eda Jan 23 '23 at 21:27

0 Answers0