コード例 #1
0
ファイル: demo_blob_from_image.py プロジェクト: ofenlab/nipy
    mkdir(write_dir)

# parameters
threshold = 3.0 # blob-forming threshold
smin = 5 # size threshold on blobs

# prepare the data
nim = load(input_image)
mask_image = Nifti1Image((nim.get_data() ** 2 > 0).astype('u8'),
                         nim.get_affine())
domain = grid_domain_from_image(mask_image)
data = nim.get_data()
values = data[data != 0]

# compute the  nested roi object
nroi = hroi.HROI_as_discrete_domain_blobs(domain, values, threshold=threshold,
                                          smin=smin)

# compute region-level activation averages
activation = [values[nroi.select_id(id, roi=False)] for id in nroi.get_id()]
nroi.set_feature('activation', activation)
average_activation = nroi.representative_feature('activation')

# saving the blob image,i. e. a label image
descrip = "blob image extracted from %s" % input_image
wim = nroi.to_image('id', roi=True, descrip=descrip)
save(wim, path.join(write_dir, "blob.nii"))

# saving the image of the average-signal-per-blob
descrip = "blob average signal extracted from %s" % input_image
wim = nroi.to_image('activation', roi=True, descrip=descrip)
save(wim, path.join(write_dir, "bmap.nii"))
コード例 #2
0
ファイル: hierarchical_rois.py プロジェクト: zddzxxsmile/nipy
import nipy.labs.utils.simul_multisubject_fmri_dataset as simul
from nipy.labs.spatial_models.discrete_domain import domain_from_binary_array

##############################################################################
# simulate the data
shape = (60, 60)
pos = np.array([[12, 14], [20, 20], [30, 20]])
ampli = np.array([3, 4, 4])

dataset = simul.surrogate_2d_dataset(n_subj=1, shape=shape, pos=pos,
                                     ampli=ampli, width=10.0).squeeze()

# create a domain descriptor associated with this
domain = domain_from_binary_array(dataset ** 2 > 0)

nroi = hroi.HROI_as_discrete_domain_blobs(domain, dataset.ravel(),
                                          threshold=2., smin=5)

n1 = nroi.copy()
nroi.reduce_to_leaves()

td = n1.make_forest().depth_from_leaves()
root = np.argmax(td)
lv = n1.make_forest().get_descendants(root)
u = nroi.make_graph().cc()

flat_data = dataset.ravel()
activation = [flat_data[nroi.select_id(id, roi=False)]
              for id in nroi.get_id()]
nroi.set_feature('activation', activation)

label = np.reshape(n1.label, shape)