Commit e81892a4 authored by Zhou Chao's avatar Zhou Chao

improve l0smooth coding style

parent bbe38930
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <vector> #include <vector>
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp> #include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv; using namespace cv;
using namespace std; using namespace std;
...@@ -45,7 +46,8 @@ using namespace std; ...@@ -45,7 +46,8 @@ using namespace std;
namespace namespace
{ {
class ParallelDft : public ParallelLoopBody { class ParallelDft : public ParallelLoopBody
{
private: private:
vector<Mat> src_; vector<Mat> src_;
public: public:
...@@ -62,7 +64,8 @@ namespace ...@@ -62,7 +64,8 @@ namespace
} }
}; };
class ParallelIdft : public ParallelLoopBody { class ParallelIdft : public ParallelLoopBody
{
private: private:
vector<Mat> src_; vector<Mat> src_;
public: public:
...@@ -72,13 +75,15 @@ namespace ...@@ -72,13 +75,15 @@ namespace
} }
void operator() (const Range& range) const void operator() (const Range& range) const
{ {
for (int i = range.start; i != range.end; i++){ for (int i = range.start; i != range.end; i++)
{
idft(src_[i], src_[i],DFT_SCALE); idft(src_[i], src_[i],DFT_SCALE);
} }
} }
}; };
class ParallelDivComplexByReal : public ParallelLoopBody { class ParallelDivComplexByReal : public ParallelLoopBody
{
private: private:
vector<Mat> numer_; vector<Mat> numer_;
vector<Mat> denom_; vector<Mat> denom_;
...@@ -115,11 +120,13 @@ namespace ...@@ -115,11 +120,13 @@ namespace
}; };
void shift(InputArray src, OutputArray dst, int shift_x, int shift_y) { void shift(InputArray src, OutputArray dst, int shift_x, int shift_y)
{
Mat S = src.getMat(); Mat S = src.getMat();
Mat D = dst.getMat(); Mat D = dst.getMat();
if(S.data == D.data){ if(S.data == D.data)
{
S = S.clone(); S = S.clone();
} }
...@@ -142,7 +149,8 @@ namespace ...@@ -142,7 +149,8 @@ namespace
} }
// dft after padding imaginary // dft after padding imaginary
void fft(InputArray src, OutputArray dst) { void fft(InputArray src, OutputArray dst)
{
Mat S = src.getMat(); Mat S = src.getMat();
Mat planes[] = {S.clone(), Mat::zeros(S.size(), S.type())}; Mat planes[] = {S.clone(), Mat::zeros(S.size(), S.type())};
Mat x; Mat x;
...@@ -152,7 +160,8 @@ namespace ...@@ -152,7 +160,8 @@ namespace
dft(dst, dst); dft(dst, dst);
} }
void psf2otf(InputArray src, OutputArray dst, int height, int width) { void psf2otf(InputArray src, OutputArray dst, int height, int width)
{
Mat S = src.getMat(); Mat S = src.getMat();
Mat D = dst.getMat(); Mat D = dst.getMat();
...@@ -172,7 +181,8 @@ namespace ...@@ -172,7 +181,8 @@ namespace
fft(padded, dst); fft(padded, dst);
} }
void dftMultiChannel(InputArray src, vector<Mat> &dst) { void dftMultiChannel(InputArray src, vector<Mat> &dst)
{
Mat S = src.getMat(); Mat S = src.getMat();
split(S, dst); split(S, dst);
...@@ -186,7 +196,8 @@ namespace ...@@ -186,7 +196,8 @@ namespace
} }
void idftMultiChannel(const vector<Mat> &src, OutputArray dst){ void idftMultiChannel(const vector<Mat> &src, OutputArray dst)
{
vector<Mat> channels(src); vector<Mat> channels(src);
parallel_for_(Range(0, int(src.size())), ParallelIdft(channels)); parallel_for_(Range(0, int(src.size())), ParallelIdft(channels));
...@@ -202,7 +213,8 @@ namespace ...@@ -202,7 +213,8 @@ namespace
D.copyTo(dst); D.copyTo(dst);
} }
void addComplex(InputArray aSrc, int bSrc, OutputArray dst){ void addComplex(InputArray aSrc, int bSrc, OutputArray dst)
{
Mat panels[2]; Mat panels[2];
split(aSrc.getMat(), panels); split(aSrc.getMat(), panels);
panels[0] = panels[0] + bSrc; panels[0] = panels[0] + bSrc;
...@@ -210,7 +222,8 @@ namespace ...@@ -210,7 +222,8 @@ namespace
} }
void divComplexByRealMultiChannel(vector<Mat> &numer, void divComplexByRealMultiChannel(vector<Mat> &numer,
vector<Mat> &denom, vector<Mat> &dst){ vector<Mat> &denom, vector<Mat> &dst)
{
for(int i = 0; unsigned(i) < numer.size(); i++) for(int i = 0; unsigned(i) < numer.size(); i++)
{ {
...@@ -221,13 +234,18 @@ namespace ...@@ -221,13 +234,18 @@ namespace
} }
// power of 2 of the absolute value of the complex // power of 2 of the absolute value of the complex
Mat pow2absComplex(InputArray src){ Mat pow2absComplex(InputArray src)
{
Mat S = src.getMat(); Mat S = src.getMat();
Mat sPanels[2]; Mat sPanels[2];
split(S, sPanels); split(S, sPanels);
return sPanels[0].mul(sPanels[0]) + sPanels[1].mul(sPanels[1]); Mat mag;
magnitude(sPanels[0], sPanels[1], mag);
pow(mag, 2, mag);
return mag;
} }
} }
...@@ -246,7 +264,8 @@ namespace cv ...@@ -246,7 +264,8 @@ namespace cv
dst.create(src.size(), src.type()); dst.create(src.size(), src.type());
if(S.data == dst.getMat().data){ if(S.data == dst.getMat().data)
{
S = S.clone(); S = S.clone();
} }
...@@ -257,7 +276,9 @@ namespace cv ...@@ -257,7 +276,9 @@ namespace cv
else if(S.depth() == CV_16U) else if(S.depth() == CV_16U)
{ {
S.convertTo(S, CV_32F, 1/65535.0f); S.convertTo(S, CV_32F, 1/65535.0f);
}else if(S.depth() == CV_64F){ }
else if(S.depth() == CV_64F)
{
S.convertTo(S, CV_32F); S.convertTo(S, CV_32F);
} }
...@@ -273,7 +294,8 @@ namespace cv ...@@ -273,7 +294,8 @@ namespace cv
vector<Mat> denomConst; vector<Mat> denomConst;
Mat tmp = pow2absComplex(otfFx) + pow2absComplex(otfFy); Mat tmp = pow2absComplex(otfFx) + pow2absComplex(otfFy);
for(int i = 0; i < S.channels(); i++){ for(int i = 0; i < S.channels(); i++)
{
denomConst.push_back(tmp); denomConst.push_back(tmp);
} }
...@@ -302,11 +324,12 @@ namespace cv ...@@ -302,11 +324,12 @@ namespace cv
} }
else if(S.channels() > 1) else if(S.channels() > 1)
{ {
Mat *channels = new Mat[S.channels()]; vector<Mat> channels(S.channels());
split(hvMag, channels); split(hvMag, channels);
hvMag = channels[0]; hvMag = channels[0];
for(int i = 1; i < S.channels(); i++){ for(int i = 1; i < S.channels(); i++)
{
hvMag = hvMag + channels[i]; hvMag = hvMag + channels[i];
} }
...@@ -314,8 +337,6 @@ namespace cv ...@@ -314,8 +337,6 @@ namespace cv
Mat in[] = {mask, mask, mask}; Mat in[] = {mask, mask, mask};
merge(in, 3, mask); merge(in, 3, mask);
delete[] channels;
} }
h = h.mul(mask); h = h.mul(mask);
...@@ -323,7 +344,8 @@ namespace cv ...@@ -323,7 +344,8 @@ namespace cv
// S subproblem // S subproblem
vector<Mat> denom(S.channels()); vector<Mat> denom(S.channels());
for(int i = 0; i < S.channels(); i++){ for(int i = 0; i < S.channels(); i++)
{
denom[i] = beta * denomConst[i] + 1; denom[i] = beta * denomConst[i] + 1;
} }
...@@ -335,7 +357,8 @@ namespace cv ...@@ -335,7 +357,8 @@ namespace cv
dftMultiChannel(hGrad+vGrad, hvGradFreq); dftMultiChannel(hGrad+vGrad, hvGradFreq);
vector<Mat> numer(S.channels()); vector<Mat> numer(S.channels());
for(int i = 0; i < S.channels(); i++){ for(int i = 0; i < S.channels(); i++)
{
numer[i] = numerConst[i] + hvGradFreq[i] * beta; numer[i] = numerConst[i] + hvGradFreq[i] * beta;
} }
...@@ -355,9 +378,13 @@ namespace cv ...@@ -355,9 +378,13 @@ namespace cv
else if(D.depth() == CV_16U) else if(D.depth() == CV_16U)
{ {
S.convertTo(D, CV_16U, 65535); S.convertTo(D, CV_16U, 65535);
}else if(D.depth() == CV_64F){ }
else if(D.depth() == CV_64F)
{
S.convertTo(D, CV_64F); S.convertTo(D, CV_64F);
}else{ }
else
{
S.copyTo(D); S.copyTo(D);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment