ipol上的BM3D在VS2015下编译使用

本文详细介绍BM3D算法在VS2015下的编译流程,包括解决libpng和fftw库依赖、OpenMP支持等问题,以及如何配置和运行代码,提供了一个高效去噪算法的实现案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ipol上的BM3D在VS2015下编译使用

主要是参考了《Windows下编译测试BM3D算法效果》这篇文章,它在输出png结果的时候,遇到了问题,使用最新(lpng1634)就没问题了,所以这里也进行下更新。实际上github上面BM3D的代码有很多,比如

  • HomeOfVapourSynthEvolution/VapourSynth-BM3D
    这个应该是VapourSynth开源视频处理软件里面的一个子功能,实现了BM3D和VBM3D的算法,并且封装得比较严实,不知道是否做了代码优化;
  • yspMing/BM3D
    这个还是修改自ipol上的BM3D源码,然后使用opencv来存储图像的;
  • qianghaowork/BM3Ddenoising
    这个用了opencv,然后里边的测试结果如下所示:Execution time ~ 1min ~ 3 min ~ 10min,这远远慢于ipol里面的代码。

以上就是github里面使用c++实现BM3D算法、star数最多、实现比较靠谱的仓库,跟ipol的代码相比,考虑到代码可读性、执行效率等因素,还是推荐采用ipol的代码,学习起来更加方便,而且如果要进行改进,以此为基础也是很不错的。

一、算法、代码介绍

在我之前的文章(BM3D(Block-Matching and 3D filtering)读后感)里面,已经详细地对算法进行了说明,这里还是可以提一下,BM3D是目前公认的去噪效果最好的算法之一:

The baseline for high-quality image denoising using patches remains block matching with 3D filtering (BM3D) [2]. Knaus C, Zwicker M. Progressive Image Denoising[J]. Image Processing IEEE Transactions on, 2014, 23(7):3114-3125.

项目地址(http://www.ipol.im/pub/art/2012/l-bm3d/)

代码地址(http://www.ipol.im/pub/art/2012/l-bm3d/bm3d_src.zip)

论文地址(http://www.cs.tut.fi/~foi/GCF-BM3D/BM3D_TIP_2007.pdf)

1. 代码依赖

libpng library and the fftw library,这里编译libpng的dll和lib要走点弯路。

2. OpenMP支持

在VS里面把OpenMP打开,就可以把输入图像分割成n块(处理器核数)同时处理,速度更快。

3. 输入与输出

./BM3Ddenoising
The generic way to run the code is:

./BM3Ddenoising cinput.png sigma ImNoisy.png ImBasic.png ImDenoised.png ImDiff.png ImBias.png
ImDiffBias.png computeBias 2DtransformStep1 useSD1 2DtransformStep2 useSD2 ColorSpace

with :

  • cinput.png is a noise-free image;
  • sigma is the value of the noise which will be added to cinput.png;
  • ImNoisy.png will contain the noisy image;
  • ImBasic.png will contain the result of the first step of the algorithm;
  • ImDenoised.png will contain the final result of the algorithm;
  • ImDiff.png will contain the difference between cinput.png and ImDenoised.png;
  • ImBias.png will contain the result of the algorithm applied on cinput.png;
  • ImDiffBias.png will contain the difference between cinput.png and ImBias.png;
  • computeBias : see (3);
  • 2DtransformStep1: choice of the 2D transform which will be applied in the first step of the
    algorithm. See (4);
  • useSD1 : see (1) below;
  • 2DtransformStep2: choice of the 2D transform which will be applied in the second step of the
    algorithm. See (4);
  • useSD2 : see (2);
  • ColorSpace : choice of the color space on which the image will be applied. See (5).

Example, run
./BM3Ddenoising cinput.png 10 ImNoisy.png ImBasic.png ImDenoised.png ImDiff.png ImBias.png
ImDiffBias.png 1 bior 0 dct 1 opp

二、VS2015编译运行

平台:WIN7 x64,VS2015
建好工程,这里我用的是文件-新建-从现有代码创建项目加入png和fftw的第三方库就可以了。

1. fftw库配置

现在64位最新版本是fftw-3.3.5-dll64,里面已经包含了dll文件,将dll文件的目录添加到系统环境变量里面就可以了,如果还需要lib的话,可以参考这篇文章libfftw3-3之正确生成x64和x32的lib文件,操作详细有效。

.\VS15\VC\bin cmd
lib /machine:x64 /def:libfftw3-3.def
lib /machine:x64 /def:libfftw3f-3.def
lib /machine:x64 /def:libfftw3l-3.def

将这些加到依赖里面,这里还需要修改几处代码:

// 源码
//! Allocate plan for FFTW library

//fftwf_plan plan_2d_for_1[nb_threads];
//fftwf_plan plan_2d_for_2[nb_threads];
//fftwf_plan plan_2d_inv[nb_threads];

// 改成如下

fftwf_plan* plan_2d_for_1 = new fftwf_plan[nb_threads];
fftwf_plan* plan_2d_for_2 = new fftwf_plan[nb_threads];
fftwf_plan* plan_2d_inv = new fftwf_plan[nb_threads];

2. 使用头文件unistd.h

在默认库文件夹下(例如D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\)添加一个unistd.h文件即可,其内容如下:

#ifndef _UNISTD_H
#define _UNISTD_H
#include <io.h>
#include <process.h>
#endif /* _UNISTD_H */

3. libpng库配置

这个东西主要是为了图像的读写操作,实际上你可以把这个给换成其它方法,比如opencv,BM3D的核心代码是使用vector将图像拉成一维矩阵来存储的,所以用不用libpng都可以。如果非要,那就去libpng的官网上下载就可以了。这里我使用的是libpng1.6.34,里面包含有lpng1634和zlib-1.2.8,在.\lpng1634\projects\vstudio里直接双击打开vstudio.sln,打开后生成lib就可以了,这里需要注意一下的是,它默认是x86的,如果是x64平台,需要自己在配置管理器里面添加x64的配置。

用libpng1.6.34是没啥问题的,png图像能读写。

4. OpenMP的for循环使用整形

出错的地方,修改成整形就好了。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值