Ignore peak values with transforms.normalize

I am using transforms.Normalize to normalize chest x-rays before feeding into a DenseNet. I’ve noticed that some of these images have a large white square present somewhere in the image, and when this happens the normalized image ends up very dark. Aside from these random white squares the images should have a pretty normal distribution…so I’m assuming histograms of these have a normal distribution and then very high very narrow jump up around 255. Is there a way with transforms.Normalize to ignore these abnormal peak values?

Hi @bkonk ,

When using transforms.Normalize, you are the one specifying the mean and std for each image. How do you compute it per sample?

Thanks for the reply @spanev,

This is branching off topic a bit, but I’m a little unclear on how to set the means and stds. I initially went with those used in Chexnet (densenet for a huge x-ray database) as I thought these would translate well, but the images I was viewing (with matplotlib.pyplot…maybe this distorts things a bit?) were looking very dark or very saturated. My images are 0 to 255 value .png files. I tried loading them, converting to a -1 to 1 range, and then grabbing the means and stds across all images, but this gave even worse looking results. I similarly opened the pngs as numpy arrays with cv2, and tried changing those white-box values (usually 1 or 255 depending on range) to whatever the mean value was of the other pixels and then re-saving. This seemed to help a bit when it came to previewing those white-box images (i.e., they weren’t super dark except for the box) but doesn’t seem like a great solution.