コード例 #1
0
 def test_write_center(self):
     dpath = os.path.join('test', 'tmp')
     cen_range = (5, 7, 0.5)
     cen = np.arange(*cen_range)
     write_center(
         read_file('proj.npy'),
         read_file('angle.npy'),
         dpath, cen_range=cen_range)
     for m in range(cen.size):
         assert_equals(
             os.path.isfile(
                 os.path.join(
                     os.path.join('test', 'tmp'),
                     str('{0:.2f}'.format(cen[m]) + '.tiff'))), True)
     shutil.rmtree(dpath)
コード例 #2
0
def manualFindCenter(filename,output_file,center_shift,center_shift_w,
                     zinger=None,zinger_level=1000,sliceStart=100,sliceEnd=120,
                     data_center_path=None,flat_name=None,dark_name=None,
                     mask=False,mask_ratio=1,**kwargs):
    dim = dataInfo(filename)
    theta = np.linspace(0,np.pi,num=dim[0]+1)
    
    if kwargs.has_key('ExplicitParams'):
        sliceStart = kwargs['ExplicitParams']['sliceStart']
        sliceEnd = kwargs['ExplicitParams']['sliceEnd']
        zinger = kwargs['ExplicitParams']['zinger']
        zinger_level = kwargs['ExplicitParams']['zinger_level']
        data_center_path = kwargs['ExplicitParams']['data_center_path']
        flat_name = kwargs['ExplicitParams']['flat_name']
        dark_name = kwargs['ExplicitParams']['dark_name'] 
        mask = kwargs['ExplicitParams']['mask'] 
        mask_ratio = kwargs['ExplicitParams']['mask_ratio']
        

    data,white,dark = dataStandardReader(filename,sliceStart=sliceStart,sliceEnd=sliceEnd,
                                         flat_name=flat_name,dark_name=dark_name)
   
    if data.all() == 0:
        print 'Reconstruction is terminated due to data file error.'
        exit()
    
    data_size = data.shape
    theta = np.linspace(0,np.pi,num=data_size[0]+1) 
    print 'data is read'
    
#    # remove zingers (pixels with abnormal counts)
    if zinger == True:
        data = tomopy.misc.corr.remove_outlier(data,zinger_level,size=15,axis=0)
        white = tomopy.misc.corr.remove_outlier(white,zinger_level,size=15,axis=0)
        print  'remove outlier is done'
    
    # normalize projection images; for now you need to do below two operations in sequence
    data = tomopy.prep.normalize.normalize(data,white,dark)
    print 'normalization is done'
    
    data = generalFilterContainer(data,**kwargs) 
        
#    data = tomopy.prep.normalize.minus_log(data)
    if data_center_path==None:
        data_center_path = '~/tomopy_data_center'
    write_center(data[:,int(data_size[1]/2)-1:int(data_size[1]/2)+1,:], theta, dpath=data_center_path, 
                 cen_range=(data.shape[2]/2+center_shift,data.shape[2]/2+center_shift+center_shift_w,0.5),
                 mask = mask, ratio = mask_ratio)
コード例 #3
0
 def test_write_center(self):
     dpath = os.path.join('test', 'tmp')
     # if get_nproc() > 1 and get_rank() > 0:
     #    dpath += "_{}".format(get_rank())
     cen_range = (5, 7, 0.5)
     cen = np.arange(*cen_range)
     write_center(
         read_file('proj.npy'),
         read_file('angle.npy'),
         dpath, cen_range=cen_range,
         algorithm='gridrec', filter_name='shepp')
     for m in range(cen.size):
         assert_equals(
             os.path.isfile(
                 os.path.join(
                     os.path.join('test', 'tmp'),
                     str('{0:.2f}'.format(cen[m]) + '.tiff'))), True)
     shutil.rmtree(dpath)
コード例 #4
0
ファイル: tomo_wrap.py プロジェクト: hdersar/seashell_project
    def center_shift(self,
                     offset=None,
                     test_path=None,
                     ind=None,
                     cen_range=None):
        '''
        Find the center of the sinogram and apply the shift to corect for the offset
        '''
        sz = self._parent.data.shape(2) // 2

        if test_path is not None:
            rotation.write_center(self._parent.data._data,
                                  theta=self._parent.meta.theta,
                                  dpath=test_path,
                                  ind=ind,
                                  cen_range=cen_range,
                                  sinogram_order=True)

        else:
            if offset is None:
                offset = sz - rotation.find_center(self._parent.data._data,
                                                   self._parent.meta.theta,
                                                   sinogram_order=True)[0]
                #offset = sz-rotation.find_center_pc(self._parent.data._data[:,0,:], self._parent.data._data[:,self._parent.data.shape(1)//2,:])p

            # Do nothing is the offset is less than 1 pixel
            if (numpy.abs(offset) >= 1):
                self._parent.data._data = interp.shift(self._parent.data._data,
                                                       (0, 0, offset))
                self._parent.meta.history[
                    'process.center_shift(offset)'] = offset

                self._parent.message('Horizontal offset corrected.')
            else:
                self._parent.warning(
                    "Center shift found an offset smaller than 1. Correction won't be applied"
                )
コード例 #5
0
ファイル: Reconstructtxrm.py プロジェクト: jamesvigor/zrecon
data = tomopy.prep.phase.retrieve_phase(data,
                                        pixel_size=header['pixel_size'],
                                        energy=eng,
                                        alpha=rat,
                                        pad=True)

# Propagation distance data...
#data = tomopy.prep.phase.retrieve_phase(data, pixel_size=header['pixel_size'], energy=eng, alpha=rat, pad=True, dist=dist)

# Find the center of rotation using artifacts present in a reconstructed image at discrete centres of rotation.

# In[ ]:

#CoR = find_center(data, theta, mask=True, tol=1)
CoR = write_center(
    data,
    theta,
)
print("Center of Rotation found at: {}".format(CoR))

# Reconstruct the dataset using the algorithm specified. The Zeiss reconstructor probably uses the standard filtered back projection fbp algorithm, also available in tomopu are the blog algebraic reconstruction technique, and fourier grid reconstruction technique (probably quicker on a good workstation).

# In[ ]:

# Reconstruct using the fourier grid reconstruction algorithm...
rcn = recon(data[:, 50:55, 0:2000],
            theta,
            center=CoR,
            algorithm='gridrec',
            nchunk=100,
            ncore=4)