def test_equal(self):
        AG = AcquisitionGeometry.create_Parallel3D()
        AG.set_channels(4, ['a','b','c','d'])
        AG.set_panel([2,3])
        AG.set_angles([0,1,2,3,5])
        AG.set_labels(('horizontal','angle','vertical','channel'))

        AG2 = AcquisitionGeometry.create_Parallel3D()
        AG2.set_channels(4, ['a','b','c','d'])
        AG2.set_panel([2,3])
        AG2.set_angles([0,1,2,3,5])
        AG2.set_labels(('horizontal','angle','vertical','channel'))
        self.assertTrue(AG == AG2)

        #test not equal
        AG3 = AG2.copy()
        AG3.config.system.ray.direction = [1,0,0]
        self.assertFalse(AG == AG3)

        AG3 = AG2.copy()
        AG3.config.panel.num_pixels = [1,2]
        self.assertFalse(AG == AG3)

        AG3 = AG2.copy()
        AG3.config.channels.channel_labels = ['d','b','c','d']
        self.assertFalse(AG == AG3)

        AG3 = AG2.copy()
        AG3.config.angles.angle_unit ='radian'
        self.assertFalse(AG == AG3)

        AG3 = AG2.copy()
        AG3.config.angles.angle_data[0] = -1
        self.assertFalse(AG == AG3)
    def test_get_centre_slice(self):
        #returns the 2D version
        AG = AcquisitionGeometry.create_Parallel3D()
        AG2 = AcquisitionGeometry.create_Parallel2D()
        cs = AG.config.system.get_centre_slice()
        self.assertEqual(cs, AG2.config.system)

        #returns the 2D version
        AG = AcquisitionGeometry.create_Parallel3D(
            rotation_axis_direction=[-1, 0, 1],
            detector_direction_x=[1, 0, 1],
            detector_direction_y=[-1, 0, 1])
        AG2 = AcquisitionGeometry.create_Parallel2D()
        cs = AG.config.system.get_centre_slice()
        self.assertEqual(cs, AG2.config.system)

        #raise error if cannot extract a cnetre slice
        AG = AcquisitionGeometry.create_Parallel3D(ray_direction=[0, 1, 1])
        with self.assertRaises(ValueError):
            cs = AG.config.system.get_centre_slice()

        AG = AcquisitionGeometry.create_Parallel3D(
            detector_direction_x=[1, 0, 1], detector_direction_y=[-1, 0, 1])
        with self.assertRaises(ValueError):
            cs = AG.config.system.get_centre_slice()
    def test_system_description(self):
        AG = AcquisitionGeometry.create_Parallel3D()
        self.assertTrue(AG.system_description == 'simple')

        AG = AcquisitionGeometry.create_Parallel3D(
            detector_position=[5, 0, 0], rotation_axis_position=[5, 0, 0])
        self.assertTrue(AG.system_description == 'simple')

        AG = AcquisitionGeometry.create_Parallel3D(
            rotation_axis_position=[5, 0, 0])
        self.assertTrue(AG.system_description == 'offset')

        AG = AcquisitionGeometry.create_Parallel3D(ray_direction=[1, 1, 0])
        self.assertTrue(AG.system_description == 'advanced')
Esempio n. 4
0
    def setUp(self):
        #%% Setup Geometry
        voxel_num_xy = 16
        voxel_num_z = 4

        pix_size = 0.2
        det_pix_x = voxel_num_xy
        det_pix_y = voxel_num_z

        num_projections = 36
        angles = np.linspace(0, 360, num=num_projections, endpoint=False)

        self.ag = AcquisitionGeometry.create_Parallel2D()\
                                           .set_angles(angles)\
                                           .set_panel(det_pix_x, pix_size)\
                                           .set_labels(['angle','horizontal'])

        self.ig = self.ag.get_ImageGeometry()

        self.ag3D = AcquisitionGeometry.create_Parallel3D()\
                                     .set_angles(angles)\
                                     .set_panel((det_pix_x,det_pix_y), (pix_size,pix_size))\
                                     .set_labels(['angle','vertical','horizontal'])
        self.ig3D = self.ag3D.get_ImageGeometry()

        self.ad3D = self.ag3D.allocate('random')
        self.ig3D = self.ag3D.get_ImageGeometry()
