def transform(self, data):
     config = CONFIG
     type = np.random.choice(13)
     img, mask = data[0, :, :, 0], data[1, :, :, 0]
     if type == 0:
         img, mask = img, mask
     if config.do_center_pad_to_factor and type == 1:
         img, mask = do_center_pad_to_factor2(img, mask)
     if config.do_random_shift_scale_crop_pad and type == 2:
         img, mask = do_random_shift_scale_crop_pad2(img, mask)
     if config.do_random_pad_to_factor and type == 3:
         img, mask = do_random_pad_to_factor2(img, mask)
     if config.do_shift_scale_rotate and type == 4:
         img, mask = do_shift_scale_rotate2(img, mask)
     if config.do_horizontal_flip and type == 5:
         img, mask = do_horizontal_flip2(img, mask)
     if config.do_horizontal_shear and type == 6:
         img, mask = do_horizontal_shear2(img, mask)
     if config.do_elastic_transform and type == 7:
         img, mask = do_elastic_transform2(img, mask)
     if config.do_flip_transpose and type == 8:
         img, mask = do_flip_transpose2(img, mask, type=np.random.choice(5))
     if config.do_brightness_shift and type == 9:
         img = do_brightness_shift(img)
     if config.do_brightness_multiply and type == 10:
         img = do_brightness_multiply(img, np.random.uniform(0.92, 1.08))
     if config.do_gamma and type == 11:
         img = do_gamma(img)
     if config.do_invert_intensity and type == 12:
         img = do_invert_intensity(img)
     if not img_size_ori == img_size_target and config.doresize:
         img, mask = do_resize2(img, mask, img_size_target, img_size_target)
     return np.stack((img, mask)).transpose(1, 2, 0)
Exemplo n.º 2
0
def valid_transform(imgs, masks, config):
    valid_transform_imgs = []
    valid_trasnform_masks = []
    for id in range(len(imgs)):
        img, mask = np.squeeze(imgs[id], axis=2), np.squeeze(masks[id], axis=2)

        if not img_size_ori == img_size_target and config.doresize:
            img, mask = do_resize2(img, mask, img_size_target, img_size_target)
        valid_transform_imgs.append(img)
        valid_trasnform_masks.append(mask)
    return np.array(valid_transform_imgs).reshape(-1, img_size_target, img_size_target, 1), \
           np.array(valid_trasnform_masks).reshape(-1, img_size_target, img_size_target, 1)
Exemplo n.º 3
0
def transform(imgs, masks, config):
    transform_imgs = []
    transform_masks = []
    for id in range(len(imgs)):
        img, mask = np.squeeze(imgs[id], axis=2), np.squeeze(masks[id], axis=2)
        if config.do_center_pad_to_factor and np.random.randint(2):
            img, mask = do_center_pad_to_factor2(img, mask)
        if config.do_random_shift_scale_crop_pad:
            img, mask = do_random_shift_scale_crop_pad2(img, mask)
        if config.do_random_pad_to_factor and np.random.randint(2):
            img, mask = do_random_pad_to_factor2(img, mask)
        if config.do_shift_scale_rotate and np.random.randint(2):
            img, mask = do_shift_scale_rotate2(img, mask)
        if config.do_horizontal_flip and np.random.randint(2):
            img, mask = do_horizontal_flip2(img, mask)
        if config.do_horizontal_shear and np.random.randint(2):
            img, mask = do_horizontal_shear2(img, mask)
        if config.do_elastic_transform and np.random.randint(2):
            img, mask = do_elastic_transform2(img, mask)
        if config.do_flip_transpose and np.random.randint(2):
            img, mask = do_flip_transpose2(img, mask, type=np.random.choice(7))
        if config.do_brightness_shift and np.random.randint(2):
            img = do_brightness_shift(img)
        if config.do_brightness_multiply and np.random.randint(2):
            img = do_brightness_multiply(img)
        if config.do_gamma and np.random.randint(2):
            img = do_gamma(img)
        if config.do_invert_intensity and np.random.randint(2):
            img = do_invert_intensity(img)
        if not img_size_ori == img_size_target and config.doresize:
            img, mask = do_resize2(img, mask, img_size_target, img_size_target)

        transform_imgs.append(img)
        transform_masks.append(mask)
    return np.array(transform_imgs).reshape(-1, img_size_target, img_size_target, 1), \
           np.array(transform_masks).reshape(-1, img_size_target, img_size_target, 1)
def resize_transform(data):
    img, mask = data[0, :, :], data[1, :, :]
    if not img_size_ori == img_size_target:
        img, mask = do_resize2(img, mask, img_size_target, img_size_target)

    return np.stack((img, mask))