Exemple #1
0
    def run(self):
        '''
        '''
        #pdb.set_trace()
        # define polarity based on the warp requested
        self.polarity = 1.
        if self.warp:
            self.polarity = -1.

        # Evaluate spherical harmonics on a smaller grid
        dv, g_xyz2rcs = self.eval_spharm_grid(self.vendor, self.coeffs)

        # transform RAS-coordinates into LAI-coordinates
        m_ras2lai = np.array([[-1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0],
                              [0.0, 0.0, -1.0, 0.0], [0.0, 0.0, 0.0, 1.0]],
                             dtype=np.float)
        m_rcs2lai = np.dot(m_ras2lai, self.m_rcs2ras)
        m_rcs2lai_nohalf = m_rcs2lai[:, :]

        # indices of image volume
        '''
        nr, nc, ns = self.vol.shape[:3]
        vc3, vr3, vs3 = utils.meshgrid(np.arange(nr), np.arange(nc), np.arange(ns), dtype=np.float32)
        vrcs = CV(x=vr3, y=vc3, z=vs3)
        vxyz = utils.transform_coordinates(vrcs, m_rcs2lai)
        '''

        # account for half-voxel shift in R and C directions
        halfvox = np.zeros((4, 4))
        halfvox[0, 3] = m_rcs2lai[0, 0] / 2.0
        halfvox[1, 3] = m_rcs2lai[1, 1] / 2.0
        #m_rcs2lai = m_rcs2lai + halfvox

        # extract rotational and scaling parts of the transformation matrix
        # ignore the translation part
        r_rcs2lai = np.eye(4, 4)
        r_rcs2lai[:3, :3] = m_rcs2lai[:3, :3]

        # Jon Polimeni:
        # Since partial derivatives in Jacobian Matrix are differences
        # that depend on the ordering of the elements of the 3D array, the
        # coordinates may increase in the opposite direction from the array
        # indices, in which case the differential element should be negative.
        # The differentials can be determined by mapping a vector of 1s
        # through rotation and scaling, where any mirror
        # will impose a negation
        ones = CV(1., 1., 1.)
        dxyz = utils.transform_coordinates_old(ones, r_rcs2lai)

        # do the nonlinear unwarp
        if self.vendor == 'siemens':
            self.out, self.vjacout = self.non_linear_unwarp_siemens(
                self.vol.shape, dv, dxyz, m_rcs2lai, m_rcs2lai_nohalf,
                g_xyz2rcs)
    def run(self):
        '''
        '''
        #pdb.set_trace()
        # define polarity based on the warp requested
        self.polarity = 1.
        if self.warp:
            self.polarity = -1.

        # Evaluate spherical harmonics on a smaller grid 
        dv, g_xyz2rcs = self.eval_spharm_grid(self.vendor, self.coeffs)

        # transform RAS-coordinates into LAI-coordinates
        m_ras2lai = np.array([[-1.0, 0.0, 0.0, 0.0],
                             [0.0, 1.0, 0.0, 0.0],
                             [0.0, 0.0, -1.0, 0.0],
                             [0.0, 0.0, 0.0, 1.0]], dtype=np.float)
        m_rcs2lai = np.dot(m_ras2lai, self.m_rcs2ras)
        m_rcs2lai_nohalf = m_rcs2lai[:, :]

        # indices of image volume
        '''
        nr, nc, ns = self.vol.shape[:3]
        vc3, vr3, vs3 = utils.meshgrid(np.arange(nr), np.arange(nc), np.arange(ns), dtype=np.float32)
        vrcs = CV(x=vr3, y=vc3, z=vs3)
        vxyz = utils.transform_coordinates(vrcs, m_rcs2lai)
        '''

        # account for half-voxel shift in R and C directions
        halfvox = np.zeros((4, 4))
        halfvox[0, 3] = m_rcs2lai[0, 0] / 2.0
        halfvox[1, 3] = m_rcs2lai[1, 1] / 2.0
        #m_rcs2lai = m_rcs2lai + halfvox

        # extract rotational and scaling parts of the transformation matrix
        # ignore the translation part
        r_rcs2lai = np.eye(4, 4)
        r_rcs2lai[:3, :3] = m_rcs2lai[:3, :3]

        # Jon Polimeni:
        # Since partial derivatives in Jacobian Matrix are differences
        # that depend on the ordering of the elements of the 3D array, the
        # coordinates may increase in the opposite direction from the array
        # indices, in which case the differential element should be negative.
        # The differentials can be determined by mapping a vector of 1s
        # through rotation and scaling, where any mirror
        # will impose a negation
        ones = CV(1., 1., 1.)
        dxyz = utils.transform_coordinates_old(ones, r_rcs2lai)

        # do the nonlinear unwarp
        if self.vendor == 'siemens':
            self.out, self.vjacout = self.non_linear_unwarp_siemens(self.vol.shape, dv, dxyz,
                                                                 m_rcs2lai, m_rcs2lai_nohalf, g_xyz2rcs)
    def run(self):
        '''
        '''
        #pdb.set_trace()
        # define polarity based on the warp requested
        self.polarity = 1.
        if self.warp:
            self.polarity = -1.

        # transform RAS-coordinates into LAI-coordinates
        m_ras2lai = np.array([[-1.0, 0.0, 0.0, 0.0],
                             [0.0, 1.0, 0.0, 0.0],
                             [0.0, 0.0, -1.0, 0.0],
                             [0.0, 0.0, 0.0, 1.0]], dtype=np.float)
        m_rcs2lai = np.dot(m_ras2lai, self.m_rcs2ras)

        # indices of image volume
        nr, nc, ns = self.vol.shape[:3]
        vc3, vr3, vs3 = utils.meshgrid(np.arange(nr), np.arange(nc), np.arange(ns), dtype=np.float32)
        vrcs = CV(x=vr3, y=vc3, z=vs3)
        vxyz = utils.transform_coordinates(vrcs, m_rcs2lai)

        # account for half-voxel shift in R and C directions
        halfvox = np.zeros((4, 4))
        halfvox[0, 3] = m_rcs2lai[0, 0] / 2.0
        halfvox[1, 3] = m_rcs2lai[1, 1] / 2.0
        m_rcs2lai = m_rcs2lai + halfvox

        # extract rotational and scaling parts of the transformation matrix
        # ignore the translation part
        r_rcs2lai = np.eye(4, 4)
        r_rcs2lai[:3, :3] = m_rcs2lai[:3, :3]

        # Jon Polimeni:
        # Since partial derivatives in Jacobian Matrix are differences
        # that depend on the ordering of the elements of the 3D array, the
        # coordinates may increase in the opposite direction from the array
        # indices, in which case the differential element should be negative.
        # The differentials can be determined by mapping a vector of 1s
        # through rotation and scaling, where any mirror
        # will impose a negation
        ones = CV(1., 1., 1.)
        dxyz = utils.transform_coordinates_old(ones, r_rcs2lai)

        # # convert image vol coordinates from RAS to LAI
        # vxyz = utils.transform_coordinates(vrcs, m_rcs2lai)

        # # compute new coordinates and the jacobian determinant
        # # TODO still not clear about what to return
        # self.out, self.vjacmult_lps = self.non_linear_unwarp(vxyz, dxyz,
        #                                                     m_rcs2lai)


        # for each slice
        '''
        for slice in xrange(ns):
            sys.stdout.flush()
            if (slice + 1) % 10 == 0:
                print(slice + 1),
            else:
                print('.'),

            # we are doing it slice by slice
            vs = np.ones(vr.shape) * slice

            vrcs2d = CV(vr, vc, slice)
            # rcs2lai
            vxyz2d = utils.transform_coordinates(vrcs2d, m_rcs2lai)

            # compute new coordinates and the jacobian determinant
            moddv, modxyz = eval_spherical_harmonics(self.coeffs, self.vendor, vxyz2d)
            dvx[..., slice] = moddv.x
            dvy[..., slice] = moddv.y
            dvz[..., slice] = moddv.z
            '''

        print
        # Evaluate spherical harmonics on a smaller grid 
        dv, grcs, g_xyz2rcs = self.eval_spharm_grid(self.vendor, self.coeffs)
        # do the nonlinear unwarp
        self.out, self.vjacmult_lps = self.non_linear_unwarp(vxyz, grcs, dv, dxyz,
                                                                 m_rcs2lai, g_xyz2rcs)