Esempio n. 5
0
    def test_fill_dimension_AcquisitionData(self):
        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_channels(4)
        ag.set_panel([2,3])
        ag.set_angles([0,1,2,3,5])
        ag.set_labels(('horizontal','angle','vertical','channel'))
        u = ag.allocate(0)
        a = numpy.ones((4,2))
        # default_labels = [ImageGeometry.VERTICAL, ImageGeometry.HORIZONTAL_Y, ImageGeometry.HORIZONTAL_X]
        
        data = u.as_array()
        axis_number = u.get_dimension_axis('horizontal_y')
        
        u.fill(a, horizontal_y=0)
        numpy.testing.assert_array_equal(u.subset(horizontal_y=0).as_array(), a)

        u.fill(2, horizontal_y=1)
        numpy.testing.assert_array_equal(u.subset(horizontal_y=0).as_array(), 2 * a)

        u.fill(2, horizontal_y=1)
        numpy.testing.assert_array_equal(u.subset(horizontal_y=1).as_array(), 2 * a)
        
        b = u.subset(horizontal_y=2)
        b.fill(3)
        u.fill(b, horizontal_y=2)
        numpy.testing.assert_array_equal(u.subset(horizontal_y=2).as_array(), 3 * a)

        # slice with 2 axis
        a = numpy.ones((2,))
        u.fill(a, horizontal_y=1, vertical=0)
        numpy.testing.assert_array_equal(u.subset(horizontal_y=1, vertical=0).as_array(), a)
Esempio n. 6
0
    def test_parallel3D_offset(self):

        ag = AcquisitionGeometry.create_Parallel3D(detector_position=[2,0,0], rotation_axis_position=[3,0, 0])\
                                      .set_angles(self.angles_deg, angle_unit='degree')\
                                      .set_labels(['vertical', 'angle','horizontal'])\
                                      .set_panel((self.num_pixels_x,self.num_pixels_y), (self.pixel_size_x,self.pixel_size_y))

        self.assertTrue(ag.system_description == 'offset')

        tg_geometry, tg_angles = CIL2TIGREGeometry.getTIGREGeometry(
            self.ig, ag)

        det_offset = np.array([0, -1, 0])
        np.testing.assert_allclose(tg_geometry.offDetector, det_offset)

        for i, ang in enumerate(tg_angles):
            ang2 = -(self.angles_rad[i] + np.pi / 2)
            self.compare_angles(ang, ang2, 1e-6)

        self.assertTrue(tg_geometry.mode == 'parallel')
        np.testing.assert_allclose(tg_geometry.dDetector,
                                   ag.config.panel.pixel_size[::-1])
        np.testing.assert_allclose(tg_geometry.nDetector,
                                   ag.config.panel.num_pixels[::-1])
        np.testing.assert_allclose(
            tg_geometry.sDetector,
            tg_geometry.dDetector * tg_geometry.nDetector)
        np.testing.assert_allclose(tg_geometry.offOrigin, 0)

        np.testing.assert_allclose(
            tg_geometry.nVoxel,
            [self.ig.voxel_num_z, self.ig.voxel_num_y, self.ig.voxel_num_x])
        np.testing.assert_allclose(
            tg_geometry.dVoxel,
            [self.ig.voxel_size_z, self.ig.voxel_size_y, self.ig.voxel_size_x])
Esempio n. 7
0
    def test_fill_dimension_AcquisitionData(self):
        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_channels(4)
        ag.set_panel([2,3])
        ag.set_angles([0,1,2,3,5])
        ag.set_labels(('horizontal','angle','vertical','channel'))
        u = ag.allocate(0)
        print (u.shape)
        # (2, 5, 3, 4)
        a = numpy.ones((2,5))
        # default_labels = [ImageGeometry.VERTICAL, ImageGeometry.HORIZONTAL_Y, ImageGeometry.HORIZONTAL_X]
        b = u.subset(channel=0, vertical=0)
        print(b.shape)
        data = u.as_array()
        
        u.fill(a, channel=0, vertical=0)
        print(u.shape)
        numpy.testing.assert_array_equal(u.subset(channel=0, vertical=0).as_array(), a)

        u.fill(2, channel=0, vertical=0)
        numpy.testing.assert_array_equal(u.subset(channel=0, vertical=0).as_array(), 2 * a)

        u.fill(2, channel=0, vertical=0)
        numpy.testing.assert_array_equal(u.subset(channel=0, vertical=0).as_array(), 2 * a)
        
        b = u.subset(channel=0, vertical=0)
        b.fill(3)
        u.fill(b, channel=1, vertical=1)
        numpy.testing.assert_array_equal(u.subset(channel=1, vertical=1).as_array(), 3 * a)
