Example #1
0
def run_bm3d(noisy_im, sigma, n_H, k_H, N_H, p_H, tauMatch_H, useSD_H,
             tau_2D_H, lambda3D_H, n_W, k_W, N_W, p_W, tauMatch_W, useSD_W,
             tau_2D_W):
    k_H = 8 if (tau_2D_H == 'BIOR' or sigma < 40.) else 12
    k_W = 8 if (tau_2D_W == 'BIOR' or sigma < 40.) else 12

    noisy_im_p = symetrize(noisy_im, n_H)
    img_basic = bm3d_1st_step_block_mean(sigma, noisy_im_p, n_H, k_H, N_H, p_H,
                                         lambda3D_H, tauMatch_H, useSD_H,
                                         tau_2D_H)
    img_basic = img_basic[n_H:-n_H, n_H:-n_H]

    img_basic_p = symetrize(img_basic, n_W)
    noisy_im_p = symetrize(noisy_im, n_W)
    img_denoised = bm3d_2nd_step_block_mean(sigma,
                                            noisy_im_p,
                                            img_basic_p,
                                            n_W,
                                            k_W,
                                            N_W,
                                            p_W,
                                            tauMatch_W,
                                            useSD_W,
                                            tau_2D_W,
                                            block_mean=True)
    img_denoised = img_denoised[n_W:-n_W, n_W:-n_W]

    return img_basic, img_denoised
Example #2
0
def hyper_run_bm3d_tf(im_dir, im_name, sigma, nH, kH, NH, pH, tauMatchH,
                      useSDH, tau_2DH, lambda3DH, nW, kW, NW, pW, tauMatchW,
                      useSDW, lamb):
    nW = 2 * kW
    im = cv2.imread('test_data/image/' + im_name, cv2.IMREAD_GRAYSCALE)
    im_noisy = cv2.imread(
        'noisy_image_and_1st_res/' + im_name[:-4] + '_sigma' + str(sigma) +
        '.png', cv2.IMREAD_GRAYSCALE)
    im_basic = cv2.imread(
        'noisy_image_and_1st_res/' + im_name[:-4] + '_sigma' + str(sigma) +
        '_1st.png', cv2.IMREAD_GRAYSCALE)

    im_noisy_p = symetrize(im_noisy, nW)
    im_basic_p = symetrize(im_basic, nW)
    im_denoised = bm3d_2nd_step_trendfilter3D(im_noisy_p, im_basic_p, nW, kW,
                                              NW, pW, tauMatchW, useSDW, lamb)
    im_denoised = im_denoised[nW:-nW, nW:-nW]

    im_basic = (np.clip(im_basic, 0, 255)).astype(np.uint8)
    im_denoised = (np.clip(im_denoised, 0, 255)).astype(np.uint8)

    psnr = compute_psnr(im, im_denoised)
    return im_basic, im_denoised, psnr
Example #3
0
if __name__ == '__main__':
    from psnr import compute_psnr
    from utils import add_gaussian_noise, symetrize

    # <hyper parameter> -------------------------------------------------------------------------------
    sigma = 20

    nWien = 16
    kWien = 8
    NWien = 16
    pWien = 3
    tauMatchWien = 400 if sigma < 35 else 3500  # ! threshold determinates similarity between patches
    useSD_w = True
    tau_2D_wien = 'DCT'
    # <\ hyper parameter> -----------------------------------------------------------------------------

    img = cv2.imread('Cameraman256.png', cv2.IMREAD_GRAYSCALE)
    img_noisy = cv2.imread('image_noise.png', cv2.IMREAD_GRAYSCALE)
    img_basic = cv2.imread('y_basic.png', cv2.IMREAD_GRAYSCALE)

    img_basic_p = symetrize(img_basic, nWien)
    img_noisy_p = symetrize(img_noisy, nWien)
    img_denoised = bm3d_2nd_step(sigma, img_noisy_p, img_basic_p, nWien, kWien,
                                 NWien, pWien, tauMatchWien, useSD_w,
                                 tau_2D_wien)
    img_denoised = img_denoised[nWien:-nWien, nWien:-nWien]

    psnr_2st = compute_psnr(img, img_denoised)
    print('img and img_denoised PSNR: ', psnr_2st)
    # cv2.imwrite('y_final.png', img_denoised.astype(np.uint8))
