@@ -77,19 +77,19 @@ namespace ximgproc
77
77
{
78
78
public:
79
79
80
- static Ptr<FastBilateralSolverFilterImpl> create (InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol)
80
+ static Ptr<FastBilateralSolverFilterImpl> create (InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol)
81
81
{
82
82
CV_Assert (guide.type () == CV_8UC1 || guide.type () == CV_8UC3);
83
83
FastBilateralSolverFilterImpl *fbs = new FastBilateralSolverFilterImpl ();
84
84
Mat gui = guide.getMat ();
85
- fbs->init (gui,sigma_spatial,sigma_luma,sigma_chroma,num_iter,max_tol);
85
+ fbs->init (gui,sigma_spatial,sigma_luma,sigma_chroma,lambda, num_iter,max_tol);
86
86
return Ptr<FastBilateralSolverFilterImpl>(fbs);
87
87
}
88
88
89
89
void filter (InputArray src, InputArray confidence, OutputArray dst) CV_OVERRIDE
90
90
{
91
91
92
- CV_Assert (!src.empty () && (src.depth () == CV_8U || src.depth () == CV_16S || src.depth () == CV_32F) && src.channels ()<=4 );
92
+ CV_Assert (!src.empty () && (src.depth () == CV_8U || src.depth () == CV_16S || src.depth () == CV_16U || src. depth () == CV_32F) && src.channels ()<=4 );
93
93
CV_Assert (!confidence.empty () && (confidence.depth () == CV_8U || confidence.depth () == CV_32F) && confidence.channels ()==1 );
94
94
if (src.rows () != rows || src.cols () != cols)
95
95
{
@@ -133,7 +133,7 @@ namespace ximgproc
133
133
134
134
// protected:
135
135
void solve (cv::Mat& src, cv::Mat& confidence, cv::Mat& dst);
136
- void init (cv::Mat& reference, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol);
136
+ void init (cv::Mat& reference, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol);
137
137
138
138
void Splat (Eigen::VectorXf& input, Eigen::VectorXf& dst);
139
139
void Blur (Eigen::VectorXf& input, Eigen::VectorXf& dst);
@@ -174,8 +174,8 @@ namespace ximgproc
174
174
grid_params ()
175
175
{
176
176
spatialSigma = 8.0 ;
177
- lumaSigma = 4 .0 ;
178
- chromaSigma = 4 .0 ;
177
+ lumaSigma = 8 .0 ;
178
+ chromaSigma = 8 .0 ;
179
179
}
180
180
};
181
181
@@ -201,9 +201,10 @@ namespace ximgproc
201
201
202
202
203
203
204
- void FastBilateralSolverFilterImpl::init (cv::Mat& reference, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol)
204
+ void FastBilateralSolverFilterImpl::init (cv::Mat& reference, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol)
205
205
{
206
206
207
+ bs_param.lam = lambda;
207
208
bs_param.cg_maxiter = num_iter;
208
209
bs_param.cg_tol = max_tol;
209
210
@@ -266,7 +267,6 @@ namespace ximgproc
266
267
267
268
// construct Blur matrices
268
269
Eigen::VectorXf ones_nvertices = Eigen::VectorXf::Ones (nvertices);
269
- Eigen::VectorXf ones_npixels = Eigen::VectorXf::Ones (npixels);
270
270
diagonal (ones_nvertices,blurs);
271
271
blurs *= 10 ;
272
272
for (int offset = -1 ; offset <= 1 ;++offset)
@@ -379,7 +379,6 @@ namespace ximgproc
379
379
380
380
// construct Blur matrices
381
381
Eigen::VectorXf ones_nvertices = Eigen::VectorXf::Ones (nvertices);
382
- Eigen::VectorXf ones_npixels = Eigen::VectorXf::Ones (npixels);
383
382
diagonal (ones_nvertices,blurs);
384
383
blurs *= 10 ;
385
384
for (int offset = -1 ; offset <= 1 ;++offset)
@@ -486,6 +485,14 @@ namespace ximgproc
486
485
x (i) = (cv::saturate_cast<float >(pft[i])+32768 .0f )/65535 .0f ;
487
486
}
488
487
}
488
+ else if (target.depth () == CV_16U)
489
+ {
490
+ const uint16_t *pft = reinterpret_cast <const uint16_t *>(target.data );
491
+ for (int i = 0 ; i < npixels; i++)
492
+ {
493
+ x (i) = cv::saturate_cast<float >(pft[i])/65535 .0f ;
494
+ }
495
+ }
489
496
else if (target.depth () == CV_8U)
490
497
{
491
498
const uchar *pft = reinterpret_cast <const uchar*>(target.data );
@@ -566,7 +573,15 @@ namespace ximgproc
566
573
int16_t *pftar = (int16_t *) output.data ;
567
574
for (int i = 0 ; i < int (splat_idx.size ()); i++)
568
575
{
569
- pftar[i] = cv::saturate_cast<ushort>(y (splat_idx[i]) * 65535 .0f - 32768 .0f );
576
+ pftar[i] = cv::saturate_cast<short >(y (splat_idx[i]) * 65535 .0f - 32768 .0f );
577
+ }
578
+ }
579
+ else if (target.depth () == CV_16U)
580
+ {
581
+ uint16_t *pftar = (uint16_t *) output.data ;
582
+ for (int i = 0 ; i < int (splat_idx.size ()); i++)
583
+ {
584
+ pftar[i] = cv::saturate_cast<ushort>(y (splat_idx[i]) * 65535 .0f );
570
585
}
571
586
}
572
587
else if (target.depth () == CV_8U)
@@ -592,14 +607,14 @@ namespace ximgproc
592
607
593
608
// //////////////////////////////////////////////////////////////////////////
594
609
// //////////////////////////////////////////////////////////////////////////
595
- Ptr<FastBilateralSolverFilter> createFastBilateralSolverFilter (InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol)
610
+ Ptr<FastBilateralSolverFilter> createFastBilateralSolverFilter (InputArray guide, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol)
596
611
{
597
- return Ptr<FastBilateralSolverFilter>(FastBilateralSolverFilterImpl::create (guide, sigma_spatial, sigma_luma, sigma_chroma, num_iter, max_tol));
612
+ return Ptr<FastBilateralSolverFilter>(FastBilateralSolverFilterImpl::create (guide, sigma_spatial, sigma_luma, sigma_chroma, lambda, num_iter, max_tol));
598
613
}
599
614
600
- void fastBilateralSolverFilter (InputArray guide, InputArray src, InputArray confidence, OutputArray dst, double sigma_spatial, double sigma_luma, double sigma_chroma, int num_iter, double max_tol)
615
+ void fastBilateralSolverFilter (InputArray guide, InputArray src, InputArray confidence, OutputArray dst, double sigma_spatial, double sigma_luma, double sigma_chroma, double lambda, int num_iter, double max_tol)
601
616
{
602
- Ptr<FastBilateralSolverFilter> fbs = createFastBilateralSolverFilter (guide, sigma_spatial, sigma_luma, sigma_chroma, num_iter, max_tol);
617
+ Ptr<FastBilateralSolverFilter> fbs = createFastBilateralSolverFilter (guide, sigma_spatial, sigma_luma, sigma_chroma, lambda, num_iter, max_tol);
603
618
fbs->filter (src, confidence, dst);
604
619
}
605
620
@@ -614,12 +629,12 @@ namespace cv
614
629
namespace ximgproc
615
630
{
616
631
617
- Ptr<FastBilateralSolverFilter> createFastBilateralSolverFilter (InputArray, double , double , double , int , double )
632
+ Ptr<FastBilateralSolverFilter> createFastBilateralSolverFilter (InputArray, double , double , double , double , int , double )
618
633
{
619
634
CV_Error (Error::StsNotImplemented, " createFastBilateralSolverFilter : needs to be compiled with EIGEN" );
620
635
}
621
636
622
- void fastBilateralSolverFilter (InputArray, InputArray, InputArray, OutputArray, double , double , double , int , double )
637
+ void fastBilateralSolverFilter (InputArray, InputArray, InputArray, OutputArray, double , double , double , double , int , double )
623
638
{
624
639
CV_Error (Error::StsNotImplemented, " fastBilateralSolverFilter : needs to be compiled with EIGEN" );
625
640
}
0 commit comments