示例#1
0
def fig_5c():
    wl_name = 'haar'
    lp_d, hp_d, lp_r, hp_r = map(np.array, pywt.Wavelet(wl_name).filter_bank)
    num_levels = 2
    res = 32
    slice = int(res / 2)
    p = 0.5

    wavelet_slice = generateWavelets(lp_d, hp_d, res, fine=0)
    im_vol = np.zeros((res, res, res))
    im_vol[slice, :, :] = idwt2(wavelet_slice, lp_r, hp_r, num_levels)

    fft_vol = np.fft.fftn(im_vol, axes=(0, 1, 2))
    mask = np.random.choice([0, 1], size=(res, res), p=[1 - p, p])

    us_fft_vol = np.copy(fft_vol) * 0

    print(mask.shape)
    for i in range(res):
        us_fft_vol[i, :, :] = np.multiply(fft_vol[i, :, :], mask)

    ifft_vol = np.fft.ifftn(us_fft_vol, axes=(0, 1, 2))

    dwt_slice = dwt2(np.real(ifft_vol[slice, :, :]), lp_d, hp_d, num_levels)

    plot3D(np.abs(dwt_slice), title="3D_coarse.png")
示例#2
0
def generateWavelets(lp_d, hp_d, _res=100, levels=2, fine=0, padding=0):
    img = generateImage(_res)
    wv = dwt2(img, lp_d, hp_d, levels)
    z = np.zeros((_res + padding, _res + padding))
    if fine == 0:
        p = int(_res / 4)
        z[:p, p:2 * p] = np.abs(wv[:p, p:2 * p])
    else:
        p = int(_res / 2)
        z[p:, p:] = wv[p:, p:]
    z = z / np.max(z)
    return z
示例#3
0
def fig_4_b():
    wl_name = 'haar'
    lp_d, hp_d, lp_r, hp_r = map(np.array, pywt.Wavelet(wl_name).filter_bank)
    num_levels = 2

    wv_img1 = generateWavelets(lp_d, hp_d, levels=num_levels, fine=0)

    # step 1: IDWT of wavelet domain
    iwv_img = idwt2(wv_img1, lp_r, hp_r, levels=num_levels)

    # step 2: FFT of image domain
    fft_img = np.fft.fft2(iwv_img)

    # step 3: random undersampling of FFT domain
    us_fft = randomUndersample(fft_img, 0.2)

    # step 4: IFFT of undersampled FFT domain
    ifft_img = np.real(np.fft.ifft2(us_fft))

    # step 5: DWT of image domain
    wv_img2 = dwt2(ifft_img, lp_d, hp_d, levels=num_levels)

    fig = plt.figure(figsize=plt.figaspect(2 / 3))

    X = np.arange(0, 100)
    Y = np.arange(0, 100)
    X, Y = np.meshgrid(X, Y)

    print(wv_img1.shape)
    ax = fig.add_subplot(2, 3, 1, projection='3d')
    surf = ax.plot_surface(X, Y, wv_img1, color='r')

    ax = fig.add_subplot(2, 3, 2, projection='3d')
    surf = ax.plot_surface(X, Y, iwv_img, color='r')

    ax = fig.add_subplot(2, 3, 3, projection='3d')
    surf = ax.plot_surface(X, Y, np.real(np.fft.fftshift(fft_img)), color='r')

    ax = fig.add_subplot(2, 3, 6, projection='3d')
    surf = ax.plot_surface(X, Y, np.real(np.fft.fftshift(us_fft)), color='r')

    ax = fig.add_subplot(2, 3, 5, projection='3d')
    surf = ax.plot_surface(X, Y, ifft_img, color='r')

    ax = fig.add_subplot(2, 3, 4, projection='3d')
    surf = ax.plot_surface(X, Y, wv_img2, color='r')

    fig.tight_layout()

    fig.savefig("4b_fine.png")

    plt.show()
示例#4
0
def fig_5a():
    wl_name = 'haar'
    lp_d, hp_d, lp_r, hp_r = map(np.array, pywt.Wavelet(wl_name).filter_bank)
    num_levels = 2
    res = 32
    slice = int(res / 2)
    p = 0.5

    mask = np.random.choice([0, 1], size=(res, ), p=[1 - p, p])
    mask = np.tile(mask, (res, 1)).T

    wavelet_slice = generateWavelets(lp_d, hp_d, res, fine=1)
    im_vol = np.zeros((res, res, res))
    im_vol[slice, :, :] = idwt2(wavelet_slice, lp_r, hp_r, num_levels)

    fft_vol = np.fft.fftn(im_vol, axes=(1, 0))

    us_fft_vol = np.copy(fft_vol) * 0
    us_fft_vol[slice, :, :] = np.multiply(fft_vol[slice, :, :], mask)

    ifft_vol = np.fft.ifftn(us_fft_vol, axes=(1, 0))
    dwt_slice = dwt2(np.real(ifft_vol[slice, :, :]), lp_d, hp_d, num_levels)

    plot3D(np.abs(dwt_slice), "Single_slice_coarse")