Example #4
0
    from utils import add_gaussian_noise, symetrize

    # <hyper parameter>
    ref_i, ref_j = 196, 142
    # ref_i, ref_j = 271, 206

    kHW = 8
    NHW = 3
    nHW = 16
    tauMatch = 2500
    # <hyper parameter \>

    im = cv2.imread('test_data/image/Cameraman.png', cv2.IMREAD_GRAYSCALE)
    im_noisy = add_gaussian_noise(im, 10, seed=1)

    img_noisy_p = symetrize(im_noisy, nHW)
    near_pij, threshold_count = precompute_BM(img_noisy_p,
                                              kHW=kHW,
                                              NHW=NHW,
                                              nHW=nHW,
                                              tauMatch=tauMatch)

    im = cv2.cvtColor(img_noisy_p, cv2.COLOR_GRAY2RGB)
    # <draw search area>
    points_list = [(ref_j - nHW, ref_i - nHW), (ref_j + nHW, ref_i - nHW),
                   (ref_j - nHW, ref_i + nHW), (ref_j + nHW, ref_i + nHW)]
    for point in points_list:
        cv2.circle(im, point, 0, (0, 0, 255), 1)
    # <draw search area \>

    # <draw reference patch>
Example #5
0
    img_basic = numerator / denominator
    return img_basic


if __name__ == '__main__':
    from utils import add_gaussian_noise, symetrize

    # <hyper parameter> -------------------------------------------------------------------------------
    sigma = 20

    nHard = 16
    kHard = 8
    NHard = 16
    pHard = 3
    lambdaHard3D = 2.7  # ! Threshold for Hard Thresholding
    tauMatchHard = 2500 if sigma < 35 else 5000  # ! threshold determinates similarity between patches
    useSD_h = False
    tau_2D_hard = 'BIOR'
    # <\ hyper parameter> -----------------------------------------------------------------------------

    img = cv2.imread('test_data/image/Cameraman.png', cv2.IMREAD_GRAYSCALE)
    img_noisy = add_gaussian_noise(img, sigma)
    # img_noisy = cv2.imread('matlab_officialfg_compare/noisy_image.png', cv2.IMREAD_GRAYSCALE)

    img_noisy_p = symetrize(img_noisy, nHard)
    img_basic = bm3d_1st_step(sigma, img_noisy_p, nHard, kHard, NHard, pHard,
                              lambdaHard3D, tauMatchHard, useSD_h, tau_2D_hard)
    img_basic = img_basic[nHard:-nHard, nHard:-nHard]

    # cv2.imwrite('y_basic.png', img_basic.astype(np.uint8))
Example #6
0
    sigma = 10

    nHard = 16
    kHard = 8
    NHard = 16
    # pHard = 3
    pHard = 1
    useSD_h = False
    tau_2D_hard = 'BIOR'

    # <\ hyper parameter> -----------------------------------------------------------------------------

    img = cv2.imread('Cameraman256.png', cv2.IMREAD_GRAYSCALE)
    # img = cv2.resize(img, (128, 128))
    # img = add_gaussian_noise(img, sigma)

    img_noisy = symetrize(img, nHard)

    img_basic = bm3d_1st_step(sigma, img_noisy, nHard, kHard, NHard, pHard,
                              useSD_h, tau_2D_hard)

    img_basic = img_basic[nHard:-nHard, nHard:-nHard]

    diff = np.abs(img - img_basic)
    print('max: ', np.max(diff))
    print('sum: ', np.sum(diff))

    cv2.imwrite('aggregation_test.png', img_basic)
    cv2.imshow('', img_basic)
    cv2.waitKey()