示例#1
0
def create_scanner_k_space(im,
                           N,
                           P=2,
                           pctg=0.25,
                           dirData=False,
                           dirs=None,
                           radius=0.2,
                           cyl=[0],
                           style='mult',
                           pft=False,
                           ext=0.5):
    '''
    Read in the data, size, and the directions (if they exist) so that we can create a
    retrospectively sampled set of data for testing.
    '''

    # Create a pdf so that we can use it to make a starting point
    pdf = samp.genPDF(N[-2:],
                      P,
                      pctg,
                      radius=radius,
                      cyl=[1, N[-2], N[-1]],
                      style='mult',
                      pft=pft,
                      ext=0.5)

    # Generate the sampling scheme, depending on whether or not
    if dirData:
        if dirs is None:
            raise ValueError(
                'If we have directional data, you need to feed this into the function'
            )
        k = d.dirPDFSamp([int(dirs.shape[0]), N[-2], N[-1]],
                         P=2,
                         pctg=pctg,
                         radius=radius,
                         dirs=dirs,
                         cyl=True,
                         taper=0.25)[0]
    else:
        k = samp.genSampling(pdf, 50, 2)[0].astype(int)

    # Since our functions are built to work in 3D datasets, here we
    # make sure that N and things are all in 3D
    if len(N) == 2:
        N = np.hstack([1, N])
        k = k.reshape(N)
        im = im.reshape(N)
    elif len(N) == 3:
        if k.ndim == 2:
            k = k.reshape(np.hstack([1, N[-2:]])).repeat(N[0], 0)

    k = np.fft.fftshift(k, axes=(-2, -1))
    # Convert the image data into k-space
    ph_ones = np.ones(N, complex)
    dataFull = tf.fft2c(im, ph=ph_ones, axes=(-2, -1))
    # Apply our sampling
    data = k * dataFull
    # Now we need to calculate the phase in order to deal with the undersampled image and the
    # non perfect cancellation of terms
    #filtdata = gaussian_filter(im_scan_wph.real,0,0) + 1j*gaussian_filter(im_scan_wph.imag,0,0)
    #ph_scan = np.exp(1j*np.angle(filtdata.conj()))
    im_scan_wph = tf.ifft2c(data, ph=ph_ones)
    ph_scan = np.angle(
        gaussian_filter(im_scan_wph.real, 0) +
        1.j * gaussian_filter(im_scan_wph.imag, 0))
    ph_scan = np.exp(1j * ph_scan)
    im_scan = tf.ifft2c(data, ph=ph_scan)

    pdfDiv = pdf.copy()
    pdfZeros = np.where(pdf < 1e-4)
    pdfDiv[pdfZeros] = 1
    datadc = data / pdfDiv

    return dataFull, data, datadc, pdf, k, im_scan, ph_scan
im = np.load('/home/asalerno/Documents/pyDirectionCompSense/phantom/diffusionPhantomSmoothedSNR1000.npy')
#im = np.load('/home/asalerno/Documents/pyDirectionCompSense/directionData/singleSlice_30dirs.npy')
#im=im/np.max(abs(im))
minval = np.min(abs(im))
maxval = np.max(abs(im))
N = np.array(im.shape)  # image Size
szFull = im.size


P = 2
nSteps = 4

print('k for Directions')
#kDir = samp.genSamplingDir(img_sz=N, dirFile=dirFile, pctg=pctg, cyl=[1], radius=radius,            
                #nmins=nmins, engfile=engfile)
kDir = d.dirPDFSamp(N,P=2,pctg=0.25,radius=0.2,dirs=dirs,cyl=True,taper=0.25)

pdf = samp.genPDF(N[-2:], P, pctg, radius=radius, cyl=[1, N[-2], N[-1]], style='mult', pft=pft,ext=0.5)
k = np.zeros(N)

print('k for non')
for i in xrange(N[0]):                             
    np.random.seed(int(i*abs(np.random.randn(1)*np.random.randn(1))))
    print(i)
    k[i,:,:] = samp.genSampling(pdf, 50, 2)[0].astype(int)


