Пример #1
0
    def setUp(self):
        # Timing
        self.start_time = time.time()

        # DATA
        self.d = ctdata.sets[14]
        self.d.load()

        # Parameters
        det_row_count, num_proj, det_col_count = self.d.shape
        num_voxel = (det_col_count, det_col_count, det_row_count)
        # voxel_size = 1
        voxel_size = 2 * self.d.roi_cubic_width_mm / num_voxel[0]
        source_origin = self.d.distance_source_origin_mm / voxel_size
        origin_detector = self.d.distance_origin_detector_mm / voxel_size
        angles = self.d.angles_rad
        det_col_spacing = self.d.detector_width_mm / det_col_count / voxel_size
        det_row_spacing = det_col_spacing

        # PROJECTOR
        self.projector = Projector(
            num_voxel=num_voxel,
            det_row_count=det_row_count, det_col_count=det_col_count,
            source_origin=source_origin, origin_detector=origin_detector,
            det_row_spacing=det_row_spacing, det_col_spacing=det_col_spacing,
            angles=angles)

        # ALGORITHM
        self.cgm = ChanGolubMullet(projections=self.d.projections,
                                   projector=self.projector)

        self.u_shape = num_voxel
Пример #2
0
class ChanGolubMulletTestCase(unittest.TestCase):

    def setUp(self):
        # Timing
        self.start_time = time.time()

        # DATA
        self.d = ctdata.sets[14]
        self.d.load()

        # Parameters
        det_row_count, num_proj, det_col_count = self.d.shape
        num_voxel = (det_col_count, det_col_count, det_row_count)
        # voxel_size = 1
        voxel_size = 2 * self.d.roi_cubic_width_mm / num_voxel[0]
        source_origin = self.d.distance_source_origin_mm / voxel_size
        origin_detector = self.d.distance_origin_detector_mm / voxel_size
        angles = self.d.angles_rad
        det_col_spacing = self.d.detector_width_mm / det_col_count / voxel_size
        det_row_spacing = det_col_spacing

        # PROJECTOR
        self.projector = Projector(
            num_voxel=num_voxel,
            det_row_count=det_row_count, det_col_count=det_col_count,
            source_origin=source_origin, origin_detector=origin_detector,
            det_row_spacing=det_row_spacing, det_col_spacing=det_col_spacing,
            angles=angles)

        # ALGORITHM
        self.cgm = ChanGolubMullet(projections=self.d.projections,
                                   projector=self.projector)

        self.u_shape = num_voxel

    def tearDown(self):
        # Timing
        t = time.time() - self.start_time
        print "%s: %.3f" % (self.id(), t)
        # Clear ASTRA memory
        self.projector.clear()

    def test_initialization(self):
        self.assertTrue(issubclass(type(self.cgm), object))

    def test_g(self):
        g = self.cgm.g
        u_shape = self.cgm.K.volume_shape
        self.assertEqual(g.__class__.__name__, 'ndarray')
        self.assertEqual(np.shape(g), tuple((x - 0 for x in u_shape)))

    def test_f(self):
        f = self.cgm.f
        fl = list(f)
        # ft = tuple(f)
        self.assertEqual(len(fl), len(self.d.shape))
        # self.assertEqual(type(f), list)

    def test_func_du(self):
        func_du = self.cgm.func_du(np.zeros(self.u_shape))
        self.assertEqual(func_du.shape, self.u_shape)
        self.assertTrue(func_du.any() == 0)