def extract_patches(volume, patch_shape, extraction_step):
    patches = sk_extract_patches(volume,
                                 patch_shape=patch_shape,
                                 extraction_step=extraction_step)

    ndim = len(volume.shape)
    npatches = np.prod(patches.shape[:ndim])
    return patches.reshape((npatches, ) + patch_shape)
Beispiel #2
0
def extract_patches(img, patch_shape, extraction_step):
    from sklearn.feature_extraction.image import extract_patches as sk_extract_patches
    patches = sk_extract_patches(img,
                                 patch_shape=patch_shape,
                                 extraction_step=extraction_step)
    ndim = img.ndim
    npatches = np.prod(patches.shape[:ndim])
    return patches.reshape((npatches, ) + patch_shape)
def extract_patches(dimension, volume, patch_shape, extraction_step):
    actual_patch_shape = patch_shape
    actual_extraction_step = extraction_step
    # todo: need to check!!!
    if dimension == 2:
        if len(actual_patch_shape) == 3:
            actual_patch_shape = actual_patch_shape[:1] + (
                1, ) + actual_patch_shape[1:]
            actual_extraction_step = actual_extraction_step[:1] + (
                1, ) + actual_extraction_step[1:]
        else:
            actual_patch_shape = (1, ) + actual_patch_shape
            actual_extraction_step = (1, ) + actual_extraction_step

    patches = sk_extract_patches(volume,
                                 patch_shape=actual_patch_shape,
                                 extraction_step=actual_extraction_step)

    ndim = len(volume.shape)
    npatches = np.prod(patches.shape[:ndim])
    return patches.reshape((npatches, ) + patch_shape)
Beispiel #4
0
def extract_patches(dimension, volume, patch_shape, extraction_step):
    actual_patch_shape = patch_shape
    actual_extraction_step = extraction_step

    if dimension == 2:
        if len(actual_patch_shape) == 3:
            actual_patch_shape = actual_patch_shape[:1] + (
                1, ) + actual_patch_shape[1:]
            actual_extraction_step = actual_extraction_step[:1] + (
                1, ) + actual_extraction_step[1:]
        else:
            actual_patch_shape = (1, ) + actual_patch_shape
            actual_extraction_step = (1, ) + actual_extraction_step

    patches = sk_extract_patches(volume,
                                 patch_shape=actual_patch_shape,
                                 extraction_step=actual_extraction_step)

    ndim = len(volume.shape)
    npatches = np.prod(patches.shape[:ndim])

    print(np.shape(patches))
    #print(np.shape(patches.reshape([-1] + list(patch_shape))))
    return patches.reshape((npatches, ) + patch_shape)