ZFTurbo / volumentations

Library for 3D augmentations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any specific purpose of using different resize methods in the resize function in functional?

flora-sun-zhixin opened this issue · comments

Hi, thanks for sharing the code. After reading and testing the part of what I need, may I ask why you use different resize function here for image(assume is 3 dimensions) and mask(assume is 4 dimensions)?
For dim=3: you used skimage.transform.resize()
For dim=4: you used scipy.ndimage.zoom() for each channel
I tried the two on the same mask and in the resized masks there are some pixels labeled differently. So I am confused whether this will also trigger some mismatch between image and mask?

def resize(img, new_shape, interpolation=1):
    """
    img: [H, W, D, C] or [H, W, D]
    new_shape: [H, W, D]
    """
    type = 1

    if type == 0:
        new_img = skt.resize(img, new_shape, order=interpolation, mode='constant', cval=0, clip=True, anti_aliasing=False)
    else:
        shp = tuple(np.array(new_shape) / np.array(img.shape[:3]))
        # Multichannel
        data = []
        for i in range(img.shape[-1]):
            d0 = zoom(img[..., i].astype(np.uint8).copy(), shp, order=interpolation)
            data.append(d0.copy())
        new_img = np.stack(data, axis=3)

    return new_img

As I remember I added zoom because it was many times faster than skt.resize. I probably need to create some test script to show it.

Also I must note I almost not tested masks functionality with this package.