bowang-lab / MedSAM

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

LiteMedSAM的inference_2D.py能否直接使用一系列的box #312

Open chimmut opened 1 week ago

chimmut commented 1 week ago

我想知道LiteMedSAM的inference_2D.py在分割一张bmp图片时能否直接读取一系列的box作为提示,而不是使用.npz文件。如果可以的话,能否告诉我该如何修改代码?期待您的回复

ff98li commented 1 week ago

Yes, it is possible to modify the inference_2D.py script to read a series of bounding boxes as prompts directly instead of using an .npz file:

  1. Images in the .npz format are preprocessed and scaled to the value range of [0, 255] with np.uint8 dtype and ensured to have 3 channels. To use other input formats, you'll first need to add preprocessing code to convert your input image to the same format: https://github.com/bowang-lab/MedSAM/blob/5b2fc44be42ea43b98f6b9e265884d7c2d183540/pre_grey_rgb.py#L47-L52
  2. After adding the preprocessing part, a better reference for your purpose of using LiteMedSAM with a series of bounding box prompts is CVPR24_LiteMedSAM_infer.py. https://github.com/bowang-lab/MedSAM/blob/5b2fc44be42ea43b98f6b9e265884d7c2d183540/CVPR24_LiteMedSAM_infer.py#L374-L399 You'll need to format your bounding boxes as a list, where each element is a numPy array in the format [x_min, y_min, x_max, y_max], e.g.
    boxes = [
    np.array([100, 200, 300, 400]),
    np.array([500, 600, 700, 800]),
    # Add more bounding boxes as needed
    ]