bm3d图像去噪算法C++代码


三维块匹配(BM3D)算法: 它首先把图像分成一定大小的块,根据图像块之间的相似性,把具有相似结构的二维图像块组合在一起形成三维数组,然后用联合滤波的方法对这些三维数组进行处理,最后,通过逆变换,把处理后的结果返回到原图像中,从而得到去噪后的图像。该方法确实有效,它不仅有一个较高的信噪比,而且视觉效果也很好,是最经典的算法之一。此为BM3D算法的C++完整代码
资源截图
代码片段和文件信息
/*
 * Copyright (c) 2011 Marc Lebrun 
 * All rights reserved.
 *
 * This program is free software: you can use modify and/or
 * redistribute it under the terms of the GNU General Public
 * License as published by the Free Software Foundation either
 * version 3 of the License or (at your option) any later
 * version. You should have received a copy of this license along
 * this program. If not see .
 */


/**
 * @file bm3d.cpp
 * @brief BM3D denoising functions
 *
 * @author Marc Lebrun 
 **/

#include 
#include 
#include 

#include “bm3d.h“
#include “utilities.h“
#include “lib_transforms.h“

#define SQRT2     1.414213562373095
#define SQRT2_INV 0.7071067811865475
#define YUV       0
#define YCBCR     1
#define OPP       2
#define RGB       3
#define DCT       4
#define BIOR      5
#define HADAMARD  6

#ifdef _OPENMP
    #include 
#endif

 using namespace std;

 bool ComparaisonFirst(pair pair1 pair pair2)
{
return pair1.first < pair2.first;
}

/** ----------------- **/
/** - Main function - **/
/** ----------------- **/
/**
 * @brief run BM3D process. Depending on if OpenMP is used or not
 *        and on the number of available threads it divides the noisy
 *        image in sub_images to process them in parallel.
 *
 * @param sigma: value of assumed noise of the noisy image;
 * @param img_noisy: noisy image;
 * @param img_basic: will be the basic estimation after the 1st step
 * @param img_denoised: will be the denoised final image;
 * @param width height chnls: size of the image;
 * @param useSD_h (resp. useSD_w): if true use weight based
 *        on the standard variation of the 3D group for the
 *        first (resp. second) step otherwise use the number
 *        of non-zero coefficients after Hard Thresholding
 *        (resp. the norm of Wiener coefficients);
 * @param tau_2D_hard (resp. tau_2D_wien): 2D transform to apply
 *        on every 3D group for the first (resp. second) part.
 *        Allowed values are DCT and BIOR;
 * @param color_space: Transformation from RGB to YUV. Allowed
 *        values are RGB (do nothing) YUV YCBCR and OPP.
 *
 * @return EXIT_FAILURE if color_space has not expected
 *         type otherwise return EXIT_SUCCESS.
 **/
int run_bm3d(
    const float sigma
   vector &img_noisy
   vector &img_basic
   vector &img_denoised
   const unsigned width
   const unsigned height
   const unsigned chnls
   const bool useSD_h
   const bool useSD_w
   const unsigned tau_2D_hard
   const unsigned tau_2D_wien
   const unsigned color_space
){
    //! Parameters
    const unsigned nHard = 16; //! Half size of the search window
    const unsigned nWien = 16; //! Half size of the search window
    const unsigned kHard = (tau_2D_hard == BIOR || sigma < 40.f ? 8 : 12); //! Must be a power of 2 if tau_2D_hard == BIOR
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-12-17 13:01  bm3d_src
     目录           0  2018-12-17 15:06  bm3d_src.vs
     文件          44  2018-12-17 13:01  bm3d_src.vsProjectSettings.json
     文件         114  2018-12-17 15:06  bm3d_src.vsVSWorkspaceState.json
     目录           0  2018-12-17 13:01  bm3d_src.vsm3d_src
     目录           0  2018-12-17 15:06  bm3d_src.vsm3d_srcv15
     文件       22016  2018-12-17 15:06  bm3d_src.vsm3d_srcv15.suo
     文件     6287360  2018-12-17 15:06  bm3d_src.vsm3d_srcv15Browse.VC.db
     目录           0  2018-12-17 13:01  bm3d_src.vsm3d_srcv15ipch
     目录           0  2018-12-17 13:02  bm3d_src.vsm3d_srcv15ipchAutoPCH
     目录           0  2018-12-17 13:05  bm3d_src.vsm3d_srcv15ipchAutoPCH125b3706f1ad177c
     文件    32309248  2018-12-17 13:05  bm3d_src.vsm3d_srcv15ipchAutoPCH125b3706f1ad177cUTILITIES.ipch
     目录           0  2018-12-17 13:05  bm3d_src.vsm3d_srcv15ipchAutoPCH4125cd27a26487a9
     文件    33357824  2018-12-17 13:05  bm3d_src.vsm3d_srcv15ipchAutoPCH4125cd27a26487a9MAIN.ipch
     目录           0  2018-12-17 13:02  bm3d_src.vsm3d_srcv15ipchAutoPCH937b23f2080d25da
     文件    35127296  2018-12-17 13:02  bm3d_src.vsm3d_srcv15ipchAutoPCH937b23f2080d25daBM3D.ipch
     目录           0  2018-12-17 13:02  bm3d_src.vsm3d_srcv15ipchAutoPCHdcea950fba765a45
     文件    24379392  2018-12-17 13:02  bm3d_src.vsm3d_srcv15ipchAutoPCHdcea950fba765a45LIB_TRANSFORMS.ipch
     文件       77824  2018-12-17 15:06  bm3d_src.vsslnx.sqlite
     文件        1100  2011-12-15 21:32  bm3d_srcMakefile
     文件        3372  2012-04-13 22:34  bm3d_srcREADME.txt
     文件       54878  2012-04-14 00:36  bm3d_srcm3d.cpp
     文件        4788  2012-04-13 23:35  bm3d_srcm3d.h
     文件       22401  2010-09-07 21:03  bm3d_srcio_png.c
     文件         753  2010-09-07 21:03  bm3d_srcio_png.h
     文件       13021  2012-04-13 23:08  bm3d_srclib_transforms.cpp
     文件        1500  2012-04-13 23:08  bm3d_srclib_transforms.h
     文件        6889  2012-04-13 23:09  bm3d_srcmain.cpp
     文件        5065  2010-09-18 07:30  bm3d_srcmt19937ar.c
     文件         250  2010-09-18 07:30  bm3d_srcmt19937ar.h
     文件       21659  2012-04-13 23:09  bm3d_srcutilities.cpp
............此处省略1个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)