Example #1
0
def test_gamma_float_equal_uint8():
    img = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
    img_f = img.astype(np.float32) / 255.0
    gamma = 0.5

    img = F.gamma_transform(img, gamma)
    img_f = F.gamma_transform(img_f, gamma)

    img = img.astype(np.float32)
    img_f *= 255.0

    assert (np.abs(img - img_f) <= 1).all()
 def __getitem__(self, index):
     img_path = self.images[index]
     img = cv2.cvtColor(cv2.imread(img_path), cv2.COLOR_BGR2RGB)
     img = F.gamma_transform(img, GAMMA_CORRECTION)
     
     if self.combination_type == "STAPLE" : 
         target = cv2.imread(self.staple_target[index], cv2.IMREAD_UNCHANGED)
     else :
         t1 = cv2.imread(self.target1[index], cv2.IMREAD_UNCHANGED)
         t2 = cv2.imread(self.target2[index], cv2.IMREAD_UNCHANGED)
         target = self.combine_multiple_targets(t1, t2)
         
     if self.get_disks:
         target_disk = cv2.imread(self.disks[index], cv2.IMREAD_UNCHANGED)
     
     if self.transforms is not None:
         if self.get_disks:
             augmented = self.transforms(image=img, masks=[target, target_disk])
         else:
             augmented = self.transforms(image=img, mask=target)
         img = augmented['image']
         # pick only green channel
         if self.green_only:
             img = img[[1]]
         if self.get_disks:
             target = torch.from_numpy(augmented['masks'][0]).long() / 255
             target_disk = torch.from_numpy(augmented['masks'][1]).long() / 255
         else:
             target = augmented['mask'].long() / 255
     if self.get_disks:
         return img, target, target_disk
     else:
         return img, target
Example #3
0
def preprocess_image(img, orig='DRIVE', gray=True):
    _, vt_ = get_transforms(orig)
    gamma_ = config.GAMMA_CORRECTION
    img_t = gamma_transform(img, gamma_)
    img_t = vt_(image=img_t)['image']
    if gray:
        img_t = img_t[[1]].unsqueeze(0)  # shape (B, 1, H, W)

    return img_t
Example #4
0
 def __getitem__(self, index):
     from interrater.config import GAMMA_CORRECTION
     target = self.target[index]
     img_path = self.images[index]
     try : 
         img = cv2.cvtColor(cv2.imread(img_path), cv2.COLOR_BGR2RGB)
         img = F.gamma_transform(img, GAMMA_CORRECTION)
         if self.transforms is not None:
             augmented = self.transforms(image=img)
             img = augmented['image']
 
         # pick only green channel (even if no transformation is applied)
         if self.green_only:
             img = img[[1]]
 
         return img, target
     except : 
         pdb.set_trace()
 def __getitem__(self, index):
     img_path = self.images[index]
     mask_path = self.masks[index]
     img = cv2.cvtColor(cv2.imread(img_path), cv2.COLOR_BGR2RGB)
     img = F.gamma_transform(img, GAMMA_CORRECTION)
     mask = imageio.imread(mask_path)
     if self.train:
         tgt_path = self.targets[index]
         target = imageio.imread(tgt_path)
         if self.transforms is not None:
             augmented = self.transforms(image=img, masks=[mask, target])
             img = augmented['image']
             if self.green_only:
                 img = img[[1]]
             mask, target = augmented['masks']
             # if isinstance(img, np.ndarray):
             #     img[mask == 0] = 0
             # else:
             #     img[:, mask == 0] = 0
             target = target.astype(int) / 255
         if self.return_mask:
             return img, torch.from_numpy(mask).long(), torch.from_numpy(target).long()
         else:
             return img, torch.from_numpy(target).long()
     else:
         if self.transforms is not None:
             augmented = self.transforms(image=img, mask=mask)
             img = augmented['image']
             if self.green_only:
                 img = img[[1]]
             mask = augmented['mask']
             # if isinstance(np.ndarray, img):
             #     img[mask == 0] = 0
             # else:
             #     img[:, mask == 0] = 0
         if self.return_mask:
             return img, torch.from_numpy(mask).long()
         return img
Example #6
0
 def albumentations(self, img):
     return albumentations.gamma_transform(img, gamma=0.5)
Example #7
0
def test_gamma_transform_float(gamma, expected):
    img = np.ones((100, 100, 3), dtype=np.float32) * 0.4
    expected = np.ones((100, 100, 3), dtype=np.float32) * expected
    img = F.gamma_transform(img, gamma=gamma)
    assert img.dtype == np.dtype("float32")
    assert np.allclose(img, expected)
Example #8
0
def test_gamma_transform(gamma, expected):
    img = np.ones((100, 100, 3), dtype=np.uint8)
    img = F.gamma_transform(img, gamma=gamma)
    assert img.dtype == np.dtype("uint8")
    assert (img == expected).all()
def test_gamma_transform(gamma, expected):
    img = np.ones((100, 100, 3), dtype=np.uint8)
    img = F.gamma_transform(img, gamma=gamma)
    assert img.dtype == np.dtype('uint8')
    assert (img == expected).all()
 def albumentations(self, img):
     return albumentations.gamma_transform(img, gamma=0.5)