def get_3D_from_4D(image, vol_idx=<NUM_LIT:0>):
img      = check_img(image)<EOL>hdr, aff = get_img_info(img)<EOL>if len(img.shape) != <NUM_LIT:4>:<EOL><INDENT>raise AttributeError('<STR_LIT>'.format(repr_imgs(img)))<EOL><DEDENT>if not <NUM_LIT:0> <= vol_idx < img.shape[<NUM_LIT:3>]:<EOL><INDENT>raise IndexError('<STR_LIT>'<EOL>'<STR_LIT>'.format(repr_imgs(img), img.shape[<NUM_LIT:3>], vol_idx))<EOL><DEDENT>img_data = img.get_data()<EOL>new_vol  = img_data[:, :, :, vol_idx].copy()<EOL>hdr.set_data_shape(hdr.get_data_shape()[:<NUM_LIT:3>])<EOL>return new_vol, hdr, aff<EOL>
Pick one 3D volume from a 4D nifti image file

    Parameters
    ----------
    image: img-like object or str
        Volume defining different ROIs.
        Can either be:
        - a file path to a Nifti image
        - any object with get_data() and get_affine() methods, e.g., nibabel.Nifti1Image.
        If niimg is a string, consider it as a path to Nifti image and
        call nibabel.load on it. If it is an object, check if get_data()
        and get_affine() methods are present, raise TypeError otherwise.

    vol_idx: int
        Index of the 3D volume to be extracted from the 4D volume.

    Returns
    -------
    vol, hdr, aff
        The data array, the image header and the affine transform matrix.