Skip to content

warpPolar

Image processingfunctionOpenCV 5.0.0
import { warpPolar } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

Remaps an image to polar or semilog-polar coordinates space

Polar remaps reference

Transform the source image using the following transformation:


dst(\rho , \phi ) = src(x,y)

where


\begin{array}{l}
\vec{I} = (x - center.x, \;y - center.y) \\
\phi = Kangle \cdot \texttt{angle} (\vec{I}) \\
\rho = \left\{\begin{matrix}
Klin \cdot \texttt{magnitude} (\vec{I}) & default \\
Klog \cdot log_e(\texttt{magnitude} (\vec{I})) & if \; semilog \\
\end{matrix}\right.
\end{array}

and


\begin{array}{l}
Kangle = dsize.height / 2\Pi \\
Klin = dsize.width / maxRadius \\
Klog = dsize.width / log_e(maxRadius) \\
\end{array}

\par Linear vs semilog mapping

Polar mapping can be linear or semi-log. Add one of #WarpPolarMode to flags to specify the polar mapping mode.

Linear is the default mode.

The semilog mapping emulates the human "foveal" vision that permit very high acuity on the line of sight (central vision) in contrast to peripheral vision where acuity is minor.

\par Option on dsize:

  • if both values in dsize <=0 (default), the destination image will have (almost) same area of source bounding circle:
\begin{array}{l}
dsize.area  \leftarrow (maxRadius^2 \cdot \Pi) \\
dsize.width = \texttt{cvRound}(maxRadius) \\
dsize.height = \texttt{cvRound}(maxRadius \cdot \Pi) \\
\end{array}
  • if only dsize.height <= 0, the destination image area will be proportional to the bounding circle area but scaled by Kx * Kx:
\begin{array}{l}
dsize.height = \texttt{cvRound}(dsize.width \cdot \Pi) \\
\end{array}
  • if both values in dsize > 0 , the destination image will have the given size therefore the area of the bounding circle will be scaled to dsize.

\par Reverse mapping

You can get reverse mapping adding #WARP_INVERSE_MAP to flags \snippet polar_transforms.cpp InverseMap

In addition, to calculate the original coordinate from a polar mapped coordinate (rho, phi)->(x, y): \snippet polar_transforms.cpp InverseCoordinate

Note: - The function can not operate in-place.

  • 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.
  • This function uses #remap. Due to current implementation limitations the size of an input and output images should be less than 32767x32767.

See: cv::remap

warpPolar(src: Mat, dst: Mat, dsize: Size, center: Point2f, maxRadius: number, flags: number): void;
src

Source image.

dst

Output destination, filled by the native operation. Destination image. It will have same type as src.

dsize

The destination image size (see description for valid options).

center

The transformation center.

maxRadius

The radius of the bounding circle to transform. It determines the inverse magnitude scale parameter too.

flags

A combination of interpolation methods, #InterpolationFlags + #WarpPolarMode.

  • Add #WARP_POLAR_LINEAR to select linear polar mapping (default)
  • Add #WARP_POLAR_LOG to select semilog polar mapping
  • Add #WARP_INVERSE_MAP for reverse mapping.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.