Esempio n. 8
0
    def test_AcquisitionData(self):
        ag = AcquisitionGeometry.create_Parallel3D().set_panel(
            [5, 4]).set_angles([0, 1, 2]).set_channels(2).set_labels(
                ['channel', 'angle', 'vertical', 'horizontal'])
        data = ag.allocate(None)
        data_new = data.get_slice(angle=2)
        self.assertEquals(data_new.shape, (2, 4, 5))
        self.assertEquals(data_new.geometry.dimension_labels,
                          ('channel', 'vertical', 'horizontal'))

        #won't return a geometry for un-reconstructable slice
        ag = AcquisitionGeometry.create_Cone3D(
            [0, -200, 0], [0, 200, 0]).set_panel([5, 4]).set_angles(
                [0, 1, 2]).set_channels(2).set_labels(
                    ['channel', 'angle', 'vertical', 'horizontal'])
        data = ag.allocate('random')
        data_new = data.get_slice(vertical=1, force=True)
        self.assertEquals(data_new.shape, (2, 3, 5))
        self.assertTrue(isinstance(data_new, (DataContainer)))
        self.assertIsNone(data_new.geometry)
        self.assertEquals(data_new.dimension_labels,
                          ('channel', 'angle', 'horizontal'))

        #if 'centre' is between pixels interpolates
        data_new = data.get_slice(vertical='centre')
        self.assertEquals(data_new.shape, (2, 3, 5))
        self.assertEquals(data_new.geometry.dimension_labels,
                          ('channel', 'angle', 'horizontal'))
        numpy.testing.assert_allclose(
            data_new.array,
            (data.array[:, :, 1, :] + data.array[:, :, 2, :]) / 2)
    def setUp(self): 

        N = 128
        angles = np.linspace(0, np.pi, 180, dtype='float32')

        ag = AcquisitionGeometry.create_Parallel2D()\
                                .set_angles(angles, angle_unit='radian')\
                                .set_panel(N, 0.1)\
                                .set_labels(['angle', 'horizontal'])
        
        ig = ag.get_ImageGeometry()

        
        ag3 = AcquisitionGeometry.create_Parallel3D()\
                                .set_angles(angles, angle_unit='radian')\
                                .set_panel((N, N), (0.1, 0.1))\
                                .set_labels(['vertical', 'angle', 'horizontal'])

        ig3 = ag3.get_ImageGeometry()

        self.ig = ig
        self.ag = ag
        self.ig3 = ig3
        self.ag3 = ag3
        self.norm = 14.85
    def test_align_reference_frame_tigre(self):

        ag = AcquisitionGeometry.create_Parallel3D(
            ray_direction=[0, -1, 0],
            detector_position=[0., -100., 0],
            rotation_axis_position=[10., 5., 0],
            rotation_axis_direction=[0, 0, -1])
        ag.config.system.align_reference_frame('tigre')

        numpy.testing.assert_allclose(ag.config.system.ray.direction,
                                      [0, 1, 0],
                                      rtol=1E-6)
        numpy.testing.assert_allclose(ag.config.system.detector.position,
                                      [-10, 105, 0],
                                      rtol=1E-6)
        numpy.testing.assert_allclose(ag.config.system.detector.direction_x,
                                      [1, 0, 0],
                                      rtol=1E-6)
        numpy.testing.assert_allclose(ag.config.system.detector.direction_y,
                                      [0, 0, -1],
                                      rtol=1E-6)
        numpy.testing.assert_allclose(ag.config.system.rotation_axis.position,
                                      [0, 0, 0],
                                      rtol=1E-6)
        numpy.testing.assert_allclose(ag.config.system.rotation_axis.direction,
                                      [0, 0, 1],
                                      rtol=1E-6)
    def test_get_ImageGeometry(self):

        AG = AcquisitionGeometry.create_Parallel2D()\
            .set_panel(num_pixels=[512,1],pixel_size=[0.1,0.1])      
        IG = AG.get_ImageGeometry()
        IG_gold = ImageGeometry(512,512,0,0.1,0.1,1,0,0,0,1)
        self.assertEqual(IG, IG_gold)

        AG = AcquisitionGeometry.create_Parallel3D()\
            .set_panel(num_pixels=[512,3],pixel_size=[0.1,0.2])
        IG = AG.get_ImageGeometry()
        IG_gold = ImageGeometry(512,512,3,0.1,0.1,0.2,0,0,0,1)
        self.assertEqual(IG, IG_gold)

        AG = AcquisitionGeometry.create_Cone2D(source_position=[0,-500], detector_position=[0.,500.])\
            .set_panel(num_pixels=[512,1],pixel_size=[0.1,0.2])
        IG = AG.get_ImageGeometry()
        IG_gold = ImageGeometry(512,512,0,0.05,0.05,1,0,0,0,1)
        self.assertEqual(IG, IG_gold)

        AG = AcquisitionGeometry.create_Cone3D(source_position=[0,-500,0], detector_position=[0.,500.,0])\
            .set_panel(num_pixels=[512,3],pixel_size=[0.1,0.2])
        IG = AG.get_ImageGeometry()
        IG_gold = ImageGeometry(512,512,3,0.05,0.05,0.1,0,0,0,1)
        self.assertEqual(IG, IG_gold)

        AG = AcquisitionGeometry.create_Cone3D(source_position=[0,-500,0], detector_position=[0.,500.,0])\
            .set_panel(num_pixels=[512,3],pixel_size=[0.1,0.2])
        IG = AG.get_ImageGeometry(resolution=0.5)
        IG_gold = ImageGeometry(256,256,2,0.025,0.025,0.05,0,0,0,1)
        self.assertEqual(IG, IG_gold)
