Beispiel #1
0
    def decimate(self, dec):
        '''nim is the mri data in python format
        dec is the decimation factor'''

        #nim = self.nifti
        header = self.nifti.get_header()
        self.filename = self.nifti.get_filename()
        xend = self.nifti.get_shape()[0]
        yend = self.nifti.get_shape()[1]
        zend = self.nifti.get_shape()[2]

        if type(dec) != float and type(dec) != int:
            print 'nonuniform decimation'
            xstartval=ceil(dec[0]/2);
            print xstartval,
            ystartval=ceil(dec[1]/2);
            zstartval=ceil(dec[2]/2);
            decimg=array(self.data[xstartval::dec[0],:,:][:,ystartval::dec[1],:][:,:,zstartval::dec[2]])
            nonz = where(decimg > 0)
            x = ((nonz[0])*dec[0])+(dec[0])
            y = ((nonz[1])*dec[1])+(dec[1])
            z = ((nonz[2])*dec[2])+(dec[2])

        else:
            print 'uniform decimation'
            startval=ceil(dec/2);
            decimg=array(self.data[startval::dec,:,:][:,startval::dec,:][:,:,startval::dec])
            nonz = where(decimg > 0)
            x = ((nonz[0]+1)*dec)#-(dec)
            y = ((nonz[1]+1)*dec)#-(dec)
            z = ((nonz[2]+1)*dec)#-(dec)


        #--20090702--danc--not sure about reordering
        #mrixyz = array([x,y,z])
        #--20090702--danc--adding voxel scaling. this had to be a huge bug, so why i haven't noticed it so far???
        #                   The effect would be non existant on isotropic volumes, so thats probably why.

        voxdim = header['pixdim'][1:4]#.voxdim[::-1] #flipped voxel dims
        print voxdim
        #print 'WARNING: assuming voxdim reverse of img.voxdim. Could be wrong'
        mrixyz = (array([x,y,z]).T*voxdim).T

        self.mrixyz = mrixyz
        self.img = decimg
        self.factor = dec
        self.ind = array(nonz)

        try:

            [t,r] = transform.meg2mri(self.lpa,self.rpa,self.nas)
            self.megxyz = transform.mri2meg(t,r,self.mrixyz)
        except AttributeError:
            print 'Transform Error, skipping'