@@ -220,6 +220,37 @@ Mat sparseTableFillPlanning(
220
220
return path;
221
221
}
222
222
223
+ kernelDecompInfo decompKernel (InputArray kernel, Point anchor, int iterations)
224
+ {
225
+ Mat _kernel = kernel.getMat ();
226
+ // Fix kernel in case of it is empty.
227
+ if (_kernel.empty ())
228
+ {
229
+ _kernel = getStructuringElement (MORPH_RECT, Size (1 + iterations * 2 , 1 + iterations * 2 ));
230
+ anchor = Point (iterations, iterations);
231
+ iterations = 1 ;
232
+ }
233
+ if (countNonZero (_kernel) == 0 )
234
+ {
235
+ _kernel.at <uchar>(0 , 0 ) = 1 ;
236
+ }
237
+ // Fix anchor to the center of the kernel.
238
+ anchor = stMorph::normalizeAnchor (anchor, _kernel.size ());
239
+
240
+
241
+ int rowDepthLim = log2 (longestRowRunLength (_kernel)) + 1 ;
242
+ int colDepthLim = log2 (longestColRunLength (_kernel)) + 1 ;
243
+ std::vector<std::vector<std::vector<Point>>> pow2Rects
244
+ = genPow2RectsToCoverKernel (_kernel, rowDepthLim, colDepthLim);
245
+
246
+ Mat stPlan
247
+ = sparseTableFillPlanning (pow2Rects, rowDepthLim, colDepthLim);
248
+
249
+ anchor = stMorph::normalizeAnchor (anchor, _kernel.size ());
250
+
251
+ return { _kernel.rows , _kernel.cols , pow2Rects, stPlan, anchor, iterations };
252
+ }
253
+
223
254
void morphDfs (int minmax, Mat& st, Mat& dst,
224
255
std::vector<std::vector<std::vector<Point>>> row2Rects, const Mat& stPlan,
225
256
int rowDepth, int colDepth)
@@ -318,37 +349,6 @@ void morphOp(Op minmax, InputArray _src, OutputArray _dst, kernelDecompInfo kdi,
318
349
}
319
350
}
320
351
321
- kernelDecompInfo getKernelDecompInfo (InputArray kernel, Point anchor, int iterations)
322
- {
323
- Mat _kernel = kernel.getMat ();
324
- // Fix kernel in case of it is empty.
325
- if (_kernel.empty ())
326
- {
327
- _kernel = getStructuringElement (MORPH_RECT, Size (1 + iterations * 2 , 1 + iterations * 2 ));
328
- anchor = Point (iterations, iterations);
329
- iterations = 1 ;
330
- }
331
- if (countNonZero (_kernel) == 0 )
332
- {
333
- _kernel.at <uchar>(0 , 0 ) = 1 ;
334
- }
335
- // Fix anchor to the center of the kernel.
336
- anchor = stMorph::normalizeAnchor (anchor, _kernel.size ());
337
-
338
-
339
- int rowDepthLim = log2 (longestRowRunLength (_kernel)) + 1 ;
340
- int colDepthLim = log2 (longestColRunLength (_kernel)) + 1 ;
341
- std::vector<std::vector<std::vector<Point>>> pow2Rects
342
- = genPow2RectsToCoverKernel (_kernel, rowDepthLim, colDepthLim);
343
-
344
- Mat stPlan
345
- = sparseTableFillPlanning (pow2Rects, rowDepthLim, colDepthLim);
346
-
347
- anchor = stMorph::normalizeAnchor (anchor, _kernel.size ());
348
-
349
- return { _kernel.rows , _kernel.cols , pow2Rects, stPlan, anchor, iterations };
350
- }
351
-
352
352
void erode (InputArray src, OutputArray dst, kernelDecompInfo kdi,
353
353
BorderTypes borderType, const Scalar& borderVal)
354
354
{
@@ -408,26 +408,25 @@ void morphologyEx(InputArray src, OutputArray dst, int op, kernelDecompInfo kdi,
408
408
_dst = temp - _src;
409
409
break ;
410
410
case MORPH_HITMISS:
411
- CV_Error (cv::Error::StsBadArg, " stMorph doesn't support HITMISS operation" );
411
+ CV_Error (cv::Error::StsBadArg, " StMorph doesn't support HIT-MISS operation. " );
412
412
default :
413
- CV_Error (cv::Error::StsBadArg, " unknown morphological operation" );
413
+ CV_Error (cv::Error::StsBadArg, " Unknown morphological operation. " );
414
414
}
415
415
}
416
416
417
- // ------------------------------------------
418
417
void erode (InputArray src, OutputArray dst, InputArray kernel,
419
418
Point anchor, int iterations,
420
419
BorderTypes borderType, const Scalar& borderVal)
421
420
{
422
- kernelDecompInfo kdi = getKernelDecompInfo (kernel, anchor, iterations);
421
+ kernelDecompInfo kdi = decompKernel (kernel, anchor, iterations);
423
422
morphOp (Op::Min, src, dst, kdi, borderType, borderVal);
424
423
}
425
424
426
425
void dilate (InputArray src, OutputArray dst, InputArray kernel,
427
426
Point anchor, int iterations,
428
427
BorderTypes borderType, const Scalar& borderVal)
429
428
{
430
- kernelDecompInfo kdi = getKernelDecompInfo (kernel, anchor, iterations);
429
+ kernelDecompInfo kdi = decompKernel (kernel, anchor, iterations);
431
430
morphOp (Op::Max, src, dst, kdi, borderType, borderVal);
432
431
}
433
432
@@ -442,7 +441,7 @@ void morphologyEx(InputArray src, OutputArray dst, int op,
442
441
_kernel = getStructuringElement (MORPH_RECT, Size (3 , 3 ), Point (1 , 1 ));
443
442
}
444
443
445
- kernelDecompInfo kdi = getKernelDecompInfo (_kernel, anchor, iterations);
444
+ kernelDecompInfo kdi = decompKernel (_kernel, anchor, iterations);
446
445
morphologyEx (src, dst, op, kdi, borderType, borderVal);
447
446
}
448
447
0 commit comments