Esempio n. 12
0
    def test_filtering(self):
        ag = AcquisitionGeometry.create_Parallel3D()\
            .set_panel([64,3],[0.1,0.1])\
            .set_angles([0,90])

        ad = ag.allocate('random', seed=0)

        reconstructor = FBP(ad)
        out1 = ad.copy()
        reconstructor._pre_filtering(out1)

        #by hand
        filter = reconstructor.get_filter_array()
        reconstructor._calculate_weights(ag)
        pad0 = (len(filter) - ag.pixel_num_h) // 2
        pad1 = len(filter) - ag.pixel_num_h - pad0

        out2 = ad.array.copy()
        out2 *= reconstructor._weights
        for i in range(2):
            proj_padded = np.zeros((ag.pixel_num_v, len(filter)))
            proj_padded[:, pad0:-pad1] = out2[i]
            filtered_proj = fft(proj_padded, axis=-1)
            filtered_proj *= filter
            filtered_proj = ifft(filtered_proj, axis=-1)
            out2[i] = np.real(filtered_proj)[:, pad0:-pad1]

        diff = (out1 - out2).abs().max()
        self.assertLess(diff, 1e-5)
Esempio n. 13
0
    def test_parallel3D_simple(self):
        ag = AcquisitionGeometry.create_Parallel3D()\
                                      .set_angles(self.angles_deg, angle_unit='degree')\
                                      .set_labels(['vertical', 'angle','horizontal'])\
                                      .set_panel((self.num_pixels_x,self.num_pixels_y), (self.pixel_size_x,self.pixel_size_y))

        tg_geometry, tg_angles = CIL2TIGREGeometry.getTIGREGeometry(
            self.ig, ag)

        for i, ang in enumerate(tg_angles):
            ang2 = -(self.angles_rad[i] + np.pi / 2)
            self.compare_angles(ang, ang2, 1e-6)

        self.assertTrue(tg_geometry.mode == 'parallel')
        np.testing.assert_allclose(tg_geometry.dDetector,
                                   ag.config.panel.pixel_size[::-1])
        np.testing.assert_allclose(tg_geometry.nDetector,
                                   ag.config.panel.num_pixels[::-1])
        np.testing.assert_allclose(
            tg_geometry.sDetector,
            tg_geometry.dDetector * tg_geometry.nDetector)
        np.testing.assert_allclose(tg_geometry.rotDetector, 0)
        np.testing.assert_allclose(tg_geometry.offDetector, 0)
        np.testing.assert_allclose(tg_geometry.offOrigin, 0)

        np.testing.assert_allclose(
            tg_geometry.nVoxel,
            [self.ig.voxel_num_z, self.ig.voxel_num_y, self.ig.voxel_num_x])
        np.testing.assert_allclose(
            tg_geometry.dVoxel,
            [self.ig.voxel_size_z, self.ig.voxel_size_y, self.ig.voxel_size_x])
    def test_get_centre_slice(self):
        AG = AcquisitionGeometry.create_Parallel3D(detector_direction_y=[0,1,1])
        AG.set_panel([1000,2000],[1,1])
        AG_cs = AG.get_centre_slice()

        AG2 = AcquisitionGeometry.create_Parallel2D()
        AG2.set_panel([1000,1],[1,math.sqrt(0.5)])

        self.assertEqual(AG2, AG_cs)
    def test_copy(self):
        AG = AcquisitionGeometry.create_Parallel3D()
        AG.set_channels(4)
        AG.set_panel([2,3])
        AG.set_angles([0,1,2,3,5])
        AG.set_labels(('horizontal','angle','vertical','channel'))

        AG2 = AG.copy()
        self.assertEqual(AG2, AG)
