def inverse_square_crop(croped_image, square_mask):
    if square_mask.orientation != 'IRP':
        square_mask = set_orientation(square_mask, 'IRP')
    nz_coord = square_mask.getNonZeroCoordinates()

    assert len(nz_coord) == croped_image.data.size
    dim = len(croped_image.data.shape)

    inverse_croped = square_mask.copy()
    if dim == 3:
        done_slices = []
        for coord in nz_coord:
            if coord.x not in done_slices:
                inverse_croped.data[coord.x, coord.y: coord.y + croped_image.data.shape[1], coord.z: coord.z + croped_image.data.shape[2]] = croped_image.data[coord.x]
                done_slices.append(coord.x)
    elif dim == 2:
        coord = nz_coord[0]
        inverse_croped.data[coord.x: coord.x + croped_image.data.shape[0], coord.y: coord.y + croped_image.data.shape[1]] = croped_image.data

    inverse_croped.setFileName(croped_image.file_name + '_original_dimension' + croped_image.ext)

    return inverse_croped


########################################################################################################################
# --------------------------------------------------- VALIDATION ----------------------------------------------------- #
########################################################################################################################

# ------------------------------------------------------------------------------------------------------------------
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/scripts/msct_gmseg_utils.py/inverse_square_crop/original