Skip to content

Commit 2bd8d58

Browse files
LaurentBergeralalek
authored andcommitted
Merge pull request #1678 from LaurentBerger:MoveAssert
* Some bugs in deriche and paillou filter * Cv_Assert to CV_CheckType
1 parent c6daea8 commit 2bd8d58

File tree

2 files changed

+63
-23
lines changed

2 files changed

+63
-23
lines changed

modules/ximgproc/src/deriche_filter.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ HorizontalIIRFilter(Mat &img, Mat &dst, const Range &r, double alphaDerive)
135135
j = cols - 1;
136136
g2[j] = (a3 + a4)* *c1;
137137
j--;
138+
c1--;
138139
g2[j] = (a3 + a4) * c1[1] + b1 * g2[j + 1];
139140
j--;
140141
c1--;
@@ -160,16 +161,18 @@ class ParallelGradientDericheYCols : public ParallelLoopBody
160161
dst(d),
161162
alphaDerive(ald),
162163
verbose(false)
163-
{}
164+
{
165+
int type = img.depth();
166+
CV_CheckType(type, type == CV_8UC1 || type == CV_8SC1 || type == CV_16SC1 || type == CV_16UC1 || type == CV_32FC1, "Wrong input type for GradientDericheYCols");
167+
type = dst.depth();
168+
CV_CheckType(type, type==CV_32FC1, "Wrong output type for GradientDericheYCols");
169+
}
164170
void Verbose(bool b) { verbose = b; }
165171
virtual void operator()(const Range& range) const CV_OVERRIDE
166172
{
167-
CV_Assert(img.depth()==CV_8UC1 || img.depth()==CV_8SC1 || img.depth()==CV_16SC1 || img.depth()==CV_16UC1);
168-
CV_Assert(dst.depth()==CV_32FC1);
169173
if (verbose)
170174
std::cout << getThreadNum() << "# :Start from row " << range.start << " to " << range.end - 1 << " (" << range.end - range.start << " loops)" << std::endl;
171175

172-
173176
switch (img.depth()) {
174177
case CV_8U:
175178
VerticalIIRFilter<uchar>(img,dst,range, alphaDerive);
@@ -183,6 +186,9 @@ class ParallelGradientDericheYCols : public ParallelLoopBody
183186
case CV_16S:
184187
VerticalIIRFilter<short>(img, dst, range, alphaDerive);
185188
break;
189+
case CV_32F:
190+
VerticalIIRFilter<float>(img, dst, range, alphaDerive);
191+
break;
186192
default:
187193
return;
188194
}
@@ -207,12 +213,15 @@ class ParallelGradientDericheYRows : public ParallelLoopBody
207213
dst(d),
208214
alphaMoyenne(alm),
209215
verbose(false)
210-
{}
216+
{
217+
int type = img.depth();
218+
CV_CheckType(type, type == CV_32FC1, "Wrong input type for GradientDericheYRows");
219+
type = dst.depth();
220+
CV_CheckType(type, type == CV_32FC1, "Wrong output type for GradientDericheYRows");
221+
}
211222
void Verbose(bool b) { verbose = b; }
212223
virtual void operator()(const Range& range) const CV_OVERRIDE
213224
{
214-
CV_Assert(img.depth()==CV_32FC1);
215-
CV_Assert(dst.depth()==CV_32FC1);
216225
if (verbose)
217226
std::cout << getThreadNum() << "# :Start from row " << range.start << " to " << range.end - 1 << " (" << range.end - range.start << " loops)" << std::endl;
218227
float *f1, *f2;
@@ -280,12 +289,15 @@ class ParallelGradientDericheXCols : public ParallelLoopBody
280289
dst(d),
281290
alphaMoyenne(alm),
282291
verbose(false)
283-
{}
292+
{
293+
int type = img.depth();
294+
CV_CheckType(type, type == CV_32FC1, "Wrong input type for GradientDericheXCols");
295+
type = dst.depth();
296+
CV_CheckType(type, type == CV_32FC1, "Wrong output type for GradientDericheXCols");
297+
}
284298
void Verbose(bool b) { verbose = b; }
285299
virtual void operator()(const Range& range) const CV_OVERRIDE
286300
{
287-
CV_Assert(img.depth()==CV_32FC1);
288-
CV_Assert(dst.depth()==CV_32FC1);
289301
if (verbose)
290302
std::cout << getThreadNum() << "# :Start from row " << range.start << " to " << range.end - 1 << " (" << range.end - range.start << " loops)" << std::endl;
291303
float *f1, *f2;
@@ -355,12 +367,15 @@ class ParallelGradientDericheXRows : public ParallelLoopBody
355367
dst(d),
356368
alphaDerive(ald),
357369
verbose(false)
358-
{}
370+
{
371+
int type = img.depth();
372+
CV_CheckType(type, type == CV_8UC1 || type == CV_8SC1 || type == CV_16SC1 || type == CV_16UC1 || type == CV_32FC1, "Wrong input type for GradientDericheXRows");
373+
type = dst.depth();
374+
CV_CheckType(type, type == CV_32FC1, "Wrong output type for GradientDericheXRows");
375+
}
359376
void Verbose(bool b) { verbose = b; }
360377
virtual void operator()(const Range& range) const CV_OVERRIDE
361378
{
362-
CV_Assert(img.depth()==CV_8UC1 || img.depth()==CV_8SC1 || img.depth()==CV_16SC1 || img.depth()==CV_16UC1);
363-
CV_Assert(dst.depth()==CV_32FC1);
364379
if (verbose)
365380
std::cout << getThreadNum() << "# :Start from row " << range.start << " to " << range.end - 1 << " (" << range.end - range.start << " loops)" << std::endl;
366381

@@ -377,6 +392,9 @@ class ParallelGradientDericheXRows : public ParallelLoopBody
377392
case CV_16S:
378393
HorizontalIIRFilter<short>(img, dst, range, alphaDerive);
379394
break;
395+
case CV_32F:
396+
HorizontalIIRFilter<float>(img, dst, range, alphaDerive);
397+
break;
380398
default:
381399
return;
382400
}

modules/ximgproc/src/paillou_filter.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,15 @@ class ParallelGradientPaillouYCols: public ParallelLoopBody
143143
a(aa),
144144
w(ww),
145145
verbose(false)
146-
{}
146+
{
147+
int type = img.depth();
148+
CV_CheckType(type, type == CV_8UC1 || type == CV_8SC1 || type == CV_16SC1 || type == CV_16UC1 || type == CV_32FC1, "Wrong input type for GradientPaillouY");
149+
type = dst.depth();
150+
CV_CheckType(type, type == CV_32FC1, "Wrong output type for GradientPaillouYCols");
151+
}
147152
void Verbose(bool b){verbose=b;}
148153
virtual void operator()(const Range& range) const CV_OVERRIDE
149154
{
150-
CV_Assert(img.depth()==CV_8UC1 || img.depth()==CV_16SC1 || img.depth()==CV_16UC1);
151-
CV_Assert(dst.depth()==CV_32FC1);
152155
if (verbose)
153156
std::cout << getThreadNum()<<"# :Start from row " << range.start << " to " << range.end-1<<" ("<<range.end-range.start<<" loops)" << std::endl;
154157

@@ -162,9 +165,12 @@ class ParallelGradientPaillouYCols: public ParallelLoopBody
162165
case CV_16S :
163166
VerticalIIRFilter<short>(img, dst, range, a, w);
164167
break;
165-
case CV_16U :
168+
case CV_16U:
166169
VerticalIIRFilter<short>(img, dst, range, a, w);
167170
break;
171+
case CV_32F:
172+
VerticalIIRFilter<float>(img, dst, range, a, w);
173+
break;
168174
default :
169175
return ;
170176
}
@@ -191,11 +197,15 @@ class ParallelGradientPaillouYRows: public ParallelLoopBody
191197
a(aa),
192198
w(ww),
193199
verbose(false)
194-
{}
200+
{
201+
int type = img.depth();
202+
CV_CheckType(type, type == CV_32FC1, "Wrong input type for GradientPaillouYRows");
203+
type = dst.depth();
204+
CV_CheckType(type, type == CV_32FC1, "Wrong output type for GradientPaillouYRows");
205+
}
195206
void Verbose(bool b){verbose=b;}
196207
virtual void operator()(const Range& range) const CV_OVERRIDE
197208
{
198-
CV_Assert(img.depth()==CV_32FC1);
199209
if (verbose)
200210
std::cout << getThreadNum()<<"# :Start from row " << range.start << " to " << range.end-1<<" ("<<range.end-range.start<<" loops)" << std::endl;
201211
float *iy,*iy0;
@@ -261,11 +271,15 @@ class ParallelGradientPaillouXCols: public ParallelLoopBody
261271
a(aa),
262272
w(ww),
263273
verbose(false)
264-
{}
274+
{
275+
int type = img.depth();
276+
CV_CheckType(type, type == CV_32FC1, "Wrong input type for GradientPaillouXCols");
277+
type = dst.depth();
278+
CV_CheckType(type, type == CV_32FC1, "Wrong output type for GradientPaillouXCols");
279+
}
265280
void Verbose(bool b){verbose=b;}
266281
virtual void operator()(const Range& range) const CV_OVERRIDE
267282
{
268-
CV_Assert(img.depth()==CV_32FC1);
269283
if (verbose)
270284
std::cout << getThreadNum() << "# :Start from row " << range.start << " to " << range.end - 1 << " (" << range.end - range.start << " loops)" << std::endl;
271285
float *iy, *iy0;
@@ -331,7 +345,12 @@ class ParallelGradientPaillouXRows: public ParallelLoopBody
331345
a(aa),
332346
w(ww),
333347
verbose(false)
334-
{}
348+
{
349+
int type = img.depth();
350+
CV_CheckType(type, type == CV_8UC1 || type == CV_8SC1 || type == CV_16SC1 || type == CV_16UC1 || type == CV_32FC1, "Wrong input type for GradientPaillouXRows");
351+
type = im1.depth();
352+
CV_CheckType(type, type == CV_32FC1, "Wrong output type for GradientPaillouXRows");
353+
}
335354
void Verbose(bool b){verbose=b;}
336355
virtual void operator()(const Range& range) const CV_OVERRIDE
337356
{
@@ -349,9 +368,12 @@ class ParallelGradientPaillouXRows: public ParallelLoopBody
349368
case CV_16S :
350369
HorizontalIIRFilter<short>(img, im1, range, a, w);
351370
break;
352-
case CV_16U :
371+
case CV_16U:
353372
HorizontalIIRFilter<ushort>(img, im1, range, a, w);
354373
break;
374+
case CV_32F:
375+
HorizontalIIRFilter<float>(img, im1, range, a, w);
376+
break;
355377
default :
356378
return ;
357379
}

0 commit comments

Comments
 (0)