Example #1
0
def importOS():
    IMAGE = pr.image_read('TomoData/PhantomData/sl.mat')
    counts = pr.image_read('TomoData/noisyphantom/nslcounts.mat',
                           dtype=np.float32)
    print 'counts', counts.shape
    dark = pr.image_read('TomoData/noisyphantom/nsldark.mat', dtype=np.float32)
    print 'dark', dark.shape
    flat = pr.image_read('TomoData/noisyphantom/nslflat.mat', dtype=np.float32)
    print 'flat', flat.shape
    # flat = np.zeros(counts.shape)
    #pp.imshow( sino, cmap = 'gray_r', interpolation = 'nearest',
    #extent = ( sl.top_left[ 0 ], sl.bottom_right[ 0 ], sl.bottom_right[ 1 ], sl.top_left[ 1 ] ))
    #pp.show()

    fast_radon, fast_transp = fs.make_fourier_slice_radon_transp(counts)

    #pp.imshow( sino, cmap = 'gray_r', interpolation = 'nearest',
    #extent = ( sino.top_left[ 0 ], sino.bottom_right[ 0 ], sino.bottom_right[ 1 ], sino.top_left[ 1 ] ))
    #pp.show()

    return IMAGE, counts, dark, flat, fast_radon, fast_transp
Example #2
0
def importSino():
    sino = pr.image_read('egg_slice_1097.mat')

    #pp.imshow( sino, cmap = 'gray_r', interpolation = 'nearest',
    #extent = ( sl.top_left[ 0 ], sl.bottom_right[ 0 ], sl.bottom_right[ 1 ], sl.top_left[ 1 ] ))
    #pp.show()

    fast_radon, fast_transp = fs.make_fourier_slice_radon_transp(sino)

    #pp.imshow( sino, cmap = 'gray_r', interpolation = 'nearest',
    #extent = ( sino.top_left[ 0 ], sino.bottom_right[ 0 ], sino.bottom_right[ 1 ], sino.top_left[ 1 ] ))
    #pp.show()

    return sino, fast_radon, fast_transp
Example #3
0
def importPhoto():
    sl = pr.image_read('sl.mat')

    #pp.imshow( sl, cmap = 'gray_r', interpolation = 'nearest',
    #extent = ( sl.top_left[ 0 ], sl.bottom_right[ 0 ], sl.bottom_right[ 1 ], sl.top_left[ 1 ] ))
    #pp.show()

    sino = pr.image(np.zeros((1024, 1024)),
                    top_left=(0, 1),
                    bottom_right=(math.pi, -1))

    fast_radon, fast_transp = fs.make_fourier_slice_radon_transp(sino)

    sino = fast_radon(sl)

    #pp.imshow( sino, cmap = 'gray_r', interpolation = 'nearest',
    #extent = ( sino.top_left[ 0 ], sino.bottom_right[ 0 ], sino.bottom_right[ 1 ], sino.top_left[ 1 ] ))
    #pp.show()

    return sino, fast_radon, fast_transp
