ImageMath
Provides affine transformation utilities for image processing....
Declaration
struct ImageMathSummary
Provides affine transformation utilities for image processing. All affine matrices returned by this class operate in normalized coordinates, where image space is mapped to the [0, 1] range in both axes with origin at top-left.
Methods
| Name | Type | Summary |
|---|---|---|
| static affineCrop | CGAffineTransform | |
| static affineFit | CGAffineTransform | Returns an affine transformation that maps normalized coordinates in the source frame to normalized coordinates in the target frame. - Note: In portrait, this function aligns the top and bottom edges to the target. - Parameters: - source: The size of the source container. - sourceOrientation: The orientation of the source container. - target: The size of the target container. - targetOrientation: The orientation of the target container. - Returns: An affine transformation matrix that fits the source into the target. |
| static affineInvertHorizontal | CGAffineTransform | Returns an (u, v) -> (u', v') transformation that represents a horizontal mirroring, i.e. (u, v) -> (1 - u, v). |
| static affineInvertVertical | CGAffineTransform | Returns an (u, v) -> (u', v') transformation that represents a vertical mirroring, i.e. (u, v) -> (u, 1 - v). |
| static affineRotation | CGAffineTransform | Returns an (u, v) -> (u', v') transformation that represents a 2D affine rotation. |
| static affineScaling | CGAffineTransform | Returns an (u, v) -> (u', v') transformation that represents a 2D affine scaling. |
| static affineTranslation | CGAffineTransform | Returns an (u, v) -> (u', v') transformation that represents a 2D affine translation. |
| static deviceRotation | CGAffineTransform | Returns an affine transform that rotates between two interface orientations around the center. This method models physical device rotation. For example, rotating from .landscapeRight to .portrait results in a clockwise transform.- Parameters: - fromOrientation: The starting interface orientation. - toOrientation: The target interface orientation. - Returns: A CGAffineTransform representing the rotation. |
| static displayTransform | CGAffineTransform | Returns an affine transform that maps normalized image coordinates into a coordinate space suitable for rendering the camera image in the given viewport and orientation. This method replicates ARKit’s displayTransform(for:viewportSize:)by computing a transform that accounts for the camera image’s aspect ratio, the device’s interface orientation, and the desired viewport size. - Parameters: - orientation: The current interface orientation of the device’s UI. - viewportSize: The size of the viewport in which the image will be rendered. - imageSize: The dimensions of the camera image. - Returns: A CGAffineTransform that converts normalized image coordinates(with origin at top-left, ranging from 0.0 to 1.0) into the coordinate space of the viewport, accounting for orientation and aspect ratio. |
| static reprojection | matrix_float3x3 | Returns a 3×3 homography matrix as matrix_float3x3 that reprojectsimage coordinates from a reference camera view into a target camera view. The image coordinates are expected to be normalized [0..1]. - Parameters: - aspect: The aspect ratio of the image (width / height). - fovRadians: The vertical field of view in radians. - zNear: Near clipping plane distance. - zFar: Far clipping plane distance. - referenceView: The reference camera view. - targetView: The target camera view. - backProjectionDistance: Depth at which to reproject, normalized between clipping planes near (0) and far (1). Recommended: 0.9. - Returns: A 3×3 homography matrix in column-major order. |
| static viewRotation | CGAffineTransform | Returns an affine transform that rotates between two interface orientations around the center. This method models UI rotation (opposite to physical device rotation). For example, rotating from .landscapeRight to .portrait results in a counter-clockwise transform.- Parameters: - fromOrientation: The starting interface orientation. - toOrientation: The target interface orientation. - Returns: A CGAffineTransform representing the rotation. |
- Parameters:
- source: The size of the source container.
- target: The size of the target container.
- Returns: An affine transformation matrix that crops the source to fit the target aspect ratio.