def readXYZ(self): # Create coordinate space based on x,y,z dimensions, and multiply by affine matrix # Examples shown if xdim = 3, ydim=4, zdim=5 # Create R row variable [1 2 3 1 2 3...] ydim * zdim times Rrow = list(scinu.seq(1,self.xdim)) * (self.ydim*self.zdim) # Create C row variable [1 1 1 2 2 2 3 3 3 4 4 4 1 1 1 2 2 2...] zdim X Crow = [] for y in range(1,self.ydim+1): for x in range(0,self.xdim): Crow.append(y) Crow = Crow * self.zdim # Create P row variable [ each of 1:zdim xdim*ydim times ] Prow = [] for z in range(1,self.zdim+1): holder = ([z] * self.xdim*self.ydim) for i in holder: Prow.append(i) # Create row of 1s of length zdim*xdim*ydim so we can multiply matrices onedim = [1] * self.xdim * self.ydim * self.zdim # Stack each row on top of one another self.RCP = np.vstack((Rrow,Crow,Prow,onedim)) # Make it into a matrix self.RCP = scinu.mat(self.RCP) # Grab the first three rows of the affine transformation matrix (4th is for time) affXYZ = self.aff[0:3] # Multiply affine transformation matrix by coordinate data to go from coordinate --> MNI space self.XYZ = affXYZ * self.RCP
def readXYZ(self): # I couldn't get this method to work, but will keep to try again... # R, C, P = scinu.ndgrid(scinu.seq(1,3),scinu.seq(1,4),scinu.seq(1,5)) # Create coordinate space based on x,y,z dimensions, and multiply by affine matrix # Examples shown if xdim = 3, ydim=4, zdim=5 # Create R row variable [1 2 3 1 2 3...] ydim * zdim times Rrow = list(scinu.seq(1, self.xdim)) * (self.ydim * self.zdim) # Create C row variable [1 1 1 2 2 2 3 3 3 4 4 4 1 1 1 2 2 2...] zdim X Crow = [] for y in range(1, self.ydim + 1): for x in range(0, self.xdim): Crow.append(y) Crow = Crow * self.zdim # Create P row variable [ each of 1:zdim xdim*ydim times ] Prow = [] for z in range(1, self.zdim + 1): holder = ([z] * self.xdim * self.ydim) for i in holder: Prow.append(i) # Create row of 1s of length zdim*xdim*ydim so we can multiply matrices onedim = [1] * self.xdim * self.ydim * self.zdim # Stack each row on top of one another self.RCP = np.vstack((Rrow, Crow, Prow, onedim)) # Make it into a matrix self.RCP = scinu.mat(self.RCP) # Grab the first three rows of the affine transformation matrix (4th is for time) affXYZ = self.aff[0:3] # Multiply affine transformation matrix by coordinate data to go from coordinate --> MNI space self.XYZ = affXYZ * self.RCP
def readAff(self): self.aff = scinu.mat(self.img.get_affine())