예제 #1
0
def import_interfile_volume_data(
        headerfile='',
        datafile=''):  #FIXME: this should be in the Interfile package
    F = Interfile.load(headerfile)
    if F.has_key('matrix size[1]'):
        Nx = F['matrix size[1]']['value']
        Ny = F['matrix size[2]']['value']
        Nz = F['matrix size[3]']['value']
    else:
        Nx = F['matrix size [1]']['value']
        Ny = F['matrix size [2]']['value']
        Nz = F['matrix size [3]']['value']
    if datafile == '':
        datafile1 = headerfile.replace(
            headerfile.split(os.sep)[-1], F['name of data file']['value'])
        datafile2 = headerfile.replace('.v.hdr', '.v')
        datafile2 = datafile2.replace('.h33', '.v')
        datafile3 = headerfile.replace('.h33', '.v')
        try:
            data = fromfile(datafile1, dtype=float32)
        except:
            try:
                data = fromfile(datafile2, dtype=float32)
            except:
                try:
                    data = fromfile(datafile3, dtype=float32)
                except:
                    print("Data file not found.")
    else:
        data = fromfile(datafile, dtype=float32)
    data = data.reshape([Nz, Ny, Nx])
    data = asfortranarray(data.swapaxes(0, 2))
    data = transpose(data, [1, 0, 2])
    data = data[::-1, :, :]
    return data
예제 #2
0
def import_interfile_projection_data(headerfile='', datafile=''):   #FIXME: this should be in the Interfile package
        F = Interfile.load(headerfile)
        
        if F.has_key('matrix size[1]'): 
            N_planes    = F['matrix size[1]']['value']
            N_axial     = F['matrix size[2]']['value']
            N_sinograms = F['matrix size[3]']['value']        
        else:
            N_planes    = F['matrix size [1]']['value']
            N_axial     = F['matrix size [2]']['value']
            N_sinograms = F['matrix size [3]']['value']    
        if datafile == '': 
            datafile1 = headerfile.replace(headerfile.split(os.sep)[-1],F['name of data file']['value'])
            datafile2 = headerfile.replace('.s.hdr','.s') 
            datafile2 = datafile2.replace('.h33','.a')
            datafile3 = headerfile.replace('.h33','.s')
            try: 
                data = fromfile(datafile1,dtype=float32)
            except: 
                try: 
                    data = fromfile(datafile2,dtype=float32)
                except: 
                    try: 
                        data = fromfile(datafile3,dtype=float32)
                    except: 
                        print "Data file not found."
        else: 
            data = fromfile(datafile,dtype=float32)
        data = data.reshape([N_sinograms,N_axial,N_planes])
        return data
예제 #3
0
def import_interfile_volume_data(headerfile='', datafile=''):  #FIXME: this should be in the Interfile package
        F = Interfile.load(headerfile)
        if F.has_key('matrix size[1]'): 
            Nx    = F['matrix size[1]']['value']
            Ny    = F['matrix size[2]']['value']
            Nz    = F['matrix size[3]']['value']        
        else:
            Nx    = F['matrix size [1]']['value']
            Ny    = F['matrix size [2]']['value']
            Nz    = F['matrix size [3]']['value']    
        if datafile == '': 
            datafile1 = headerfile.replace(headerfile.split(os.sep)[-1],F['name of data file']['value'])
            datafile2 = headerfile.replace('.v.hdr','.v') 
            datafile2 = datafile2.replace('.h33','.v')
            datafile3 = headerfile.replace('.h33','.v')
            try: 
                data = fromfile(datafile1,dtype=float32)
            except: 
                try: 
                    data = fromfile(datafile2,dtype=float32)
                except: 
                    try: 
                        data = fromfile(datafile3,dtype=float32)
                    except: 
                        print "Data file not found."
        else: 
            data = fromfile(datafile,dtype=float32)
        data = data.reshape([Nz,Ny,Nx])
        data = asfortranarray(data.swapaxes(0,2))
        data = transpose(data,[1,0,2])
        data = data[::-1,:,:]
        return data    
