예제 #1
0
    def constructMatexplicit(self,uHalf2D,fun,m=0):
        # temp = fun(self.irfft2(uHalf2D)).T#ini kenapa harus di transpose ya?
        temp = fun(self.irfft2(uHalf2D))#Harusnya ga ditranspose!!
        temp = self.rfft2(temp)

        #symmetrize here
        temp = util.symmetrize_2D(temp)
        if m != 0:
            temp = util.shift_2D(temp,self.Kmatrix[:,m])

        return self.constructU(temp)
예제 #2
0
def initialize_using_FBP(sim):
    #Set initial condition of fourier index as the fourier index of FBP
    FBP_image = iradon(cp.asnumpy(sim.measurement.sinogram),
                       theta=cp.asnumpy(sim.measurement.theta),
                       circle=True)
    fbp_fHalf = sim.fourier.rfft2(cp.asarray(FBP_image, dtype=cp.float32))
    fbp_fSym2D = util.symmetrize_2D(fbp_fHalf)
    fbp_fSym = fbp_fSym2D.ravel(im.ORDER)

    sim.Layers[-1].current_sample_sym = fbp_fSym
    sim.Layers[-1].current_sample = sim.Layers[-1].current_sample_sym[
        sim.fourier.basis_number_2D_ravel - 1:]
    sim.Layers[-1].record_sample()
예제 #3
0
 def irfft2(self,uHalf2D):
     """
     Fourier transform of one dimensional signal
     ut   = 1D signal 
     num  = Ut length - 1
     dt   = timestep
     (now using cp.fft.fft) in the implementation
     """
     u2D = util.extend2D(util.symmetrize_2D(uHalf2D),self.extended_basis_number)
     if self._plan_ifft2 is None:
         self._plan_ifft2 = cpxFFT.get_fft_plan(u2D, shape=u2D.shape)   
     u2D = cp.fft.ifftshift(u2D)
     temp = cpxFFT.ifft2(u2D,shape=u2D.shape,plan=self._plan_ifft2,overwrite_x=True)
     return temp.real*(2*self.extended_basis_number-1)
예제 #4
0
def post_analysis(input_dir):
    relative_path = pathlib.Path(
        "//data.triton.aalto.fi/work/emzirm1/SimulationResult/")
    SimulationResult_dir = relative_path / input_dir
    file = h5py.File(str(SimulationResult_dir / 'result.hdf5'), mode='r')

    samples_history = file['Layers 1/samples_history'][()]
    u_samples_history = file['Layers 0/samples_history'][()]
    #    meas_std = file['measurement/stdev'][()]
    burn_start_index = np.int(0.3 * u_samples_history.shape[0])
    u_samples_history = u_samples_history[burn_start_index:, :]
    samples_history = samples_history[burn_start_index:, :]
    N = u_samples_history.shape[0]

    mean_field = util.symmetrize(cp.asarray(np.mean(samples_history, axis=0)))
    #    u_mean_field = util.symmetrize(cp.asarray(np.mean(u_samples_history,axis=0)))
    #    stdev_field = util.symmetrize(cp.asarray(np.std(samples_history,axis=0)))
    n = file['fourier/basis_number'][()]
    n_ext = file['fourier/extended_basis_number'][()]
    t_start = file['t_start'][()]
    t_end = file['t_end'][()]
    target_image = file['measurement/target_image'][()]
    corrupted_image = file['measurement/corrupted_image'][()]

    isSinogram = 'sinogram' in file['measurement'].keys()

    if isSinogram:
        sinogram = file['measurement/sinogram'][()]
        theta = file['measurement/theta'][()]
        fbp = iradon(sinogram, theta, circle=True)

    fourier = imc.FourierAnalysis_2D(n, n_ext, t_start, t_end)
    sL2 = util.sigmasLancosTwo(cp.int(n))

    vF = mean_field.reshape(2 * n - 1, 2 * n - 1, order=imc.ORDER).T

    #    if not isSinogram:
    vForiginal = sL2 * util.symmetrize_2D(
        fourier.fourierTransformHalf(cp.array(target_image)))

    vFn = cp.asnumpy(vF)

    reconstructed_image = fourier.inverseFourierLimited(vF[:, n - 1:])

    if isSinogram:
        reconstructed_image = cp.rot90(cp.fft.fftshift(reconstructed_image),
                                       -1)

    reconstructed_image_original = fourier.inverseFourierLimited(
        vForiginal[:, n - 1:])
    scalling_factor = (cp.max(reconstructed_image_original) -
                       cp.min(reconstructed_image_original)) / (
                           cp.max(reconstructed_image) -
                           cp.min(reconstructed_image))

    u_samples_history_cp = cp.asarray(u_samples_history)
    u_image = cp.zeros_like(reconstructed_image)
    for i in range(N):
        uF = util.symmetrize(u_samples_history_cp[i, :]).reshape(
            2 * n - 1, 2 * n - 1, order=imc.ORDER).T
        u_image += fourier.inverseFourierLimited(uF[:, n - 1:]) / N

    if isSinogram:
        u_image = cp.rot90(cp.fft.fftshift(u_image), -1)

    ri_n = cp.asnumpy(reconstructed_image)
    if isSinogram:
        ri_or_n = fbp
    else:
        ri_or_n = cp.asnumpy(reconstructed_image_original)

    ri_n_scalled = ri_n * cp.asnumpy(scalling_factor)
    u_n = cp.asnumpy(u_image / (np.max(ri_n) - np.min(ri_n)))
    ell_n = np.exp(u_n)
    fig, ax = plt.subplots(ncols=3, nrows=3, figsize=(15, 15))
    ax[0, 0].imshow(ri_n_scalled, cmap=plt.cm.Greys_r)
    ax[0, 0].set_title('Reconstructed Image From vF---  RI')
    ax[0, 1].imshow(target_image, cmap=plt.cm.Greys_r)
    ax[0, 1].set_title('Target Image ---  TI')
    if isSinogram:
        ax[0, 2].imshow(fbp, cmap=plt.cm.Greys_r)
        ax[0, 2].set_title('FBP --- RIO')
    else:
        ax[0, 2].imshow(ri_or_n, cmap=plt.cm.Greys_r)
        ax[0, 2].set_title('Reconstructed Image From vFOriginal --- RIO')

    ax[1, 0].imshow(np.abs(target_image - ri_n_scalled), cmap=plt.cm.Greys_r)
    ax[1, 0].set_title('Absolute error--- RI-TI')
    ax[1, 1].imshow(np.abs(ri_or_n - target_image), cmap=plt.cm.Greys_r)
    ax[1, 1].set_title('Absolute error--- RIO-TI')
    ax[1, 2].imshow(np.abs(ri_n_scalled - ri_or_n), cmap=plt.cm.Greys_r)
    ax[1, 2].set_title('Absolute error--- RI-RIO')
    ax[2, 0].imshow(u_n, cmap=plt.cm.Greys_r)
    ax[2, 0].set_title('Field u--- u')
    ax[2, 1].imshow(ell_n, cmap=plt.cm.Greys_r)
    ax[2, 1].set_title('Length Scale of v--- ell')

    if isSinogram:
        im = ax[2, 2].imshow(sinogram, cmap=plt.cm.Greys_r)
        ax[2, 2].set_title('Measurement (Sinogram) --- CI')
    else:
        im = ax[2, 2].imshow(corrupted_image, cmap=plt.cm.Greys_r)
        ax[2, 2].set_title('Measurement (corrupted_image) --- CI')

    fig.colorbar(im, ax=ax[:, :], shrink=0.8)
    fig.savefig(str(SimulationResult_dir / 'Result.pdf'), bbox_inches='tight')
    for ax_i in ax.flatten():
        extent = ax_i.get_window_extent().transformed(
            fig.dpi_scale_trans.inverted())
        #    print(ax_i.title.get_text())
        fig.savefig(str(SimulationResult_dir / ax_i.title.get_text()) + '.pdf',
                    bbox_inches=extent.expanded(1.2, 1.2))

    return file