ph_ones = np.ones(N[-2:], complex)
dataFull = np.zeros(N,complex)

ph_scan = np.zeros(N, complex)
示例#3
0
    #pdf = samp.genPDF(N[-2:], P, pctg, radius=radius, cyl=[1, N[-2], N[-1]], style='mult', pft=pft,ext=0.5)
    #k = d.dirPDFSamp([int(dirs.shape[0]), 294, 294], P=2, pctg=0.25, radius=0.2, dirs=dirs, cyl=True, taper=0.25)
    #k = np.load('/hpf/largeprojects/MICe/asalerno/pyDirectionCompSense/data/comb_k_25.npy')
    k = np.zeros([dirs.shape[0], N[-2], N[-1]])
    pdf = samp.genPDF(N[-2:],
                      P,
                      pctg,
                      radius=radius,
                      cyl=[1, N[-2], N[-1]],
                      style='mult',
                      pft=pft,
                      ext=0.5)
    k = d.dirPDFSamp([int(dirs.shape[0]), N[-2], N[-1]],
                     P=2,
                     pctg=0.25,
                     radius=0.2,
                     dirs=dirs,
                     cyl=True,
                     taper=0.25)[0]

    if len(N) == 2:
        N = np.hstack([1, N])
        k = k.reshape(N)
        im = im.reshape(N)
    elif len(N) == 3:
        if not np.all(k.shape == N):
            k = k.reshape(np.hstack([1, N[-2:]]))
            k = [k[0] for _ in range(im.shape[0])]
            k = np.stack(k, axis=0)
            #k = k.reshape(np.hstack([1,N[-2:]])).repeat(N[0],0)
示例#4
0
#im=im/np.max(abs(im))
minval = np.min(abs(im))
maxval = np.max(abs(im))
N = np.array(im.shape)  # image Size
szFull = im.size

P = 2
nSteps = 4

print('k for Directions')
#kDir = samp.genSamplingDir(img_sz=N, dirFile=dirFile, pctg=pctg, cyl=[1], radius=radius,
#nmins=nmins, engfile=engfile)
kDir = d.dirPDFSamp(N,
                    P=2,
                    pctg=0.25,
                    radius=0.2,
                    dirs=dirs,
                    cyl=True,
                    taper=0.25)

pdf = samp.genPDF(N[-2:],
                  P,
                  pctg,
                  radius=radius,
                  cyl=[1, N[-2], N[-1]],
                  style='mult',
                  pft=pft,
                  ext=0.5)
k = np.zeros(N)

print('k for non')
示例#5
0
#--------------------------------------------------------------
# If our special cases have an effect here, PLEASE put the
# original code within these two bars.

#pdf = samp.genPDF(N[-2:], P, pctg, radius=radius, cyl=[1, N[-2], N[-1]], style='mult', pft=pft,ext=0.5)
#if pft:
    #print('Partial Fourier sampling method used')

#k = samp.genSampling(pdf, 50, 2)[0].astype(int)
#d.dirPDFSamp(N,P=2,pctg=0.25,radius=0.2,dirs=dirs,cyl=True,taper=0.25)

#--------------------------------------------------------------
#k = np.zeros([int(np.ceil(N[0]/dirs.shape[0])*dirs.shape[0]), 294, 294])
k = np.zeros([dirs.shape[0], 294, 294])
pdf = samp.genPDF(N[-2:], P, pctg, radius=radius, cyl=[1, N[-2], N[-1]], style='mult', pft=pft,ext=0.5)
k = d.dirPDFSamp([int(dirs.shape[0]), 294, 294], P=2, pctg=0.25, radius=0.2, dirs=dirs, cyl=True, taper=0.25)

k = [k[0] for _ in range(im.shape[0])]
k = np.stack(k,axis=0)
# SPECIAL CASE END

# Since our functions are built to work in 3D datasets, here we
# make sure that N and things are all in 3D
if len(N) == 2:
    N = np.hstack([1, N])
    k = k.reshape(N)
    im = im.reshape(N)
elif len(N) == 3:
    if k.ndim == 2:
        k = k.reshape(np.hstack([1,N[-2:]])).repeat(N[0],0)