Example #4
0
def P_INTERP_PP(In1):
#%=====================================================================
#% This function performs interpolation from the Polar-Grid to the
#% Pseudo-Polar domain for use in the adjoint. The interpolation is in
#% two stages first along each ray to obtain non-equispaced points, then
#% along each row to obtain non-equiangular rays on the concentric square
#% grid.
#%   In - 2D-FFT on the Polar Grid (r, theta)
#%   Out- 2D-FFT on the Pseudo-Polar Grid (r, theta)
#%=====================================================================

    if In1 is None:
        In1 = pr.image_read('TomoData/noisyphantom/nslcounts.mat',dtype=np.float32)
   
    OS1=1;
    OS2=1;
    K = np.shape(In1)
    In =  In1
    print('import done')
    
    N = min(np.shape(In)); #assuming square input

    # C. resampling the rays to the Pseudo-Polar locations
    F=In[:,0:N/2]
    Fout = np.zeros((OS2*N,N/2))*0j
    Xcor = np.arange(-2.0*np.pi,2.0*np.pi-np.pi/(N*OS2),2.0*np.pi/(N*OS2))   #these are the current locations
    Xcor1 = np.arange(-np.pi*1.0,np.pi-np.pi/(2*N*OS2),2.0*np.pi/(2.0*N*OS2))  
    print('initialization done')
    for k in range(1,N/2+1):
        Ray=np.transpose(F[:,k-1])
        Factor=np.cos((k-N/4.0)*np.pi/(N)); # completion of current locations
        #f2 = interp1d(Xcor, Ray, kind='linear')
        f2 = CubicSpline(Xcor,Ray)
        Fout[:,k-1]=np.transpose(f2(Xcor1[0::2*OS2]/Factor));
  
    # C. resampling the rays to the Pseudo-Polar locations
    G=In[:,N/2::];
    Gout = np.zeros((N,N/2))*0j;
    Ycor = np.arange(-2.0*np.pi,2.0*np.pi-np.pi/(N*OS2),2.0*np.pi/(N*OS2)) #these are the current locations
    Ycor1 = np.arange(-np.pi*1.0,np.pi-np.pi/(2*N*OS2),2.0*np.pi/(2.0*N*OS2))  
    for k in range(1,N/2+1):
        Ray=G[:,k-1]
        Factor=np.cos((k-N/4.0 )*np.pi/(N)); # completion of current locations
        #f2 = interp1d(Xcor, Ray,kind='linear')
        f2 = CubicSpline(Ycor,Ray)
        Gout[:,k-1]=np.transpose(f2(Ycor1[0::2*OS2]/Factor)) 

    # B. row/columnwise interpolation to obatain equi-distant slope
    Xcor1 = 2.0*np.pi/(N*OS2)*np.arange(-OS1*N/2.0,OS1*N/2.0-1,2)/OS1/N
    Xcor2 = 1.0*np.pi/(N*OS2)*np.tan(np.pi*np.arange(-N/2.0,N/2.0-1,2)/N/2.0)
    steps = range(-N/2*OS2,N/2*OS2)
    for ll in steps:
        Temp1=Fout[ll+OS2*N/2,:]
        if ll != 0:
            #f2 = interp1d(Xcor2*ll,Temp1,kind='linear', fill_value='extrapolate')
            if ll > 0:
                f2 = CubicSpline(Xcor2*ll,Temp1)
                Fout[ll+OS2*N/2,0:N/2]=f2(Xcor1*ll);
            else:
                f2 = CubicSpline(np.flip(Xcor2*ll,0),np.flip(Temp1,0))
                Fout[ll+OS2*N/2,0:N/2]=f2(Xcor1*ll);
        else:
            Fout[ll+OS2*N/2,0:N/2]=Temp1[0::OS1];
        
    # B. row/columnwise interpolation to obatain equi-distant slope  
    Ycor1 = 2.0*np.pi/(N*OS2)*np.arange(-OS1*N/2.0,OS1*N/2.0-1,2)/OS1/N
    Ycor2 = 1.0*np.pi/(N*OS2)*np.tan(np.pi*np.arange(-N/2.0,N/2.0-1,2)/N/2.0)
    steps = range(-N/2*OS2,N/2*OS2)
    for ll in steps:
        Temp2=Gout[ll+OS2*N/2,:];
        if ll !=0:
            #f2 = interp1d(Ycor2*ll,Temp1, kind='linear',fill_value='extrapolate')
            if ll > 0:
                f2 = CubicSpline(Ycor2*ll,Temp2)
                Gout[ll+OS2*N/2,0:N/2]= f2(Ycor1*ll)
            else:
                f2 = CubicSpline(np.flip(Ycor2*ll,0),np.flip(Temp2,0))
                Gout[ll+OS2*N/2,0:N/2]=f2(Ycor1*ll);
                    
        else:
            Gout[ll+OS2*N/2,0:N/2]= Temp2[0::OS1];

    Out = np.concatenate(((Fout), Gout),1)
    return Out
Example #5
0
import pyraft as pr
import matplotlib.pyplot as pp
import fourier_slice as fs
import numpy as np
import math

# From Fullerton_Example
# implementation of FISTA
# uses actual data (seed data)

yy = pr.image_read('counts.mat', dtype=np.float32)
r = pr.image_read('dark.mat', dtype=np.float32)
b = pr.image_read('flat.mat', dtype=np.float32)

dim = 2048

# USE THIS TO CHANGE DIMENSIONS OF DATA
sino = yy  # given sinogram data
fast_radon, fast_transp = fs.make_fourier_slice_radon_transp(sino)
#pp.imshow(sino, interpolation = 'nearest', cmap = 'gray_r', extent = ( sino.top_left[ 0 ], sino.bottom_right[ 0 ], sino.bottom_right[ 1 ], sino.top_left[ 1 ] ) )
#pp.show()


def gradient(xz):
    temp = (b * yy) / (
        b + np.exp(fast_radon(xz)) * r) - b * np.exp(-fast_radon(xz))
    return fast_transp(temp)


