hitachinsk / SAMed

The implementation of the technical report: "Customized Segment Anything Model for Medical Image Segmentation"
MIT License
468 stars 43 forks source link

Image normalization #18

Open sashkagil opened 1 year ago

sashkagil commented 1 year ago

Hi, thank you very much for publishing such a wonderful work, it is a great help! I have a question regarding data normalization. I'd like to use your code for my data and a bit confused about how to normalize my images. I saw your code preprocess_data.py and it seems that the following lines should normalize the image to be [0,1]: image_data = np.clip(image_data, a_min, a_max) image_data = (image_data - a_min) / (a_max - a_min) But I can see that your input images have negative values, and above 1 as well. Or should I maybe use the original SAM normalization values: (when the images is [0,255] copying the channel 3 times) pixel_mean: List[float] = [123.675, 116.28, 103.53], pixel_std: List[float] = [58.395, 57.12, 57.375],

Thank you very much!

hitachinsk commented 1 year ago

You can use the original SAM normalization values, but we did not use it in our implementation.

sashkagil commented 1 year ago

Thank you for your answer. If I understand correctly, I can use the original values if starting from SAM's original checkpoint (sam_vit_b_01ec64.pth). But if I would like to start from your checkpoint (which is of course much better on medical images), how should I normalize my images? I looked at your preprocessing section, but wasn't quite able to understand. It seems that you normalize to [0,1], but when looking at your batches loaded from *npz files, they have different values, around ~[-1,2]. Thank you for your help!