bowang-lab / MedSAM

Segment Anything in Medical Images
https://www.nature.com/articles/s41467-024-44824-z
Apache License 2.0
2.78k stars 374 forks source link

How can we effectively apply the trained model to .nifti images with various sizes and accurately retrieve the original image dimensions in the end? #115

Closed RRouhi closed 1 year ago

RRouhi commented 1 year ago

Thank you for your excellent work. Could you please provide some guidance on how to apply the trained model to .nifi images? Since the training requires an image size of 1024, I would appreciate any hints on how to obtain the original image size after performing the inference. I am concerned that resizing might result in a loss of resolution. If possible, could you kindly add a code snippet addressing this issue to the repository?

JunMa11 commented 1 year ago

Hi @RRouhi ,

Please check the latest demo:

https://github.com/bowang-lab/MedSAM#get-started

The segmentation output size is the same as the input size. So you can add the nii metadata to the segmentation results and save them into nii again.

RRouhi commented 1 year ago

@JunMa11 thank you. How about the output of finetuning available here https://github.com/bowang-lab/MedSAM/tree/0.1? I appreciate your guidance in advance.

JunMa11 commented 1 year ago

Hi @RRouhi ,

You can use this function to resize the image to its original size.

https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.resize