예제 #5
0
    if i + 1 % 5 == 0:
        acceptancePercentage = accepted_count / (i + 1)
        pcn.adapt_beta(acceptancePercentage)

#%%
mean_field = util.symmetrize(
    cp.asarray(np.mean(Layers[-1].samples_history[:n_samples, :], axis=0)))
u_mean_field = util.symmetrize(
    cp.asarray(np.mean(Layers[0].samples_history[:n_samples, :], axis=0)))
vF = mean_field.reshape(2 * f.basis_number - 1,
                        2 * f.basis_number - 1,
                        order=im.ORDER).T
uF = u_mean_field.reshape(2 * f.basis_number - 1,
                          2 * f.basis_number - 1,
                          order=im.ORDER).T
vForiginal = util.symmetrize_2D(
    f.fourierTransformHalf(measurement.target_image))
vFwithNoise = util.symmetrize_2D(
    f.fourierTransformHalf(measurement.corrupted_image))
vFn = cp.asnumpy(vF)
uFn = cp.asnumpy(uF)
vForiginaln = cp.asnumpy(vForiginal)
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(20, 20))
ax[0, 0].imshow(vFn.real, cmap=plt.cm.Greys_r)
ax[0, 1].imshow(vForiginaln.real, cmap=plt.cm.Greys_r)
ax[1, 0].imshow(vFn.imag, cmap=plt.cm.Greys_r)
ax[1, 1].imshow(vForiginaln.imag, cmap=plt.cm.Greys_r)

fig.savefig(str(simResultPath / 'FourierDomain.pdf'), bbox_inches='tight')
#%%
reconstructed_image = f.inverseFourierLimited(vF[:, f.basis_number - 1:])
reconstructed_image_length_scale = f.inverseFourierLimited(
예제 #6
0
 def symmetrize_2D(self,uHalf2D):
     return util.symmetrize_2D(uHalf2D)
예제 #7
0
 def constructMat(self,uHalf2D,power):
     U = self.constructU(util.symmetrize_2D(uHalf2D))
     exp_power_U = util.expm(power*U) #sla.expm(power*cp.asnumpy(U))
     # res = cp.asarray(exp_power_U,dtype=cp.complex64)*self._Umask
     res = exp_power_U*self._Umask
     return res