HMath.Image.Core¶
Module index · Numerical conventions
Description
Finite CPU images with row-major spatial axes and interleaved channels (last axis). Spatial rank is 1–8, channel count 1–16, and total storage at most 262,144 samples. Dimensions are positive; empty images are explicit errors. The immutable constructor owns storage. Intensities have no implicit range; color-space and histogram functions state their stricter range contracts.
On this page¶
| API | Purpose |
|---|---|
| Image | Opaque finite CPU image with row-major spatial axes and interleaved channels. |
| image | Validate all dimensions before allocating boxed immutable array storage. |
| fromTensor | Tensor shape must be spatial dimensions followed by a channel axis. |
| toTensor | Copy an image to Tensor Double with shape spatial dimensions followed by channel count. |
| imageShape | Return spatial dimensions only, excluding the last implicit channel axis. |
| imageChannels | Return channel count, between one and sixteen for validated images. |
| imageValues | Return flat row-major samples with channels interleaved at each spatial coordinate. |
| pixel | Given image then complete spatial coordinates, return all channel values in order. |
| channel | Given zero-based channel index then image, return a copied one-channel image of the same spatial shape. |
| combineChannels | Concatenate channels of a nonempty same-spatial-shape image list in input order. |
| mapImage | Output is validated, including arithmetic overflow inside the callback. |
| zipImage | Given binary sample function then equally shaped/channel-count images, return a new validated image. |
| normalize | Global min/max scaling; a constant image maps to the requested lower bound. |
| brightness | Add a finite offset without implicit clipping. |
| contrast | Scale about a caller-defined pivot, without clipping. |
| gamma | Positive gamma, nonnegative inputs; computes x^gamma without clipping. |
| Boundary | Image sampling policy: Constant fill,edge Clamp,half-sample symmetric Reflect,or periodic Wrap. |
| Constant | Declaration and type contract below. |
| Clamp | Declaration and type contract below. |
| Reflect | Declaration and type contract below. |
| Wrap | Declaration and type contract below. |
| coordinates | Enumerate zero-based row-major coordinates of a dimension list. [] yields [[]]; zero/negative extents yield no coordinates. |
| sample | Reflect is half-sample symmetric (... b a | a b c | c b ...). |
| build | Checked output allocation for internal coordinate-wise reference kernels. |
| at | Unchecked image access: given image,complete spatial coordinates,then channel, return one sample. |
| spatialSize | Return number of spatial pixels (shape product), excluding channel multiplicity. |
| finite | Test whether Double is neither NaN nor infinite. |
| require | Given predicate then diagnostic, return Right () or image-prefixed Left InvalidArgument. |
| checked | Return finite Double values unchanged, or Left NonFiniteResult when any sample is non-finite. |
Documentation
Image
Opaque finite CPU image with row-major spatial axes and interleaved channels. Construct with image; shapechannelstorage limits are checked.
image
image :: [Int] -> Int -> [Double] -> Either MathError Image Source #
Validate all dimensions before allocating boxed immutable array storage.
fromTensor
fromTensor :: Tensor Double -> Either MathError Image Source #
Tensor shape must be spatial dimensions followed by a channel axis.
toTensor
toTensor :: Image -> Either MathError (Tensor Double) Source #
Copy an image to Tensor Double with shape spatial dimensions followed by channel count. Values remain row-major with interleaved channels; checked tensor size errors propagate.
imageShape
imageShape :: Image -> [Int] Source #
Return spatial dimensions only, excluding the last implicit channel axis.
imageChannels
imageChannels :: Image -> Int Source #
Return channel count, between one and sixteen for validated images.
imageValues
imageValues :: Image -> [Double] Source #
Return flat row-major samples with channels interleaved at each spatial coordinate.
pixel
pixel :: Image -> [Int] -> Either MathError [Double] Source #
Given image then complete spatial coordinates, return all channel values in order. Invalid coordinate rank/range returns Left InvalidArgument.
channel
channel :: Int -> Image -> Either MathError Image Source #
Given zero-based channel index then image, return a copied one-channel image of the same spatial shape. Invalid channel index fails.
combineChannels
combineChannels :: [Image] -> Either MathError Image Source #
Concatenate channels of a nonempty same-spatial-shape image list in input order. Require total channels<=16; shape/count or checked storage limits fail.
mapImage
mapImage :: (Double -> Double) -> Image -> Either MathError Image Source #
Output is validated, including arithmetic overflow inside the callback.
zipImage
zipImage :: (Double -> Double -> Double) -> Image -> Image -> Either MathError Image Source #
Given binary sample function then equally shaped/channel-count images, return a new validated image. Mismatched shape/channels or non-finite output returns Left MathError.
normalize
normalize :: Double -> Double -> Image -> Either MathError Image Source #
Global min/max scaling; a constant image maps to the requested lower bound.
brightness
brightness :: Double -> Image -> Either MathError Image Source #
Add a finite offset without implicit clipping.
contrast
contrast :: Double -> Double -> Image -> Either MathError Image Source #
Scale about a caller-defined pivot, without clipping.
gamma
gamma :: Double -> Image -> Either MathError Image Source #
Positive gamma, nonnegative inputs; computes x^gamma without clipping.
Boundary
Image sampling policy: Constant fill,edge Clamp,half-sample symmetric Reflect,or periodic Wrap.
Instances
coordinates
coordinates :: [Int] -> [[Int]] Source #
Enumerate zero-based row-major coordinates of a dimension list. [] yields [[]]; zero/negative extents yield no coordinates. This helper performs no image validation.
sample
sample :: Boundary -> Image -> [Int] -> Int -> Double Source #
Reflect is half-sample symmetric (... b a | a b c | c b ...). Boundary rankchannel validation belongs to the checked filterwarp caller.
build
build :: [Int] -> Int -> ([Int] -> Int -> Double) -> Either MathError Image Source #
Checked output allocation for internal coordinate-wise reference kernels.
at
at :: Image -> [Int] -> Int -> Double Source #
Unchecked image access: given image,complete spatial coordinates,then channel, return one sample. Checked callers must validate rank/ranges; invalid indices can raise an array error.
spatialSize
spatialSize :: Image -> Int Source #
Return number of spatial pixels (shape product), excluding channel multiplicity.