#Load in segmentation header seg = nagini.loadHeader(args.seg[0]) #Make sure its dimensions match if pet.shape[0:3] != seg.shape[0:3]: print 'ERROR: Segmentation dimensions do not match data. Please check...' sys.exit() #Load in segmentation data' segData = seg.get_data().reshape(pet.shape[0:3]) #Make a new segmentation where we have high CBV segData[cbvData >= 8.0] = np.max(segData) + 1 #Get CBV ROI averages cbvAvgs = nagini.roiAvg(cbvData.flatten(), segData.flatten(), min=0.0) #Remask CBV image from ROI averages cbvData = nagini.roiBack(cbvAvgs, segData.flatten()).reshape(cbvData.shape) #Smooth if args.fwhmSeg is not None: voxSize = pet.header.get_zooms() sigmas = np.divide(args.fwhmSeg[0] / np.sqrt(8.0 * np.log(2.0)), voxSize[0:3]) cbvData = filt.gaussian_filter(cbvData, sigmas).reshape(cbvData.shape) cbvData[segData == 0] = 0.0 #Get mask where inputs are non_zero maskData = np.where( np.logical_and(
#Load in segmentation header seg = nagini.loadHeader(args.seg[0]) #Make sure its dimensions match if pet.shape[0:3] != seg.shape[0:3]: print 'ERROR: Segmentation dimensions do not match data. Please check...' sys.exit() #Load in segmentation data' segData = seg.get_data() #Make a new segmentation where we have high CBV segData[cbvData>=8.0] = np.max(segData)+1 #Get CBV ROI averages cbvAvgs = nagini.roiAvg(cbvData.flatten(),segData.flatten(),min=0.0) #Remask CBV image from ROI averages cbvData = nagini.roiBack(cbvAvgs,segData.flatten()).reshape(cbvData.shape) #Smooth if args.fwhmSeg is not None: voxSize = pet.header.get_zooms() sigmas = np.divide(args.fwhmSeg[0]/np.sqrt(8.0*np.log(2.0)),voxSize[0:3]) cbvData = filt.gaussian_filter(cbvData,sigmas).reshape(cbvData.shape) cbvData[segData==0] = 0.0 #Get mask where inputs are non_zero maskData = np.where(np.logical_and(np.logical_and(brainData!=0,cbfData!=0),cbvData!=0),1,0) #Flatten the PET images and then mask
print 'ERROR: Images do not have same dimensions. Exiting...' sys.exit() #Load image data imgData = img.get_data() roiData = roi.get_data() #Reshape image data as necessary if len(imgData.shape) == 4: imgData = nagini.reshape4d(imgData) else: imgData = imgData.reshape((img.shape[0]*img.shape[1]*img.shape[2],1)) roiData = roiData.flatten() #Sample into ROIs avgData = nagini.roiAvg(imgData,roiData,stat=args.stat) #Save roi averages in the format user wants. if args.nii == 1: avg = nib.Nifti1Image(avgData.reshape((avgData.shape[0],1,1,avgData.shape[1])),np.identity(4)) avg.to_filename('%s_roi_%s.nii.gz'%(args.out[0],args.stat)) else: nagini.writeText('%s_roi_%s.txt'%(args.out[0],args.stat),avgData)
#Check to make sure dimensions match if pet.shape[0:3] != brain.shape[0:3] or pet.shape[3] != info.shape[0] or brain.shape[0:3] != roi.shape[0:3]: print 'ERROR: Data dimensions do not match. Please check...' sys.exit() #Get the image data petData = pet.get_data() brainData = brain.get_data() roiData = roi.get_data() #Flatten the PET images and then mask petFlat = nagini.reshape4d(petData) petMasked = petFlat[brainData.flatten()>0,:] #Get pet into rois petRoi = nagini.roiAvg(petFlat,roiData.flatten()) #If cbv image is given, load it up if args.cbv is not None: #Load in CBV image cbv = nagini.loadHeader(args.cbv[0]) if cbv.shape[0:3] != pet.shape[0:3]: print 'ERROR: CBV image does not match PET resolution...' sys.exit() cbvData = cbv.get_data() #Get whole brian mean cbv wbCbv = np.mean(cbvData.flatten()[brainData.flatten()>0] / 100 * args.d) #Get CBV roi
img = nagini.loadHeader(args.img[0]) roi = nagini.loadHeader(args.roi[0]) #Check to make sure images have same dimensions if img.shape[0:3] != roi.shape[0:3]: print 'ERROR: Images do not have same dimensions. Exiting...' sys.exit() #Load image data imgData = img.get_data() roiData = roi.get_data() #Reshape image data as necessary if len(imgData.shape) == 4: imgData = nagini.reshape4d(imgData) else: imgData = imgData.reshape((img.shape[0] * img.shape[1] * img.shape[2], 1)) roiData = roiData.flatten() #Sample into ROIs avgData = nagini.roiAvg(imgData, roiData, stat=args.stat) #Save roi averages in the format user wants. if args.nii == 1: avg = nib.Nifti1Image( avgData.reshape((avgData.shape[0], 1, 1, avgData.shape[1])), np.identity(4)) avg.to_filename('%s_roi_%s.nii.gz' % (args.out[0], args.stat)) else: nagini.writeText('%s_roi_%s.txt' % (args.out[0], args.stat), avgData)