예제 #4
0
 def __get_interfile(self, dcm):
     """
     :param dcm:
     :return lm_dict, a dictionary of interfile fields:
     """
     from interfile import Interfile
     try:
         lm_dict = Interfile.load(dcm)
     except (AttributeError, TypeError):
         raise AssertionError('dcm must be a filename')
     return lm_dict
예제 #5
0
def import_interfile_volume(headerfile='', datafile=''): 
        # Load ndarray data 
        data = import_interfile_volume_data(headerfile, datafile) 
        # Load other information - e.g. pixels size 
        F = Interfile.load(headerfile)
        if F.has_key('scale factor (mm/pixel) [1]'): 
            pixsize_x = F['scale factor (mm/pixel) [1]']['value']
            pixsize_y = F['scale factor (mm/pixel) [2]']['value']
            pixsize_z = F['scale factor (mm/pixel) [3]']['value']
        # Create Image3D 
        T_pix_to_world = Transform_Scale(int32([pixsize_x,pixsize_y,pixsize_z]), map_from='pixels_PET', map_to='world') 
        volume = Image3D(data=data, affine=T_pix_to_world, space='world')  
        return volume
예제 #6
0
def import_interfile_volume(headerfile='', datafile=''):
    # Load ndarray data
    data = import_interfile_volume_data(headerfile, datafile)
    # Load other information - e.g. pixels size
    F = Interfile.load(headerfile)
    if F.has_key('scale factor (mm/pixel) [1]'):
        pixsize_x = F['scale factor (mm/pixel) [1]']['value']
        pixsize_y = F['scale factor (mm/pixel) [2]']['value']
        pixsize_z = F['scale factor (mm/pixel) [3]']['value']
    # Create Image3D
    T_pix_to_world = Transform_Scale(int32([pixsize_x, pixsize_y, pixsize_z]),
                                     map_from='pixels_PET',
                                     map_to='world')
    volume = Image3D(data=data, affine=T_pix_to_world, space='world')
    return volume
예제 #7
0
def import_interfile_projection_data(
        headerfile='',
        datafile='',
        load_time=False):  #FIXME: this should be in the Interfile package
    F = Interfile.load(headerfile)

    if F.has_key('matrix size[1]'):
        N_planes = F['matrix size[1]']['value']
        N_axial = F['matrix size[2]']['value']
        N_sinograms = F['matrix size[3]']['value']
    else:
        N_planes = F['matrix size [1]']['value']
        N_axial = F['matrix size [2]']['value']
        N_sinograms = F['matrix size [3]']['value']
    if datafile == '':
        datafile1 = headerfile.replace(
            headerfile.split(os.sep)[-1], F['name of data file']['value'])
        datafile2 = headerfile.replace('.s.hdr', '.s')
        datafile2 = datafile2.replace('.h33', '.a')
        datafile3 = headerfile.replace('.h33', '.s')
        try:
            data = fromfile(datafile1, dtype=float32)
        except:
            try:
                data = fromfile(datafile2, dtype=float32)
            except:
                try:
                    data = fromfile(datafile3, dtype=float32)
                except:
                    print("Data file not found.")
    else:
        data = fromfile(datafile, dtype=float32)
    data = data.reshape([N_sinograms, N_axial, N_planes])
    if load_time:
        try:
            duration = int32([0, F['image duration']['value']]) * 1000
        except:
            print(
                "Unable to load image (sinogram) duration. "
                "This may determine an incorrect scale and use of randoms and scatter when reconstructing. "
                "Set .time_bins manually. ")
            duration = int32([0, 0])
    else:
        duration = int32([0, 0])
    return data, duration
예제 #8
0
 def test_sinogram_parse(self):
     """Parse a simple interfile. """
     with open('../examples/parsed_sinogram.pickle', 'rb') as handle:
         sino_ref = pickle.load(handle)
     sino = Interfile.load('../examples/pet_sinogram.s.hdr')
     self.assertEqual(sino_ref, sino)
예제 #9
0
 def test_listmode_parse(self):
     """Parse a simple interfile. """
     with open('../examples/parsed_listmode.pickle', 'rb') as handle:
         listmode_ref = pickle.load(handle)
     listmode = Interfile.load('../examples/pet_listmode.l.hdr')
     self.assertEqual(listmode_ref, listmode)