Download MedImageInsight/ImageDataLoader/transforms/threeaugment.py from lion-ai/MedImageInsights: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/lion-ai/MedImageInsights/resolve/main/MedImageInsight/ImageDataLoader/transforms/threeaugment.py
- Command line
-
hf download hf://lion-ai/MedImageInsights/MedImageInsight/ImageDataLoader/transforms/threeaugment.py
-
curl -L -o threeaugment.py https://huggingface.co/lion-ai/MedImageInsights/resolve/main/MedImageInsight/ImageDataLoader/transforms/threeaugment.py
1.26 kB
| import random | |
| from PIL import ImageFilter, ImageOps | |
| from torchvision import transforms | |
| class deitIII_GaussianBlur(object): | |
| """ | |
| Apply Gaussian Blur to the PIL image. | |
| """ | |
| def __init__(self, p=0.1, radius_min=0.1, radius_max=2.): | |
| self.prob = p | |
| self.radius_min = radius_min | |
| self.radius_max = radius_max | |
| def __call__(self, img): | |
| do_it = random.random() <= self.prob | |
| if not do_it: | |
| return img | |
| img = img.filter( | |
| ImageFilter.GaussianBlur( | |
| radius=random.uniform(self.radius_min, self.radius_max) | |
| ) | |
| ) | |
| return img | |
| class deitIII_Solarization(object): | |
| """ | |
| Apply Solarization to the PIL image. | |
| """ | |
| def __init__(self, p=0.2): | |
| self.p = p | |
| def __call__(self, img): | |
| if random.random() < self.p: | |
| return ImageOps.solarize(img) | |
| else: | |
| return img | |
| class deitIII_gray_scale(object): | |
| """ | |
| Apply Solarization to the PIL image. | |
| """ | |
| def __init__(self, p=0.2): | |
| self.p = p | |
| self.transf = transforms.Grayscale(3) | |
| def __call__(self, img): | |
| if random.random() < self.p: | |
| return self.transf(img) | |
| else: | |
| return img | |