Esempio n. 16
0
 def test_AcquisitionData(self):
     ag = AcquisitionGeometry.create_Parallel3D().set_panel(
         [5, 4]).set_angles([0, 1, 2]).set_channels(2).set_labels(
             ['channel', 'angle', 'vertical', 'horizontal'])
     data = ag.allocate(None)
     new_order = ['horizontal', 'vertical', 'angle', 'channel']
     data.reorder(new_order)
     self.assertEquals(data.shape, (5, 4, 3, 2))
     self.assertEquals(data.geometry.dimension_labels, tuple(new_order))
    def test_update_reference_frame(self):
        #translate origin
        AG = AcquisitionGeometry.create_Parallel3D(detector_position=[0.,1000.,0], rotation_axis_position=[5.,2.,4.])
        AG.config.system.update_reference_frame()
        numpy.testing.assert_allclose(AG.config.system.ray.direction, [0,1,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.position, [-5,998,-4], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.direction_x, [1,0,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.rotation_axis.position, [0,0,0], rtol=1E-6)

        #align Z axis with rotate axis
        AG = AcquisitionGeometry.create_Parallel3D(detector_position=[0.,1000.,0], rotation_axis_position=[0.,0.,0.], rotation_axis_direction=[0,1,0])
        AG.config.system.update_reference_frame()
        numpy.testing.assert_allclose(AG.config.system.ray.direction, [0,0,1], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.position, [0,0,1000], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.direction_x, [1,0,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.direction_y, [0,-1,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.rotation_axis.position, [0,0,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.rotation_axis.direction, [0,0,1], rtol=1E-6)
    def test_allocate(self):
        AG = AcquisitionGeometry.create_Parallel3D()
        AG.set_channels(4)
        AG.set_panel([2,3])
        AG.set_angles([0,1,2,3,5])
        AG.set_labels(('horizontal','angle','vertical','channel'))

        test = AG.allocate()
        test2 = numpy.ndarray([2,5,3,4])
        self.assertEqual(test.shape, test2.shape)
Esempio n. 19
0
    def test_read_as_AcquisitionData1(self):
        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_panel([10, 11])
        ag.set_angles([i for i in range(12)])
        ag.set_channels(3)
        print(ag.shape)
        # print (glob.glob(os.path.join(self.data_dir, '*')))
        reader = TIFFStackReader(file_name=self.data_dir)
        acq = reader.read_as_AcquisitionData(ag)

        np.testing.assert_array_equal(acq.as_array(), self.data.as_array())
Esempio n. 20
0
    def test_AcquisitionData_fortigre(self):
        ag = AcquisitionGeometry.create_Parallel3D().set_panel(
            [5, 4]).set_angles([0, 1, 2]).set_channels(2).set_labels(
                ['horizontal', 'vertical', 'angle', 'channel'])
        data = ag.allocate(None)

        data.reorder('tigre')
        self.assertTrue(
            list(data.dimension_labels) ==
            ['channel', 'angle', 'vertical', 'horizontal'])
        self.assertTrue(data.shape == (2, 3, 4, 5))
Esempio n. 21
0
    def setUp(self): 
        #%% Setup Geometry
        voxel_num_xy = 255
        voxel_num_z = 15
        self.cs_ind = (voxel_num_z-1)//2


        src_to_obj = 500
        src_to_det = src_to_obj

        pix_size = 0.2
        det_pix_x = voxel_num_xy
        det_pix_y = voxel_num_z

        num_projections = 360
        angles = np.linspace(0, 2*np.pi, num=num_projections, endpoint=False)

        self.ag_cone = AcquisitionGeometry.create_Cone3D([0,-src_to_obj,0],[0,src_to_det-src_to_obj,0])\
                                     .set_angles(angles, angle_unit='radian')\
                                     .set_panel((det_pix_x,det_pix_y), (pix_size,pix_size))\
                                     .set_labels(['vertical','angle','horizontal'])

        self.ag_parallel = AcquisitionGeometry.create_Parallel3D()\
                                     .set_angles(angles, angle_unit='radian')\
                                     .set_panel((det_pix_x,det_pix_y), (pix_size,pix_size))\
                                     .set_labels(['vertical','angle','horizontal'])

        self.ig_3D = self.ag_parallel.get_ImageGeometry()

        #%% Create phantom
        kernel_size = voxel_num_xy
        kernel_radius = (kernel_size - 1) // 2
        y, x = np.ogrid[-kernel_radius:kernel_radius+1, -kernel_radius:kernel_radius+1]

        circle1 = [5,0,0] #r,x,y
        dist1 = ((x - circle1[1])**2 + (y - circle1[2])**2)**0.5

        circle2 = [5,100,0] #r,x,y
        dist2 = ((x - circle2[1])**2 + (y - circle2[2])**2)**0.5

        circle3 = [25,0,100] #r,x,y
        dist3 = ((x - circle3[1])**2 + (y - circle3[2])**2)**0.5

        mask1 =(dist1 - circle1[0]).clip(0,1) 
        mask2 =(dist2 - circle2[0]).clip(0,1) 
        mask3 =(dist3 - circle3[0]).clip(0,1) 
        phantom = 1 - np.logical_and(np.logical_and(mask1, mask2),mask3)

        self.golden_data = self.ig_3D.allocate(0)
        for i in range(4):
            self.golden_data.fill(array=phantom, vertical=7+i)

        self.golden_data_cs = self.golden_data.subset(vertical=self.cs_ind)
    def test_SystemConfiguration(self):
        
        #SystemConfiguration error handeling
        AG = AcquisitionGeometry.create_Parallel3D()  

        #vector wrong length
        with self.assertRaises(ValueError):
            AG.config.system.detector.position = [-0.1,0.1]

        #detector xs and yumns should be perpendicular
        with self.assertRaises(ValueError):
            AG.config.system.detector.set_direction([1,0,0],[-0.1,0.1,1])
Esempio n. 23
0
    def test_read_as_AcquisitionData2(self):
        # with this data will be scrambled but reshape is possible
        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_panel([11, 10])
        ag.set_angles([i for i in range(12)])
        ag.set_channels(3)

        reader = TIFFStackReader(file_name=self.data_dir)
        acq = reader.read_as_AcquisitionData(ag)

        np.testing.assert_array_equal(acq.as_array().flatten(),
                                      self.data.as_array().flatten())
Esempio n. 24
0
    def test_read_as_AcquisitionData_Exceptions1(self):

        ag = AcquisitionGeometry.create_Parallel3D()
        ag.set_panel([11, 12])
        ag.set_angles([i for i in range(12)])
        ag.set_channels(3)
        reader = TIFFStackReader(file_name=self.data_dir)
        try:
            acq = reader.read_as_AcquisitionData(ag)
            assert False
        except ValueError as ve:
            print(ve)
            assert True
Esempio n. 25
0
    def setUp(self):
        self.ig = ImageGeometry(2, 3, 4, channels=5)
        angles = numpy.asarray([90., 0., -90.], dtype=numpy.float32)

        self.ag_cone = AcquisitionGeometry.create_Cone3D([0,-500,0],[0,500,0])\
                                    .set_panel((20,2))\
                                    .set_angles(angles)\
                                    .set_channels(4)

        self.ag = AcquisitionGeometry.create_Parallel3D()\
                                    .set_angles(angles)\
                                    .set_channels(4)\
                                    .set_panel((20,2))
Esempio n. 26
0
    def setUp(self):

        self.acq_data = dataexample.SIMULATED_PARALLEL_BEAM_DATA.get()
        self.img_data = dataexample.SIMULATED_SPHERE_VOLUME.get()

        self.acq_data = np.log(self.acq_data)
        self.acq_data *= -1.0

        self.ig = self.img_data.geometry
        self.ag = self.acq_data.geometry

        self.ag_small = AcquisitionGeometry.create_Parallel3D()
        self.ag_small.set_panel((16, 16))
        self.ag_small.set_angles([0])
Esempio n. 27
0
    def test_weights(self):
        ag = AcquisitionGeometry.create_Parallel3D()\
            .set_panel([3,4],[0.1,0.2])\
            .set_angles([0,90])
        ad = ag.allocate(0)

        reconstructor = FBP(ad)
        reconstructor._calculate_weights(ag)
        weights = reconstructor._weights

        scaling = (2 * np.pi / ag.num_projections) / (4 * ag.pixel_size_h)
        weights_new = np.ones_like(weights) * scaling

        np.testing.assert_allclose(weights, weights_new)
    def test_create_Parallel3D(self):

        #default
        AG = AcquisitionGeometry.create_Parallel3D()
        numpy.testing.assert_allclose(AG.config.system.ray.direction, [0,1,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.position, [0,0,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.direction_x, [1,0,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.direction_y, [0,0,1], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.rotation_axis.position, [0,0,0], rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.rotation_axis.direction, [0,0,1], rtol=1E-6)

        #values
        ray_direction = [0.1, 3.0, 0.2]
        detector_position = [-1.3,1000.0, -1.0]
        detector_direction_x = [1,0.2, 0]
        detector_direction_y = [0.0,0,1]
        rotation_axis_position=[0.1, 2,-0.4]
        rotation_axis_direction=[-0.1,-0.3,1]

        AG = AcquisitionGeometry.create_Parallel3D(ray_direction, detector_position, detector_direction_x,detector_direction_y, rotation_axis_position,rotation_axis_direction)

        ray_direction = numpy.asarray(ray_direction)
        detector_direction_x = numpy.asarray(detector_direction_x)
        detector_direction_y = numpy.asarray(detector_direction_y)
        rotation_axis_direction = numpy.asarray(rotation_axis_direction)

        ray_direction /= numpy.sqrt((ray_direction**2).sum())
        detector_direction_x /= numpy.sqrt((detector_direction_x**2).sum())
        detector_direction_y /= numpy.sqrt((detector_direction_y**2).sum())
        rotation_axis_direction /= numpy.sqrt((rotation_axis_direction**2).sum())

        numpy.testing.assert_allclose(AG.config.system.ray.direction, ray_direction, rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.position, detector_position, rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.direction_x, detector_direction_x, rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.detector.direction_y, detector_direction_y, rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.rotation_axis.position, rotation_axis_position, rtol=1E-6)
        numpy.testing.assert_allclose(AG.config.system.rotation_axis.direction, rotation_axis_direction, rtol=1E-6)
    def test_set_panel(self):
        AG = AcquisitionGeometry.create_Parallel3D()

        #default
        AG.set_panel([1000,2000])
        self.assertEqual(AG.config.panel.num_pixels, [1000,2000])
        self.assertEqual(AG.config.panel.pixel_size, [1.,1.])

        #values
        AG.set_panel([1000,2000],[0.1,0.2])
        self.assertEqual(AG.config.panel.num_pixels, [1000,2000])
        self.assertEqual(AG.config.panel.pixel_size, [0.1,0.2])

        #set 2D panel with 3D geometry
        with self.assertRaises(ValueError):
            AG.config.panel.num_pixels = [5]
    def test_set_labels(self):

        AG = AcquisitionGeometry.create_Parallel3D()
        AG.set_channels(4)
        AG.set_panel([2,3])
        AG.set_angles([0,1,2,3,5])

        #default
        self.assertEqual(AG.dimension_labels, ('channel','angle','vertical','horizontal'))
        self.assertEqual(AG.shape, (4,5,3,2))

        #values
        AG.set_angles([0])
        AG.set_labels(('horizontal','channel','vertical'))
        self.assertEqual(AG.dimension_labels, ('horizontal','channel','vertical'))
        self.assertEqual(AG.shape, (2,4,3))