def scale_input_to_original_shape(img4d, dataset, resolution="1.25mm"):
    """
    Scale input image to original resolution and pad/cut image to make it original size.
    This is not generic but optimised for some specific datasets.

    Args:
        img4d:  (x, y, z, classes)
        dataset: HCP|HCP_32g|TRACED|Schizo
        resolution: 1.25mm|2mm|2.5mm

    Returns:
        (x_original, y_original, z_original, classes)
    """
    if resolution == "1.25mm":
        if dataset == "HCP":  # (144,144,144)
            # no resize needed
            return img_utils.pad_4d_image_left(img4d, np.array([1, 15, 1, 0]),
                                               [146, 174, 146, img4d.shape[3]], pad_value=0)  # (146, 174, 146, none)
        elif dataset == "HCP_32g":  # (144,144,144)
            # no resize needed
            return img_utils.pad_4d_image_left(img4d, np.array([1, 15, 1, 0]),
                                               [146, 174, 146, img4d.shape[3]], pad_value=0)  # (146, 174, 146, none)
        elif dataset == "TRACED":  # (78,93,75)
            raise ValueError("resolution '1.25mm' not supported for dataset 'TRACED'")
        elif dataset == "Schizo":  # (144,144,144)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([1, 15, 1, 0]),
                                                [145, 174, 145, img4d.shape[3]], pad_value=0)  # (145, 174, 145, none)
            return img_utils.resize_first_three_dims(img4d, zoom=0.62)  # (91,109,91)

    elif resolution == "2mm":
        if dataset == "HCP":  # (80,80,80)
            return img_utils.pad_4d_image_left(img4d, np.array([5, 14, 5, 0]),
                                               [90, 108, 90, img4d.shape[3]], pad_value=0)  # (90, 108, 90, none)
        elif dataset == "HCP_32g":  # (80,80,80)
            return img_utils.pad_4d_image_left(img4d, np.array([5, 14, 5, 0]),
                                               [90, 108, 90, img4d.shape[3]], pad_value=0)  # (90, 108, 90, none)
        elif dataset == "HCP_2mm":  # (80,80,80)
            return img_utils.pad_4d_image_left(img4d, np.array([5, 14, 5, 0]),
                                               [90, 108, 90, img4d.shape[3]], pad_value=0)  # (90, 108, 90, none)
        elif dataset == "TRACED":  # (78,93,75)
            raise ValueError("resolution '2mm' not supported for dataset 'TRACED'")

    elif resolution == "2.5mm":
        if dataset == "HCP":  # (80,80,80)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([0, 4, 0, 0]),
                                                [80, 87, 80, img4d.shape[3]], pad_value=0) # (80,87,80,none)
            return img4d[4:77,:,4:77, :] # (73, 87, 73, none)
        elif dataset == "HCP_2.5mm":  # (80,80,80)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([0, 4, 0, 0]),
                                                [80, 87, 80, img4d.shape[3]], pad_value=0)  # (80,87,80,none)
            return img4d[4:77,:,4:77,:]  # (73, 87, 73, none)
        elif dataset == "HCP_32g":  # ((80,80,80)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([0, 4, 0, 0]),
                                                [80, 87, 80, img4d.shape[3]], pad_value=0)  # (80,87,80,none)
            return img4d[4:77, :, 4:77, :]  # (73, 87, 73, none)
        elif dataset == "TRACED":  # (80,80,80)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([0, 7, 0, 0]),
                                                [80, 93, 80, img4d.shape[3]], pad_value=0)  # (80,93,80,none)
            return img4d[1:79, :, 3:78, :]  # (78,93,75,none)
Beispiel #2
0
def scale_input_to_world_shape(img4d, dataset, resolution="1.25mm"):
    '''
    Scale input image to original resolution and pad/cut image to make it original size

    :param img4d: (x, y, z, userdefined)  (userdefined could be gradients or classes)
    :param resolution: "1.25mm" / "2mm" / "2.5mm"
    :return: img with original size
    '''

    if resolution == "1.25mm":
        if dataset == "HCP":  # (144,144,144)
            # no resize needed
            return img_utils.pad_4d_image_left(img4d, np.array([1, 15, 1, 0]),
                                               [146, 174, 146, img4d.shape[3]], pad_value=0)  # (146, 174, 146, none)
        elif dataset == "HCP_32g":  # (144,144,144)
            # no resize needed
            return img_utils.pad_4d_image_left(img4d, np.array([1, 15, 1, 0]),
                                               [146, 174, 146, img4d.shape[3]], pad_value=0)  # (146, 174, 146, none)
        elif dataset == "TRACED":  # (78,93,75)
            raise ValueError("resolution '1.25mm' not supported for dataset 'TRACED'")
        elif dataset == "Schizo":  # (144,144,144)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([1, 15, 1, 0]),
                                                [145, 174, 145, img4d.shape[3]], pad_value=0)  # (145, 174, 145, none)
            return img_utils.resize_first_three_dims(img4d, zoom=0.62)  # (91,109,91)

    elif resolution == "2mm":
        if dataset == "HCP":  # (80,80,80)
            return img_utils.pad_4d_image_left(img4d, np.array([5, 14, 5, 0]),
                                               [90, 108, 90, img4d.shape[3]], pad_value=0)  # (90, 108, 90, none)
        elif dataset == "HCP_32g":  # (80,80,80)
            return img_utils.pad_4d_image_left(img4d, np.array([5, 14, 5, 0]),
                                               [90, 108, 90, img4d.shape[3]], pad_value=0)  # (90, 108, 90, none)
        elif dataset == "HCP_2mm":  # (80,80,80)
            return img_utils.pad_4d_image_left(img4d, np.array([5, 14, 5, 0]),
                                               [90, 108, 90, img4d.shape[3]], pad_value=0)  # (90, 108, 90, none)
        elif dataset == "TRACED":  # (78,93,75)
            raise ValueError("resolution '2mm' not supported for dataset 'TRACED'")

    elif resolution == "2.5mm":
        if dataset == "HCP":  # (80,80,80)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([0, 4, 0, 0]),
                                                [80, 87, 80, img4d.shape[3]], pad_value=0) # (80,87,80,none)
            return img4d[4:77,:,4:77, :] # (73, 87, 73, none)
        elif dataset == "HCP_2.5mm":  # (80,80,80)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([0, 4, 0, 0]),
                                                [80, 87, 80, img4d.shape[3]], pad_value=0)  # (80,87,80,none)
            return img4d[4:77,:,4:77,:]  # (73, 87, 73, none)
        elif dataset == "HCP_32g":  # ((80,80,80)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([0, 4, 0, 0]),
                                                [80, 87, 80, img4d.shape[3]], pad_value=0)  # (80,87,80,none)
            return img4d[4:77, :, 4:77, :]  # (73, 87, 73, none)
        elif dataset == "TRACED":  # (80,80,80)
            img4d = img_utils.pad_4d_image_left(img4d, np.array([0, 7, 0, 0]),
                                                [80, 93, 80, img4d.shape[3]], pad_value=0)  # (80,93,80,none)
            return img4d[1:79, :, 3:78, :]  # (78,93,75,none)