@@ -28,54 +28,33 @@ std::vector<Rect> genPow2RectsToCoverKernel(InputArray _kernel)
28
28
st[0 ][0 ] = kernel;
29
29
for (int colDepth = 1 ; colDepth <= log2[kernel.cols ]; colDepth++)
30
30
{
31
- int rowStep = 0 ;
32
- int rowSkip = 0 ;
33
- int rowLim = kernel.rows - rowSkip;
34
-
35
31
int colStep = 1 << (colDepth - 1 );
36
- int colSkip = (1 << colDepth) - 1 ;
37
- int colLim = kernel.cols - colSkip;
32
+ int colLim = kernel.cols - (1 << colDepth) + 1 ;
38
33
34
+ Rect rect1 (0 , 0 , colLim, kernel.rows );
35
+ Rect rect2 (colStep, 0 , colLim, kernel.rows );
36
+ Mat src1 = st[0 ][colDepth - 1 ](rect1);
37
+ Mat src2 = st[0 ][colDepth - 1 ](rect2);
39
38
st[0 ][colDepth].create (kernel.size (), kernel.type ());
40
- uchar* ptr1 = st[0 ][colDepth - 1 ].ptr ();
41
- uchar* ptr2 = st[0 ][colDepth - 1 ].ptr (rowStep, colStep);
42
- uchar* dst = st[0 ][colDepth].ptr ();
43
- for (int row = 0 ; row < rowLim; row++)
44
- {
45
- for (int col = 0 ; col < colLim; col++)
46
- {
47
- *dst++ = *ptr1++ & *ptr2++;
48
- }
49
- ptr1 += colSkip;
50
- ptr2 += colSkip;
51
- dst += colSkip;
52
- }
39
+ Mat next = st[0 ][colDepth](rect1);
40
+ cv::bitwise_and (src1, src2, next);
53
41
}
54
42
for (int rowDepth = 1 ; rowDepth <= log2[kernel.rows ]; rowDepth++)
55
43
{
56
44
int rowStep = 1 << (rowDepth - 1 );
57
- int rowSkip = (1 << rowDepth) - 1 ;
58
- int rowLim = kernel.rows - rowSkip;
45
+ int rowLim = kernel.rows - (1 << rowDepth) + 1 ;
59
46
for (int colDepth = 0 ; colDepth <= log2[kernel.cols ]; colDepth++)
60
47
{
61
48
int colStep = 0 ;
62
- int colSkip = (1 << colDepth) - 1 ;
63
- int colLim = kernel.cols - colSkip;
49
+ int colLim = kernel.cols - (1 << colDepth) + 1 ;
64
50
51
+ Rect rect1 (0 , 0 , colLim, rowLim);
52
+ Rect rect2 (colStep, rowStep, colLim, rowLim);
53
+ Mat src1 = st[rowDepth - 1 ][colDepth](rect1);
54
+ Mat src2 = st[rowDepth - 1 ][colDepth](rect2);
65
55
st[rowDepth][colDepth].create (kernel.size (), kernel.type ());
66
- uchar* ptr1 = st[rowDepth - 1 ][colDepth].ptr ();
67
- uchar* ptr2 = st[rowDepth - 1 ][colDepth].ptr (rowStep, colStep);
68
- uchar* dst = st[rowDepth][colDepth].ptr ();
69
- for (int row = 0 ; row < rowLim; row++)
70
- {
71
- for (int col = 0 ; col < colLim; col++)
72
- {
73
- *dst++ = *ptr1++ & *ptr2++;
74
- }
75
- ptr1 += colSkip;
76
- ptr2 += colSkip;
77
- dst += colSkip;
78
- }
56
+ Mat next = st[rowDepth][colDepth](rect1);
57
+ cv::bitwise_and (src1, src2, next);
79
58
}
80
59
}
81
60
@@ -107,7 +86,7 @@ std::vector<Rect> genPow2RectsToCoverKernel(InputArray _kernel)
107
86
if (row > 0 && ptr[-kernel.cols ]
108
87
&& row < rowLim && ptr[kernel.cols ] == 1 ) continue ;
109
88
110
- // ignore one of neighbor block is white; will be alive in deeper table
89
+ // ignore if neighboring block is white; will be alive in deeper table
111
90
if (col + colOfst <= colLim && ptr[colOfst] == 1 ) continue ;
112
91
if (col - colOfst >= 0 && ptr[-colOfst] == 1 ) continue ;
113
92
if (row + rowOfst <= rowLim && ptr[x] == 1 ) continue ;
@@ -119,7 +98,6 @@ std::vector<Rect> genPow2RectsToCoverKernel(InputArray _kernel)
119
98
}
120
99
}
121
100
}
122
-
123
101
return p2Rects;
124
102
}
125
103
@@ -354,18 +332,18 @@ void morphologyEx(InputArray src, OutputArray dst, int op,
354
332
switch (op)
355
333
{
356
334
case MORPH_ERODE:
357
- stMorph::erode (_src, _dst, _kernel , anchor, iterations, borderType, borderVal);
335
+ stMorph::erode (src, dst, kernel , anchor, iterations, borderType, borderVal);
358
336
break ;
359
337
case MORPH_DILATE:
360
- stMorph::dilate (_src, _dst, _kernel , anchor, iterations, borderType, borderVal);
338
+ stMorph::dilate (src, dst, kernel , anchor, iterations, borderType, borderVal);
361
339
break ;
362
340
case MORPH_OPEN:
363
- stMorph::erode (_src, _dst, _kernel , anchor, iterations, borderType, borderVal);
364
- stMorph::dilate (_dst, _dst, _kernel , anchor, iterations, borderType, borderVal);
341
+ stMorph::erode (src, dst, kernel , anchor, iterations, borderType, borderVal);
342
+ stMorph::dilate (dst, dst, kernel , anchor, iterations, borderType, borderVal);
365
343
break ;
366
344
case MORPH_CLOSE:
367
- stMorph::dilate (_src, _dst, _kernel , anchor, iterations, borderType, borderVal);
368
- stMorph::erode (_dst, _dst, _kernel , anchor, iterations, borderType, borderVal);
345
+ stMorph::dilate (src, dst, kernel , anchor, iterations, borderType, borderVal);
346
+ stMorph::erode (dst, dst, kernel , anchor, iterations, borderType, borderVal);
369
347
break ;
370
348
case MORPH_GRADIENT:
371
349
stMorph::erode (_src, temp, _kernel, anchor, iterations, borderType, borderVal);
0 commit comments