told = 1  # initial t val
data1 = sino  # locate image
Example #6
0
def pseudoimportSino(data_case):
    #You can custom import data by loading into directory and changing string
    #Sinogram must by NxN wher N is doubly even. It may be useful to develop 
    #interpolation function in feature domain to create artificial oversampling
    #this way any data can be made NxN with N divisible by 4.
    if data_case ==0:
        sl = pr.image_read( 'TomoData/PhantomData/sl2.mat', dtype=np.float32) 
        flat = pr.image_read( 'TomoData/PhantomData/slflat.mat', dtype=np.float32  ) 
        dark = pr.image_read( 'TomoData/PhantomData/sldark.mat', dtype=np.float32  )
        counts = pr.image_read( 'TomoData/PhantomData/slcount.mat', dtype=np.float32 ) 
    elif data_case == 1:
        sl = pr.image_read( 'TomoData/PhantomData/sl2.mat', dtype=np.float32) 
        flat = pr.image_read( 'TomoData/noisyphantom/nslflat.mat', dtype=np.float32  ) 
        dark = pr.image_read( 'TomoData/noisyphantom/nsldark.mat', dtype=np.float32  ) 
        counts = pr.image_read( 'TomoData/noisyphantom/nslcounts.mat', dtype=np.float32 ) 
    elif data_case ==2:
        sl = pr.image(np.ones((1024,1024)), top_left =(-1,1), bottom_right = (1,-1)) 
        flat = pr.image_read( 'TomoData/SeedData/flati.mat', dtype=np.float32  ) 
        dark = pr.image_read( 'TomoData/SeedData/darki.mat', dtype=np.float32  ) 
        counts = pr.image_read( 'TomoData/SeedData/countsi.mat', dtype=np.float32 ) 
    else:
        print('not a valid data_case, you can insert custom data here')
        quit()
    #the lines below must always be performed regardless of data
    n,k = sl.shape
    #Form sino for interpolation step
    sino = np.log(flat/counts)
    #Pad Sino to eliminate need for extrapolation, oversample
    sino = PIPP.Pad2x(sino)
    print(np.max(sino))
    #Convert to frequency domain
    fsino = np.fft.fftshift(sino, axes = 0)
    fsino = np.fft.fft( fsino, axis = 0 )
    fsino = np.fft.fftshift(fsino)
    #Interpolate via 2 stage interpolation (reverse of averbuch et. al)
    fsino = PIPP.P_INTERP_PP(fsino)
    #Convert back to feature domain
    fsino = np.fft.fftshift(fsino )
    fsino = np.fft.ifft( fsino, axis = 0 )
    sino= (np.real(np.fft.ifftshift(fsino, axes=0)))
    sino= pr.image(np.concatenate((np.fliplr(np.flipud(sino[:,0:n])),np.fliplr(sino[:,n::])),1), top_left = (0,1), bottom_right = (np.pi,-1) )
    print(np.min(counts))
    #Reparse into counts,flat,dark
    counts = pr.image(flat/np.exp(sino), top_left = (0,1), bottom_right = (np.pi,-1) )
    function = ppfs.make_fourier_slice_radon_transp
    fast_radon, fast_transp = function( sino )

    return sl, sino, counts, dark, flat, fast_radon, fast_transp, function     
Example #7
0
def nonuimportSino(data_case):
    if data_case ==0:
        sl = pr.image_read( 'TomoData/PhantomData/sl.mat') 
        flat = pr.image_read( 'TomoData/PhantomData/slflat.mat', dtype=np.float32  ) 
        dark = pr.image_read( 'TomoData/PhantomData/sldark.mat', dtype=np.float32  )
        counts = pr.image_read( 'TomoData/PhantomData/slcount.mat', dtype=np.float32 ) 
    elif data_case ==1:
        sl = pr.image_read( 'TomoData/PhantomData/sl.mat') 
        counts = pr.image_read( 'TomoData/noisyphantom/nslcounts.mat', dtype=np.float32 ) 
        flat = pr.image_read( 'TomoData/noisyphantom/nslflat.mat', dtype=np.float32  ) 
        dark = pr.image_read( 'TomoData/noisyphantom/nsldark.mat', dtype=np.float32  )
    elif data_case ==2:
        sl = pr.image(np.ones((2048,2048)), top_left =(-1,1), bottom_right = (1,-1)) 
        flat = pr.image_read( 'TomoData/SeedData/flati.mat', dtype=np.float32  ) 
        dark = pr.image_read( 'TomoData/SeedData/darki.mat', dtype=np.float32  ) 
        counts = pr.image_read( 'TomoData/SeedData/countsi.mat', dtype=np.float32 ) 
    else:
        print('not a valid data_case, you can insert custom data here')
        quit()
        
    sino = pr.image(np.log(flat/counts), top_left = (0,1),bottom_right=(np.pi,-1))
    function = fs.make_fourier_slice_radon_transp
    fast_radon, fast_transp = function( sino )
    
    return sl, sino, counts, dark, flat, fast_radon, fast_transp, function