FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Rewite polar transforms (#11323) · pythonmjs/opencv@b8b7ca7 · GitHub

Repository navigation

Commit b8b7ca7

Browse files
authored
Rewite polar transforms (opencv#11323)
* Rewrite polar transformations - A new wrapPolar function encapsulate both linear and semi-log remap - Destination size is a parameter or calculated automatically to keep objects size between remapping - linearPolar and logPolar has been deprecated * Fix build warning and error in accuracy test * Fix function name to warpPolar * Explicitly specify the mapping mode, so we retain all the parameters as non-optional. Introduces WarpPolarMode enum to specify the mapping mode in flags * resolves performance warning on windows build * removed duplicated logPolar and linearPolar implementations
1 parent e0fef2b commit b8b7ca7

8 files changed

Lines changed: 2575 additions & 3109 deletions

File tree

-11.5 KB
LoadingViewer requires iframe.

‎modules/imgproc/doc/pics/polar_remap_doc.svg‎

Lines changed: 2252 additions & 2731 deletions
LoadingViewer requires iframe.

‎modules/imgproc/include/opencv2/imgproc.hpp‎

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ enum InterpolationFlags{
295295
WARP_INVERSE_MAP = 16
296296
};
297297

298+
/** \brief Specify the polar mapping mode
299+
@sa warpPolar
300+
*/
301+
enum WarpPolarMode
302+
{
303+
WARP_POLAR_LINEAR = 0, ///< Remaps an image to/from polar space.
304+
WARP_POLAR_LOG = 256 ///< Remaps an image to/from semilog-polar space.
305+
};
306+
298307
enum InterpolationMasks {
299308
INTER_BITS = 5,
300309
INTER_BITS2 = INTER_BITS * 2,
@@ -2546,7 +2555,10 @@ An example using the cv::linearPolar and cv::logPolar operations
25462555

25472556
/** @brief Remaps an image to semilog-polar coordinates space.
25482557
2549-
Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image"):
2558+
@deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags+WARP_POLAR_LOG);
2559+
2560+
@internal
2561+
Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image d)"):
25502562
\f[\begin{array}{l}
25512563
dst( \rho , \phi ) = src(x,y) \\
25522564
dst.size() \leftarrow src.size()
@@ -2556,13 +2568,13 @@ where
25562568
\f[\begin{array}{l}
25572569
I = (dx,dy) = (x - center.x,y - center.y) \\
25582570
\rho = M \cdot log_e(\texttt{magnitude} (I)) ,\\
2559-
\phi = Ky \cdot \texttt{angle} (I)_{0..360 deg} \\
2571+
\phi = Kangle \cdot \texttt{angle} (I) \\
25602572
\end{array}\f]
25612573
25622574
and
25632575
\f[\begin{array}{l}
25642576
M = src.cols / log_e(maxRadius) \\
2565-
Ky = src.rows / 360 \\
2577+
Kangle = src.rows / 2\Pi \\
25662578
\end{array}\f]
25672579
25682580
The function emulates the human "foveal" vision and can be used for fast scale and
@@ -2576,16 +2588,19 @@ rotation-invariant template matching, for object tracking and so forth.
25762588
@note
25772589
- The function can not operate in-place.
25782590
- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.
2591+
2592+
@sa cv::linearPolar
2593+
@endinternal
25792594
*/
25802595
CV_EXPORTS_W void logPolar( InputArray src, OutputArray dst,
25812596
Point2f center, double M, int flags );
25822597

25832598
/** @brief Remaps an image to polar coordinates space.
25842599
2585-
@anchor polar_remaps_reference_image
2586-
![Polar remaps reference](pics/polar_remap_doc.png)
2600+
@deprecated This function produces same result as cv::warpPolar(src, dst, src.size(), center, maxRadius, flags)
25872601
2588-
Transform the source image using the following transformation:
2602+
@internal
2603+
Transform the source image using the following transformation (See @ref polar_remaps_reference_image "Polar remaps reference image c)"):
25892604
\f[\begin{array}{l}
25902605
dst( \rho , \phi ) = src(x,y) \\
25912606
dst.size() \leftarrow src.size()
@@ -2594,14 +2609,14 @@ Transform the source image using the following transformation:
25942609
where
25952610
\f[\begin{array}{l}
25962611
I = (dx,dy) = (x - center.x,y - center.y) \\
2597-
\rho = Kx \cdot \texttt{magnitude} (I) ,\\
2598-
\phi = Ky \cdot \texttt{angle} (I)_{0..360 deg}
2612+
\rho = Kmag \cdot \texttt{magnitude} (I) ,\\
2613+
\phi = angle \cdot \texttt{angle} (I)
25992614
\end{array}\f]
26002615
26012616
and
26022617
\f[\begin{array}{l}
26032618
Kx = src.cols / maxRadius \\
2604-
Ky = src.rows / 360
2619+
Ky = src.rows / 2\Pi
26052620
\end{array}\f]
26062621
26072622
@@ -2615,10 +2630,104 @@ and
26152630
- The function can not operate in-place.
26162631
- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.
26172632
2633+
@sa cv::logPolar
2634+
@endinternal
26182635
*/
26192636
CV_EXPORTS_W void linearPolar( InputArray src, OutputArray dst,
26202637
Point2f center, double maxRadius, int flags );
26212638

2639+
2640+
/** \brief Remaps an image to polar or semilog-polar coordinates space
2641+
2642+
@anchor polar_remaps_reference_image
2643+
![Polar remaps reference](pics/polar_remap_doc.png)
2644+
2645+
Transform the source image using the following transformation:
2646+
\f[
2647+
dst(\rho , \phi ) = src(x,y)
2648+
\f]
2649+
2650+
where
2651+
\f[
2652+
\begin{array}{l}
2653+
\vec{I} = (x - center.x, \;y - center.y) \\
2654+
\phi = Kangle \cdot \texttt{angle} (\vec{I}) \\
2655+
\rho = \left\{\begin{matrix}
2656+
Klin \cdot \texttt{magnitude} (\vec{I}) & default \\
2657+
Klog \cdot log_e(\texttt{magnitude} (\vec{I})) & if \; semilog \\
2658+
\end{matrix}\right.
2659+
\end{array}
2660+
\f]
2661+
2662+
and
2663+
\f[
2664+
\begin{array}{l}
2665+
Kangle = dsize.height / 2\Pi \\
2666+
Klin = dsize.width / maxRadius \\
2667+
Klog = dsize.width / log_e(maxRadius) \\
2668+
\end{array}
2669+
\f]
2670+
2671+
2672+
\par Linear vs semilog mapping
2673+
2674+
Polar mapping can be linear or semi-log. Add one of #WarpPolarMode to `flags` to specify the polar mapping mode.
2675+
2676+
Linear is the default mode.
2677+
2678+
The semilog mapping emulates the human "foveal" vision that permit very high acuity on the line of sight (central vision)
2679+
in contrast to peripheral vision where acuity is minor.
2680+
2681+
\par Option on `dsize`:
2682+
2683+
- if both values in `dsize <=0 ` (default),
2684+
the destination image will have (almost) same area of source bounding circle:
2685+
\f[\begin{array}{l}
2686+
dsize.area \leftarrow (maxRadius^2 \cdot \Pi) \\
2687+
dsize.width = \texttt{cvRound}(maxRadius) \\
2688+
dsize.height = \texttt{cvRound}(maxRadius \cdot \Pi) \\
2689+
\end{array}\f]
2690+
2691+
2692+
- if only `dsize.height <= 0`,
2693+
the destination image area will be proportional to the bounding circle area but scaled by `Kx * Kx`:
2694+
\f[\begin{array}{l}
2695+
dsize.height = \texttt{cvRound}(dsize.width \cdot \Pi) \\
2696+
\end{array}
2697+
\f]
2698+
2699+
- if both values in `dsize > 0 `,
2700+
the destination image will have the given size therefore the area of the bounding circle will be scaled to `dsize`.
2701+
2702+
2703+
\par Reverse mapping
2704+
2705+
You can get reverse mapping adding #WARP_INVERSE_MAP to `flags`
2706+
\snippet polar_transforms.cpp InverseMap
2707+
2708+
In addiction, to calculate the original coordinate from a polar mapped coordinate \f$(rho, phi)->(x, y)\f$:
2709+
\snippet polar_transforms.cpp InverseCoordinate
2710+
2711+
@param src Source image.
2712+
@param dst Destination image. It will have same type as src.
2713+
@param dsize The destination image size (see description for valid options).
2714+
@param center The transformation center.
2715+
@param maxRadius The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too.
2716+
@param flags A combination of interpolation methods, #InterpolationFlags + #WarpPolarMode.
2717+
- Add #WARP_POLAR_LINEAR to select linear polar mapping (default)
2718+
- Add #WARP_POLAR_LOG to select semilog polar mapping
2719+
- Add #WARP_INVERSE_MAP for reverse mapping.
2720+
@note
2721+
- The function can not operate in-place.
2722+
- To calculate magnitude and angle in degrees #cartToPolar is used internally thus angles are measured from 0 to 360 with accuracy about 0.3 degrees.
2723+
- This function uses #remap. Due to current implementation limitations the size of an input and output images should be less than 32767x32767.
2724+
2725+
@sa cv::remap
2726+
*/
2727+
CV_EXPORTS_W void warpPolar(InputArray src, OutputArray dst, Size dsize,
2728+
Point2f center, double maxRadius, int flags);
2729+
2730+
26222731
//! @} imgproc_transform
26232732

26242733
//! @addtogroup imgproc_misc

‎modules/imgproc/include/opencv2/imgproc/imgproc_c.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,14 @@ CVAPI(void) cvConvertMaps( const CvArr* mapx, const CvArr* mapy,
260260
CvArr* mapxy, CvArr* mapalpha );
261261

262262
/** @brief Performs forward or inverse log-polar image transform
263-
@see cv::logPolar
263+
@see cv::warpPolar
264264
*/
265265
CVAPI(void) cvLogPolar( const CvArr* src, CvArr* dst,
266266
CvPoint2D32f center, double M,
267267
int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS));
268268

269269
/** Performs forward or inverse linear-polar image transform
270-
@see cv::linearPolar
270+
@see cv::warpPolar
271271
*/
272272
CVAPI(void) cvLinearPolar( const CvArr* src, CvArr* dst,
273273
CvPoint2D32f center, double maxRadius,

‎modules/imgproc/perf/opencl/perf_imgwarp.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ OCL_PERF_TEST_P(RemapFixture, Remap,
204204
const RemapParams params = GetParam();
205205
const Size srcSize = get<0>(params);
206206
const int type = get<1>(params), interpolation = get<2>(params), borderMode = BORDER_CONSTANT;
207-
const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
207+
//const double eps = CV_MAT_DEPTH(type) <= CV_32S ? 1 : 1e-4;
208208

209209
checkDeviceMaxMemoryAllocSize(srcSize, type);
210210

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL