Step 1: Change path and import necessary packages


In [5]:
import os
PATH="/Users/albertlee/NeuroCV/PCV/2Dhisteq/3D" # use your own path
os.chdir(PATH)

################

import matplotlib.pyplot as plt
import csv,gc
import matplotlib
import numpy as np
import nibabel as nb

Step 2: Setup Data


In [3]:
BINS=32 # histogram bins
RANGE=(10.0,300.0)

im = nb.load('Fear197.nii')
im = im.get_data()
img = im[:,:,:,0]

Step 3: Basic Exploratory Analysis


In [11]:
print img.shape

## print img.res -> memmap has no attribute 'res'
## print img.numbins -> memmap has no attribute 'numbins'


(896, 576, 1087)

XDimension = 896 YDimension = 576 ZDimension = 1087


In [ ]:
for z in range(1087):
    for y in range(576):
        for x in range(896):
        
            data = img
            
            # compute the histogram and store it
            (hist, bins) = np.histogram(data[data > 0], BINS, range=(0,BINS))
            hist_sum = np.add(hist_sum, hist)
            print "Processed cube {} {} {}".format(x,y,z)

In [ ]: