Skip to content

Commit c20593a

Browse files
committed
2冪長方形被覆の結果を長方形サイズごとに集約して返すように変更
1 parent efba857 commit c20593a

File tree

3 files changed

+268
-128
lines changed

3 files changed

+268
-128
lines changed

modules/ximgproc/include/opencv2/ximgproc/sparse_table_morphology.hpp

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,34 +105,77 @@ enum Op
105105
Min, Max
106106
};
107107

108+
enum StStrategy
109+
{
110+
Faster,
111+
SaveMemory
112+
};
113+
114+
enum QueryType
115+
{
116+
Stuck,
117+
Pop,
118+
Fill,
119+
};
120+
108121
struct StStep
109122
{
110-
StStep(int dimR, int dimC, Dim _ax)
123+
StStep(QueryType _qType, int dimR, int dimC, Dim _ax, std::vector<Point> _points)
111124
{
125+
qType = _qType;
112126
dimRow = dimR;
113127
dimCol = dimC;
114128
ax = _ax;
129+
points = _points;
115130
}
131+
QueryType qType;
116132
int dimRow;
117133
int dimCol;
118134
Dim ax;
135+
std::vector<Point> points;
119136
};
120137

121138
/*
122-
* Find a smaller set of power-of-2 rectangles to cover the kernel.
123-
* - The width and the height of each rectangles are power of 2.
124-
* - Overlappings of rectangles are allowed.
125-
*
126-
* this method may be applied for the covering polygon problem with rectangle.
127-
* https://www.sciencedirect.com/science/article/pii/S0019995884800121z
139+
* Find a set of power-2-rectangles to cover the kernel.
140+
* power-2-rectangles is a rectangle whose height and width are both power of 2.
128141
*/
129-
CV_EXPORTS_W std::vector<Rect> genPow2RectsToCoverKernel(InputArray kernel);
142+
CV_EXPORTS_W std::vector<std::vector<std::vector<Point>>> genPow2RectsToCoverKernel(
143+
const Mat& kernel, int rowLim, int colLim);
130144
//
131-
///*
132-
//* Plan the order to calculate the sparse table nodes.
133-
//*/
134-
CV_EXPORTS_W std::vector<StStep> planSparseTableConstr(std::vector<std::vector<bool>> stNodeMap);
145+
/*
146+
* Plan the order to fill the required sparse table nodes.
147+
*/
148+
CV_EXPORTS_W std::vector<StStep> planSparseTableConstr(
149+
std::vector<std::vector<std::vector<Point>>> stNodeMap, int rowLim, int colLim,
150+
StStrategy strategy = Faster);
151+
152+
CV_EXPORTS_W int log2(int n);
153+
CV_EXPORTS_W int longestRowRunLength(const Mat& kernel);
154+
CV_EXPORTS_W int longestColRunLength(const Mat& kernel);
135155

136156
}} // cv::stMorph::
137157

138158
#endif
159+
160+
/*
161+
162+
About sparse table:
163+
https://qiita.com/recuraki/items/0fcbc9e2abbc4fae5f62
164+
https://www.geeksforgeeks.org/sparse-table/
165+
166+
2D-sparse table:
167+
https://kopricky.github.io/code/DataStructure_Advanced/sparse_table_2D.html
168+
https://www.geeksforgeeks.org/2d-range-minimum-query-in-o1/
169+
170+
With 2D sparse table, we can get the min or max value in each power-of-2 rectangle quickly.
171+
172+
173+
1. Find a set of power-of-2 rectangles which covers the kernel.
174+
2. Group the rectangles by the size.
175+
3. Fill the sparse table
176+
177+
https://gobi-tk.hatenablog.com/entry/2024/09/18/012709
178+
https://link.springer.com/article/10.1007/BF01758762
179+
180+
181+
*/

0 commit comments

Comments
 (0)