/*
* deblur_test.cpp
* Created on: 2022年8月22日
* Author: root
*/
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <fftw3.h>
using namespace cv;
using namespace std;
#define M_2PI 6.28318530717958647692528676655900576
//#define M_PI 3.14159265358979323846264338327950288
typedef enum {
NOISEMODEL_L2,
NOISEMODEL_L1,
NOISEMODEL_POISSON
} noisemodel;
struct dim_t {
int h;
int w;
int d;
bool operator==(const dim_t &other) const {
return h == other.h && w == other.w && d == other.d;
}
};
struct tag_tvregopt
{
float Lambda;
const float *VaryingLambda;
int LambdaWidth;
int LambdaHeight;
const float *Kernel;
int KernelWidth;
int KernelHeight;
float Tol;
float Gamma1;
float Gamma2;
int MaxIter;
noisemodel NoiseModel;
int (*PlotFun)(int, int, float, const float*, int, int, int, void*);
void *PlotParam;
char *AlgString;
};
typedef struct tag_tvregopt tvregopt;
typedef float numcomplex[2];
#define _TVREG_CONCAT(A,B) A ## B
#define NUM_SINGLE
#define TVREG_DECONV
#define TVREG_USEZ
#ifdef NUM_SINGLE
#define FFT(S) _TVREG_CONCAT(fftwf_,S)
#else
#define FFT(S) _TVREG_CONCAT(fftw_,S)
#endif
typedef struct
{
float x; /**< x-component */
float y; /**< y-component */
} numvec2;
typedef struct tag_tvregsolver
{
float *u; /**< Current restoration solution */
const float *f; /**< Input image */
numvec2 *d; /**< Current solution of d */
numvec2 *dtilde; /**< Bregman variable for d constraint */
float *Ku; /**< Convolution of kernel with u */
float fNorm; /**< L2 norm of f */
float Alpha; /**< Lambda/Gamma1 or Gamma2/Gamma1 */
int Width; /**< Image width */
int Height; /**< Image height */
int PadWidth; /**< Padded image width */
int PadHeight; /**< Padded image height */
int NumChannels; /**< Number of image channels */
tvregopt Opt; /**< Solver options */
int UseZ; /**< True if selected algorithm uses z */
#ifdef TVREG_USEZ
float *z; /**< Current solution of z */
float *ztilde; /**< Bregman variable for z constraint */
#endif
#ifdef TVREG_DECONV
float *A, *B; /**< Spatial FFTW buffers */
float *ATrans, *BTrans; /**< Spectral FFTW buffers */
float *DenomTrans; /**< Precomputation for u subproblem */
float *KernelTrans; /**< Convolution kernel transform */
FFT(plan) TransformA; /**< Forward transform plan A -> ATrans */
FFT(plan) TransformB; /**< Forward transform plan B -> BTrans */
FFT(plan) InvTransformA; /**< Inverse transform plan ATrans -> A */
FFT(plan) InvTransformB; /**< Inverse transform plan BTrans -> B */
#endif
} tvregsolver;
typedef float (*usolver)(tvregsolver*);
typedef void (*zsolver)(tvregsolver*);
#define ATTRIBUTE_UNUSED
#define ALGSTRING_SIZE 128
void getinPlaceIFFTPlan(Size inputsize,fftwf_plan &theplan);
void getStep12inPlaceFFTPlan(Size inputsize,fftwf_plan &theplan);
void fftforwardc2c(fftwf_plan theplan,Mat incirclepadimg,vector<complex<float> > &planes_fft);
void Ifftforwardc2c(vector<complex<float> > fftinputreal,Size inputsize,Mat &ifftoutimglast);
void pad_dft(fftwf_plan theplan,Size inputsize,Mat dx,cv::Mat *fftimgpad);
void fftwf_dft(fftwf_plan theplan,Mat imgneeddft,cv::Mat *planes);
void fftwf_idft(cv::Mat *planes,Mat &img_idft);
void fftwf_idft_new(cv::Mat *planes,Mat &img_idft);
//void fftwf_idft(fftwf_plan &theplan_back,cv::Mat *planes,Mat &img_idft);
int bestDownSize(int size,int &newsize);
void smoothBorders(fftwf_plan theplan,Mat inputimg,Mat kernelimg,Mat &outimglast,int iterationsnum=1);
void imgPreprocess(fftwf_plan &theplan,Mat input_v,int kernelsize,Mat &outimg);
void estimateKernelOneTime(fftwf_plan theplan,Mat inputimg,Mat &gotkernel,Mat &inputimgcopy,
float &reallambda,int iterations=2,bool infoverbose=true,bool savetmpimgs=false);
void estimateSharp(fftwf_plan theplan,Mat input,Mat blenddft,Mat &blurimg,Mat kernelimg,float lambda);
void estimateKernelFromFFT(fftwf_plan theplan,Mat preprocessimg,vector<vector<complex<float> > > primerfft,Mat &kernelimg,bool removesingle=true);
void pad_dft_complex(fftwf_plan theplan,Size inputsize,Mat thekernel,vector<complex<float> > &fftimgpad);
void shift_fft(Mat input,Mat &shiftimg);
void sharppredictor(fftwf_plan theplan,Mat preInputimg,Mat &blendkernelsdft);
void estimatefftkernel(fftwf_plan theplan,Mat preInputimg,vector<vector<complex<float> > > &gradientsfft);
////////////multiscale kernel////////////////////
static void bicubic_interpolation(float *result,float *img, int w, int h, int pd, float x, float y);
static void interpolate_vec(float *out, float *x, int w, int h, int pd,float p, float q, int m);
void zoom2(float *y, const float *x, int W, int H, int pd, int w, int h, float n, int zt);
///////////////////////////////deconv //////////////////////////
int TvRestoreSimplePlot(int State, int Iter, float Delta,
ATTRIBUTE_UNUSED const float *u,ATTRIBUTE_UNUSED int Width,ATTRIBUTE_UNUSED int Height,
ATTRIBUTE_UNUSED int NumChannels,ATTRIBUTE_UNUSED void *Param);
void removeDeconvPad(Mat paddeconv,cv::Size kernelsize,int origimaxvalue,Mat &outimg);
void padblurredimg(Mat blurredimg,Mat kernel,int &max_value,Mat &blurredstandard,Mat &outimg);
tvregopt *TvRegNewOpt(const float *Kernel,int KernelWidth,int KernelHeight, float Lambda, int MaxIter
, float Gamma1, float Tol);
void TvRegSetPlotFun(tvregopt *Opt,
int (*PlotFun)(int, int, float, const float*, int, int, int, void*),
void *PlotParam);
int TvRestore(float *u,const float *f,int Width,int Height,int NumChannels,tvregopt *Opt);
void TvRegFreeOpt(tvregopt *Opt);
void splitBregmanAlgo(Mat blurpad,Mat kernelimg,Mat &outimg,int iteranum=7,float lambda=3000.0f,float beta=30.0f);
static int TvRestoreChooseAlgorithm(int *UseZ, int *DeconvFlag, int *DctFlag,
usolver *USolveFun, zsolver *ZSolveFun, const tvregopt *Opt);
static int IsSymmetric(const float *Kernel, int KernelWidth, int KernelHeight);
static void DSolve(tvregsolver *S);
static float UUpdate(tvregsolver *S);
static void UTransSolveFourier(numcomplex *BTrans, float *B, FFT(plan) TransformB,
numcomplex *ATrans, const numvec2 *dtilde,
const float *DenomTrans, int Width, int Height, int NumChannels);
static void Divergence(float *DivV, int DivWidth, int DivHeight,
const numvec2 *V, int Width, int Height, int NumChannels);
static void SymmetricPadding(float *Dest, const float *Src,
int Width, int Height, int NumChannels);
static float UDeconvDct(tvregsolver *S);
static float UDeconvFourier(tvregsolver *S);
static int InitDeconvDct(tvregsolver *S);
static int InitDeconvFourier(tvregsolver *S);
////////////////////////////////////////////////////////////////////////////
void gaussian_downsample(Mat &in, float factor);
void upsample(Mat &outlast,Mat _in,float factor,int targetw,int targeth,int interp=2);;
void downscale_image(float *out,float *in,int outw,int outh,int inw,int inh,float scalestep);
void downsa_v2(float *out,float *in,int outw,int outh,int inw,int inh);
void gblur_gray(float *y, float *x, int w, int h, float s);
float interpolate_float_image_bilinearly(float *x,int w,int h,float i,float j);
float extend_float_image_constant(flo
没有合适的资源?快使用搜索试试~ 我知道了~
用盲去模糊算法实例测试
共7个文件
png:6个
cpp:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 2 下载量 35 浏览量
2023-03-01
17:58:32
上传
评论 1
收藏 2.24MB ZIP 举报
温馨提示
盲去模糊算法,使用了优化后的Split Bregman,单尺度计算模糊核,然后利用模糊核去模糊。效果如https://blog.csdn.net/wd1603926823/article/details/45271889 中所示。
资源推荐
资源详情
资源评论
收起资源包目录
blinddeblur.zip (7个子文件)
blinddeblur
src
deblur_test.cpp 90KB
resultimg-16bit
3.png 416KB
0.png 413KB
1.png 287KB
5.png 463KB
4.png 447KB
2.png 274KB
共 7 条
- 1
资源评论
- m0_463339932023-03-22资源内容详实,描述详尽,解决了我的问题,受益匪浅,学到了。
- evergarden92023-05-06资源值得借鉴的内容很多,那就浅学一下吧,值得下载!
元气少女缘结神
- 粉丝: 6065
- 资源: 65
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功