1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""This example shows how to create a temporary image to use during processing.
The array is filled with zeros.
"""
import numpy as np
from nipy.core.api import fromarray, save_image
# create an array of zeros, the shape of your data array
zero_array = np.zeros((91,109,91))
# create an image from our array
img = fromarray(zero_array)
# save the image to a file
newimg = save_image(img, 'tempimage.nii.gz')
# Example of creating a temporary image file from an existing image
# with a matching comap.
# from nipy.core.api import load_image
# img = load_image('foo.nii.gz')
# zeroarray = np.zeros(img.comap.shape)
# zeroimg = fromarray(zeroarray, comap=img.comap)
# newimg = save_image(zeroimg, 'tempimage.nii.gz')
|