Exemplo n.º 1
0
def preprocess_volume_3d(volume,
                         crop_size,
                         patches_per_side,
                         patch_overlap,
                         is_training=True):
    result = []
    w, _, _, _ = volume.shape

    if is_training:
        volume = crop_3d(volume, is_training,
                         (crop_size, crop_size, crop_size))
        volume = pad_to_final_size_3d(volume, w)

    for patch in crop_patches_3d(volume, is_training, patches_per_side,
                                 -patch_overlap):
        if is_training:
            normal_patch_size = patch.shape[0]
            patch_crop_size = int(normal_patch_size * (7.0 / 8.0))

            do_flip = np.random.choice([False, True])
            if do_flip:
                patch = np.flip(patch, 0)

            patch = crop_3d(
                patch, is_training,
                (patch_crop_size, patch_crop_size, patch_crop_size))
            patch = pad_to_final_size_3d(patch, normal_patch_size)

        else:
            pass  # lets give it the most information we can get

        result.append(patch)

    return np.asarray(result)
Exemplo n.º 2
0
def preprocess_image(image, is_training, patches_per_side, patch_jitter,
                     permutations, mode3d):
    label = random.randint(0, len(permutations) - 1)

    if mode3d:
        patches = crop_patches_3d(image, is_training, patches_per_side,
                                  patch_jitter)
    else:
        patches = crop_patches(image, is_training, patches_per_side,
                               patch_jitter)

    b = np.zeros((len(permutations), ))
    b[label] = 1

    return np.array(patches)[np.array(permutations[label])], np.array(b)
def preprocess_image_3d(image, patches_per_side, patch_jitter, is_training):
    cropped_image = crop_patches_3d(image, is_training, patches_per_side,
                                    patch_jitter)
    return np.array(cropped_image)
Exemplo n.º 4
0
def preprocess_image_crop_only(image, patches_per_side, is_training, mode3d):
    if mode3d:
        patches = crop_patches_3d(image, is_training, patches_per_side, 0)
    else:
        patches = crop_patches(image, is_training, patches_per_side, 0)
    return np.stack(patches)