2923434b29a910232dfd6c3f5b5639216900592a,ants/utils/convert_nibabel.py,,to_nibabel,#Any#,9

Before Change


    
    Convert an ANTsImage to a Nibabel image
    
    if image.dimension != 3:
        raise ValueError("Only 3D images currently supported")

    import nibabel as nib

    array_data = image.numpy()
    affine = np.hstack(
        [
            np.matmul(image.direction, np.diag(image.spacing)),
            np.array(image.origin).reshape(3, 1),
        ]
    )
    affine = np.vstack([affine, np.array([0, 0, 0, 1.0])])
    affine[:2, :] *= -1
    new_img = nib.Nifti1Image(array_data, affine)
    return new_img

After Change


    import nibabel as nib
    tmpfile = mktemp(suffix=".nii.gz")
    image.to_filename(tmpfile)
    new_img = nib.load(tmpfile)
    // os.remove(tmpfile) //// Don"t remove tmpfile as nibabel lazy loads the data.
    return new_img

Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 6

Instances


Project Name: ANTsX/ANTsPy
Commit Name: 2923434b29a910232dfd6c3f5b5639216900592a
Time: 2019-07-16
Author: d.gomez@posteo.org
File Name: ants/utils/convert_nibabel.py
Class Name:
Method Name: to_nibabel


Project Name: analysiscenter/batchflow
Commit Name: 98d1d7a0ad751fd91e6ec9c8ec6668bdea877cd1
Time: 2017-06-14
Author: rhudor@gmail.com
File Name: dataset/batch_image.py
Class Name: ImagesBatch
Method Name: load


Project Name: vatlab/SoS
Commit Name: b3192bf244120efa901cc9c46fe36fb6fb501803
Time: 2016-11-19
Author: ben.bog@gmail.com
File Name: sos/__main__.py
Class Name:
Method Name: cmd_run