Skip to content

HMath.Image

Module index · Numerical conventions

Description

Finite ND CPU images and bounded reference color, filtering, resampling, histogram, topology, and measurement operations. Color spaces, boundary extension, channel layout, and intensity range are explicit in each API.

On this page

API Purpose
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.
Image Opaque finite CPU image with row-major spatial axes and interleaved channels.
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.
normalize Global min/max scaling; a constant image maps to the requested lower bound.
gamma Positive gamma, nonnegative inputs; computes x^gamma without clipping.
image Validate all dimensions before allocating boxed immutable array storage.
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.
brightness Add a finite offset without implicit clipping.
contrast Scale about a caller-defined pivot, without clipping.
gradient Returns row derivative, column derivative, magnitude, and atan2(row,col) direction in radians.
laplacian Given boundary then one-channel 2D image, apply the four-neighbor 3-by-3 Laplacian [0,1,0;1,-4,1;0,1,0].
convolve Given boundary,kernel dimensions,flat weights,then image, reverse all kernel axes and correlate.
correlate Correlation uses sample(ix+kernelOffset-center).
gaussianBlur Separable Gaussian, truncated at an explicitly supplied integer radius.
boxBlur Given boundary,radius,then image, average a centered full-dimensional box neighborhood independently per channel.
medianBlur Given boundary,radius,then image, choose the median of each centered odd-sized neighborhood independently per channel.
bilateralBlur Per-channel bilateral filtering: spatial and range Gaussian weights are multiplied, normalized locally, and computed relative to the center sample.
sharpen Unsharp mask x+amount*(x-Gaussian(x)); no implicit range clipping.
GradientOperator Image gradient stencil selector, choosing Sobel,Prewitt,or Scharr.
Sobel Declaration and type contract below.
Prewitt Declaration and type contract below.
Scharr Declaration and type contract below.
canny Canny: Gaussian smoothing, Sobel gradient, four-direction nonmaximum suppression, and 8-connected hysteresis. low/high are absolute normalized gradient magnitudes, not quantiles.
Morphology Grayscale footprint operation selector: erosion,dilation,opening,or closing.
Erosion Declaration and type contract below.
Dilation Declaration and type contract below.
Opening Declaration and type contract below.
Closing Declaration and type contract below.
morphology Flat grayscale morphology with an explicit odd-rank Boolean footprint.
morphologicalGradient Given boundary,footprint dimensions,Bool footprint,then image, return dilation minus erosion.

Documentation

Boundary

data Boundary Source #

Image sampling policy: Constant fill,edge Clamp,half-sample symmetric Reflect,or periodic Wrap.

Constructors

Constant Double 
Clamp 
Reflect 
Wrap 

Instances

Instances details
Show Boundary Source # 
Instance details

Defined in HMath.Image.Core

Eq Boundary Source # 
Instance details

Defined in HMath.Image.Core

Image

data Image Source #

Opaque finite CPU image with row-major spatial axes and interleaved channels. Construct with image; shapechannelstorage limits are checked.

Instances

Instances details
Show Image Source # 
Instance details

Defined in HMath.Image.Core

Methods

showsPrec :: Int -> Image -> ShowS #

show :: Image -> String #

showList :: [Image] -> ShowS #

Eq Image Source # 
Instance details

Defined in HMath.Image.Core

Methods

(==) :: Image -> Image -> Bool #

(/=) :: Image -> Image -> Bool #

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.

normalize

normalize :: Double -> Double -> Image -> Either MathError Image Source #

Global min/max scaling; a constant image maps to the requested lower bound.

gamma

gamma :: Double -> Image -> Either MathError Image Source #

Positive gamma, nonnegative inputs; computes x^gamma without clipping.

image

image :: [Int] -> Int -> [Double] -> Either MathError Image Source #

Validate all dimensions before allocating boxed immutable array storage.

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.

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.

gradient

gradient :: GradientOperator -> Boundary -> Image -> Either MathError (Image, Image, Image, Image) Source #

Returns row derivative, column derivative, magnitude, and atan2(row,col) direction in radians. Smoothing/derivative kernels are normalized so an interior unit ramp has derivative one.

laplacian

laplacian :: Boundary -> Image -> Either MathError Image Source #

Given boundary then one-channel 2D image, apply the four-neighbor 3-by-3 Laplacian [0,1,0;1,-4,1;0,1,0]. Invalid image/boundary or non-finite output fails.

convolve

convolve :: Boundary -> [Int] -> [Double] -> Image -> Either MathError Image Source #

Given boundary,kernel dimensions,flat weights,then image, reverse all kernel axes and correlate. Channels are filtered independently; require odd extents<=65, matching rankcount, <=4096 weights and <=20000000 sample operations. Invalidnon-finite input/result fails.

correlate

correlate :: Boundary -> [Int] -> [Double] -> Image -> Either MathError Image Source #

Correlation uses sample(ix+kernelOffset-center). Convolution reverses all kernel axes; channels are filtered independently without channel mixing.

gaussianBlur

gaussianBlur :: Boundary -> Double -> Int -> Image -> Either MathError Image Source #

Separable Gaussian, truncated at an explicitly supplied integer radius.

boxBlur

boxBlur :: Boundary -> Int -> Image -> Either MathError Image Source #

Given boundary,radius,then image, average a centered full-dimensional box neighborhood independently per channel. Neighborhood/work bounds and boundary finiteness are checked; invalid/non-finite output fails.

medianBlur

medianBlur :: Boundary -> Int -> Image -> Either MathError Image Source #

Given boundary,radius,then image, choose the median of each centered odd-sized neighborhood independently per channel. Invalid boundaryneighborhoodwork bounds fail.

bilateralBlur

bilateralBlur :: Boundary -> Double -> Double -> Int -> Image -> Either MathError Image Source #

Per-channel bilateral filtering: spatial and range Gaussian weights are multiplied, normalized locally, and computed relative to the center sample.

sharpen

sharpen :: Boundary -> Double -> Double -> Int -> Image -> Either MathError Image Source #

Unsharp mask x+amount*(x-Gaussian(x)); no implicit range clipping.

GradientOperator

data GradientOperator Source #

Image gradient stencil selector, choosing Sobel,Prewitt,or Scharr.

Constructors

Sobel 
Prewitt 
Scharr 

canny

canny :: Boundary -> Double -> Int -> Double -> Double -> Image -> Either MathError Image Source #

Canny: Gaussian smoothing, Sobel gradient, four-direction nonmaximum suppression, and 8-connected hysteresis. low/high are absolute normalized gradient magnitudes, not quantiles. Output is exactly zero or one.

Morphology

data Morphology Source #

Grayscale footprint operation selector: erosion,dilation,opening,or closing.

Constructors

Erosion 
Dilation 
Opening 
Closing 

Instances

Instances details
Show Morphology Source # 
Instance details

Defined in HMath.Image.Filter

Eq Morphology Source # 
Instance details

Defined in HMath.Image.Filter

morphology

morphology :: Morphology -> Boundary -> [Int] -> [Bool] -> Image -> Either MathError Image Source #

Flat grayscale morphology with an explicit odd-rank Boolean footprint. Erosion samples x+offset; dilation samples x-offset (reflected footprint), so asymmetric footprints obey the usual adjunction. Opening/closing compose these operators under the same caller-selected boundary extension.

morphologicalGradient

morphologicalGradient :: Boundary -> [Int] -> [Bool] -> Image -> Either MathError Image Source #

Given boundary,footprint dimensions,Bool footprint,then image, return dilation minus erosion. Shapefootprintwork/boundary validation and finite output checks propagate from morphology.