hmsch / natural-synthetic-anomalies

Code for ECCV 2022 paper "Natural Synthetic Anomalies for Self-Supervised Anomaly Detection and Localization".
https://arxiv.org/abs/2109.15222
MIT License
48 stars 6 forks source link

Using images with continues representation #2

Closed eliahuhorwitz closed 2 years ago

eliahuhorwitz commented 2 years ago

Hey, In the self_sup_tasks file in the patch_ex function it says the images should be of type uint8. Do you have an idea of how to change it to support images in the range of [0,1]? The reason I am asking is that I have images with a higher dynamic range and the discretization to [0,255] hurts the contents of the images. Instead I would like to use a continues representation if possible.

Thanks, Eliahu

hmsch commented 2 years ago

Hi Eliahu,

Since the data I worked with was mostly 0-255 RGB values, I used methods from OpenCV in several places in self_sup_tasks, e.g. for seamless cloning (i.e. Poisson blending). As far as I know, OpenCV usually represents each color channel by 8 bits (i.e. 0-255) so you won't be able to pass inputs with a higher dynamic range to those methods.

To avoid having to discretize your data to 0-255, you could replace all the cv2 calls with other imaging libraries or your own implementation. I think there are several open-source implementations of Poisson blending out there that you could substitute. But note that these will probably be slower than when using just 8-bits.

After the synthetic anomalies are generated, the rest of the training pipeline works with float32 data, so representing a higher dynamic range there should not be a problem.