#walkzzz/image.mbt/process/transform

    几何变换(仿射、透视、Seam Carving、金字塔、极坐标)

    #概览

    项目数量
    公开函数77
    公开类型2
    常量0
    错误类型0

    #类型

    pub(all) struct AffineMatrix {
    pub(all) struct PerspectiveMatrix {

    #API

    pub fn build_gaussian_pyramid(@types.Image, Int) -> Array[@types.Image] raise @types.LoadError
    pub fn build_gaussian_pyramid_16(@types.Image16, Int) -> Array[@types.Image16] raise @types.LoadError
    pub fn build_gaussian_pyramid_f(@types.ImageF, Int) -> Array[@types.ImageF] raise @types.LoadError
    pub fn build_laplacian_pyramid(@types.Image, Int) -> Array[@types.Image] raise @types.LoadError
    pub fn build_laplacian_pyramid_16(@types.Image16, Int) -> Array[@types.Image16] raise @types.LoadError
    pub fn build_laplacian_pyramid_float(@types.ImageF, Int) -> Array[@types.ImageF] raise @types.LoadError
    pub fn compute_energy(@types.Image) -> Array[Double]
    pub fn compute_energy_16(@types.Image16) -> Array[Double]
    pub fn compute_energy_f(@types.ImageF) -> Array[Double]
    pub fn crop(@types.Image, Int, Int, Int, Int) -> @types.Image raise @types.LoadError
    pub fn crop_16(@types.Image16, Int, Int, Int, Int) -> @types.Image16 raise @types.LoadError
    pub fn crop_f(@types.ImageF, Int, Int, Int, Int) -> @types.ImageF raise @types.LoadError
    pub fn draw_circle(@types.Image, Int, Int, Int, Array[Byte], thickness? : Int, fill? : Bool) -> @types.Image
    pub fn draw_circle_16(@types.Image16, Int, Int, Int, Array[Int], thickness? : Int, fill? : Bool) -> @types.Image16
    pub fn draw_circle_f(@types.ImageF, Int, Int, Int, Array[Float], thickness? : Int, fill? : Bool) -> @types.ImageF
    pub fn draw_copy(@types.Image, @types.Image, Int, Int) -> @types.Image raise @types.LoadError
    pub fn draw_line(@types.Image, Int, Int, Int, Int, Array[Byte], thickness? : Int) -> @types.Image
    pub fn draw_line_16(@types.Image16, Int, Int, Int, Int, Array[Int], thickness? : Int) -> @types.Image16
    pub fn draw_line_f(@types.ImageF, Int, Int, Int, Int, Array[Float], thickness? : Int) -> @types.ImageF
    pub fn draw_over(@types.Image, @types.Image, Int, Int) -> @types.Image raise @types.LoadError
    pub fn draw_polygon(@types.Image, Array[(Int, Int)], Array[Byte], thickness? : Int, fill? : Bool) -> @types.Image
    pub fn draw_polygon_16(@types.Image16, Array[(Int, Int)], Array[Int], thickness? : Int) -> @types.Image16
    pub fn draw_polygon_f(@types.ImageF, Array[(Int, Int)], Array[Float], thickness? : Int) -> @types.ImageF
    pub fn draw_rectangle(@types.Image, Int, Int, Int, Int, Array[Byte], thickness? : Int, fill? : Bool) -> @types.Image
    pub fn draw_rectangle_16(@types.Image16, Int, Int, Int, Int, Array[Int], thickness? : Int, fill? : Bool) -> @types.Image16
    pub fn draw_rectangle_f(@types.ImageF, Int, Int, Int, Int, Array[Float], thickness? : Int, fill? : Bool) -> @types.ImageF
    pub fn find_horizontal_seam(Array[Double], Int, Int) -> Array[Int]
    pub fn find_vertical_seam(Array[Double], Int, Int) -> Array[Int]
    pub fn flip_horizontal(@types.Image) -> @types.Image
    pub fn flip_horizontal_16(@types.Image16) -> @types.Image16
    pub fn flip_horizontal_f(@types.ImageF) -> @types.ImageF
    pub fn flip_vertical(@types.Image) -> @types.Image
    pub fn flip_vertical_16(@types.Image16) -> @types.Image16
    pub fn flip_vertical_f(@types.ImageF) -> @types.ImageF
    pub fn get_affine_transform(Array[(Float, Float)], Array[(Float, Float)]) -> AffineMatrix?
    pub fn get_perspective_transform(Array[(Float, Float)], Array[(Float, Float)]) -> PerspectiveMatrix?
    pub fn get_rotation_matrix_2d((Float, Float), Float, Float) -> AffineMatrix
    pub fn multi_band_blend(@types.Image, @types.Image, @types.Image, num_bands? : Int) -> @types.Image raise @types.LoadError
    pub fn multi_band_blend_16(@types.Image16, @types.Image16, @types.Image16, num_bands? : Int) -> @types.Image16 raise @types.LoadError
    pub fn multi_band_blend_f(@types.ImageF, @types.ImageF, @types.ImageF, num_bands? : Int) -> @types.ImageF raise @types.LoadError
    pub fn pyr_down(@types.Image) -> @types.Image raise @types.LoadError
    pub fn pyr_down_16(@types.Image16) -> @types.Image16 raise @types.LoadError
    pub fn pyr_down_f(@types.ImageF) -> @types.ImageF raise @types.LoadError
    pub fn pyr_up(@types.Image) -> @types.Image raise @types.LoadError
    pub fn pyr_up_16(@types.Image16) -> @types.Image16 raise @types.LoadError
    pub fn pyr_up_f(@types.ImageF) -> @types.ImageF raise @types.LoadError
    pub fn remove_horizontal_seam(@types.Image, Array[Int]) -> @types.Image
    pub fn remove_horizontal_seam_16(@types.Image16, Array[Int]) -> @types.Image16
    pub fn remove_horizontal_seam_f(@types.ImageF, Array[Int]) -> @types.ImageF
    pub fn remove_vertical_seam(@types.Image, Array[Int]) -> @types.Image
    pub fn remove_vertical_seam_16(@types.Image16, Array[Int]) -> @types.Image16
    pub fn remove_vertical_seam_f(@types.ImageF, Array[Int]) -> @types.ImageF
    pub fn resize_16(@types.Image16, Int, Int) -> @types.Image16
    pub fn resize_f(@types.ImageF, Int, Int) -> @types.ImageF
    pub fn resize_to_contain(@types.Image, Int, Int, Array[Byte]) -> @types.Image raise @types.LoadError
    pub fn resize_to_cover(@types.Image, Int, Int) -> @types.Image raise @types.LoadError
    pub fn rotate(@types.Image, Float) -> @types.Image
    pub fn rotate_180(@types.Image) -> @types.Image
    pub fn rotate_180_16(@types.Image16) -> @types.Image16
    pub fn rotate_180_f(@types.ImageF) -> @types.ImageF
    pub fn rotate_270(@types.Image) -> @types.Image
    pub fn rotate_270_16(@types.Image16) -> @types.Image16
    pub fn rotate_270_f(@types.ImageF) -> @types.ImageF
    pub fn rotate_90(@types.Image) -> @types.Image
    pub fn rotate_90_16(@types.Image16) -> @types.Image16
    pub fn rotate_90_f(@types.ImageF) -> @types.ImageF
    pub fn seam_carve_resize(@types.Image, Int, Int) -> @types.Image raise @types.LoadError
    pub fn seam_carve_resize_16(@types.Image16, Int, Int) -> @types.Image16 raise @types.LoadError
    pub fn seam_carve_resize_f(@types.ImageF, Int, Int) -> @types.ImageF raise @types.LoadError
    pub fn transpose_16(@types.Image16) -> @types.Image16
    pub fn transpose_f(@types.ImageF) -> @types.ImageF
    pub fn warp_affine(@types.Image, (Float, Float, Float, Float, Float, Float), Int, Int) -> @types.Image
    pub fn warp_affine_16(@types.Image16, (Float, Float, Float, Float, Float, Float), Int, Int) -> @types.Image16
    pub fn warp_affine_f(@types.ImageF, (Float, Float, Float, Float, Float, Float), Int, Int) -> @types.ImageF
    pub fn warp_perspective(@types.Image, PerspectiveMatrix, Int, Int) -> @types.Image
    pub fn warp_perspective_16(@types.Image16, PerspectiveMatrix, Int, Int) -> @types.Image16
    pub fn warp_perspective_f(@types.ImageF, PerspectiveMatrix, Int, Int) -> @types.ImageF

    #纯 MoonBit 实现

    本包不依赖任何 C FFI,四目标(native/wasm-gc/js/wasm)均可编译运行。

    AffineMatrix

    pub(all) struct AffineMatrix {
    a : Float
    b : Float
    c : Float
    d : Float
    e : Float
    f : Float
    }

    2×3 仿射变换矩阵 (a, b, c, d, e, f) 正向仿射变换 x' = ax + by + c 正向仿射变换 y' = dx + ey + f

    PerspectiveMatrix

    pub(all) struct PerspectiveMatrix {
    m00 : Float
    m01 : Float
    m02 : Float
    m10 : Float
    m11 : Float
    m12 : Float
    m20 : Float
    m21 : Float
    m22 : Float
    }

    3×3 透视变换矩阵 (m00, m01, m02, m10, m11, m12, m20, m21, m22)

    build_gaussian_pyramid

    fn build_gaussian_pyramid(img :
    core
    /types.Image, levels : Int) -> Array[
    core
    /types.Image] raise
    core
    /types.LoadError

    构建高斯金字塔。返回各级图像(从原图到最小级),levels 为最大层数(0=自动到 1x1)。

    build_gaussian_pyramid_16

    fn build_gaussian_pyramid_16(img :
    core
    /types.Image16, levels : Int) -> Array[
    core
    /types.Image16] raise
    core
    /types.LoadError

    构建高斯金字塔 16-bit 版本。 @see build_gaussian_pyramid 8-bit 版本,本函数为 Image16 变体

    build_gaussian_pyramid_f

    fn build_gaussian_pyramid_f(img :
    core
    /types.ImageF, levels : Int) -> Array[
    core
    /types.ImageF] raise
    core
    /types.LoadError

    构建高斯金字塔 float 版本。 @see build_gaussian_pyramid 8-bit 版本,本函数为 ImageF 变体

    build_laplacian_pyramid

    fn build_laplacian_pyramid(img :
    core
    /types.Image, levels : Int) -> Array[
    core
    /types.Image] raise
    core
    /types.LoadError

    构建拉普拉斯金字塔。返回各级拉普拉斯图像(高斯金字塔相邻层之差)。 最后一层为高斯金字塔的最小级(不加差)。

    build_laplacian_pyramid_16

    fn build_laplacian_pyramid_16(img :
    core
    /types.Image16, levels : Int) -> Array[
    core
    /types.Image16] raise
    core
    /types.LoadError

    构建拉普拉斯金字塔 16-bit 版本。 @see build_laplacian_pyramid 8-bit 版本,本函数为 Image16 变体

    build_laplacian_pyramid_float

    fn build_laplacian_pyramid_float(img :
    core
    /types.ImageF, levels : Int) -> Array[
    core
    /types.ImageF] raise
    core
    /types.LoadError

    构建拉普拉斯金字塔 float 版本。

    compute_energy

    fn compute_energy(img :
    core
    /types.Image) -> Array[Double]

    计算图像能量图(Sobel 梯度幅值 |Gx| + |Gy|)

    compute_energy_16

    fn compute_energy_16(img :
    core
    /types.Image16) -> Array[Double]

    计算图像能量图 16-bit 版本 @see compute_energy 8-bit 版本,本函数为 Image16 变体

    compute_energy_f

    fn compute_energy_f(img :
    core
    /types.ImageF) -> Array[Double]

    计算图像能量图 float 版本 @see compute_energy 8-bit 版本,本函数为 ImageF 变体

    crop

    fn crop(img :
    core
    /types.Image, x : Int, y : Int, w : Int, h : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    裁剪 8-bit Image 的指定区域

    crop_16

    fn crop_16(img :
    core
    /types.Image16, x : Int, y : Int, w : Int, h : Int) ->
    core
    /types.Image16 raise
    core
    /types.LoadError

    裁剪 16-bit Image16 @see crop 8-bit 版本,本函数为 Image16 变体

    crop_f

    fn crop_f(img :
    core
    /types.ImageF, x : Int, y : Int, w : Int, h : Int) ->
    core
    /types.ImageF raise
    core
    /types.LoadError

    裁剪 float ImageF @see crop 8-bit 版本,本函数为 ImageF 变体

    crop_region

    fn crop_region(img :
    core
    /types.Image, region :
    core
    /types.Region) ->
    core
    /types.Image

    按 Region 裁剪,越界部分自动裁掉(不报错)。空区域返回 0×0 图。 内部走零复制的 ImageRegion 视图,只为目标像素分配一次内存。

    draw_circle

    fn draw_circle(img :
    core
    /types.Image, cx : Int, cy : Int, r : Int, color : Array[Byte], thickness? : Int, fill? : Bool) ->
    core
    /types.Image

    画圆(中点画圆算法)。color 为颜色数组。thickness 为线宽(默认 1)。fill 为是否填充(默认 false)。

    draw_circle_16

    fn draw_circle_16(img :
    core
    /types.Image16, cx : Int, cy : Int, r : Int, color : Array[Int], thickness? : Int, fill? : Bool) ->
    core
    /types.Image16

    16-bit 绘制圆形。 @see draw_circle 8-bit 版本,本函数为 Image16 变体

    draw_circle_f

    fn draw_circle_f(img :
    core
    /types.ImageF, cx : Int, cy : Int, r : Int, color : Array[Float], thickness? : Int, fill? : Bool) ->
    core
    /types.ImageF

    float 绘制圆形。 @see draw_circle 8-bit 版本,本函数为 ImageF 变体

    draw_copy

    fn draw_copy(dst :
    core
    /types.Image, src :
    core
    /types.Image, x : Int, y : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    将 src 图像直接拷贝到 dst 的 (x, y) 位置 返回新的 Image,不修改原图。要求 dst 和 src channels 相同。

    draw_line

    fn draw_line(img :
    core
    /types.Image, x1 : Int, y1 : Int, x2 : Int, y2 : Int, color : Array[Byte], thickness? : Int) ->
    core
    /types.Image

    画线段(Bresenham 算法)。color 为颜色数组(如 [R,G,B])。thickness 为线宽(默认 1)。

    draw_line_16

    fn draw_line_16(img :
    core
    /types.Image16, x1 : Int, y1 : Int, x2 : Int, y2 : Int, color : Array[Int], thickness? : Int) ->
    core
    /types.Image16

    16-bit 绘制直线。 @see draw_line 8-bit 版本,本函数为 Image16 变体

    draw_line_f

    fn draw_line_f(img :
    core
    /types.ImageF, x1 : Int, y1 : Int, x2 : Int, y2 : Int, color : Array[Float], thickness? : Int) ->
    core
    /types.ImageF

    float 绘制直线。 @see draw_line 8-bit 版本,本函数为 ImageF 变体

    draw_over

    fn draw_over(dst :
    core
    /types.Image, src :
    core
    /types.Image, x : Int, y : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    Alpha 混合合成(source over destination) 将 src 图像合成到 dst 的 (x, y) 位置 要求 dst 和 src 均为 RGBA (channels=4) 公式: result = src * src_a + dst * (1 - src_a)

    draw_polygon

    fn draw_polygon(img :
    core
    /types.Image, points : Array[(Int, Int)], color : Array[Byte], thickness? : Int, fill? : Bool) ->
    core
    /types.Image

    画多边形。points 为顶点数组 [(x1,y1), (x2,y2), ...]。color 为颜色数组。thickness 为线宽(默认 1)。fill 为是否填充(默认 false)。

    draw_polygon_16

    fn draw_polygon_16(img :
    core
    /types.Image16, points : Array[(Int, Int)], color : Array[Int], thickness? : Int) ->
    core
    /types.Image16

    16-bit 绘制多边形。 @see draw_polygon 8-bit 版本,本函数为 Image16 变体

    draw_polygon_f

    fn draw_polygon_f(img :
    core
    /types.ImageF, points : Array[(Int, Int)], color : Array[Float], thickness? : Int) ->
    core
    /types.ImageF

    float 绘制多边形。 @see draw_polygon 8-bit 版本,本函数为 ImageF 变体

    draw_rectangle

    fn draw_rectangle(img :
    core
    /types.Image, x : Int, y : Int, rw : Int, rh : Int, color : Array[Byte], thickness? : Int, fill? : Bool) ->
    core
    /types.Image

    画矩形。color 为颜色数组。thickness 为线宽(默认 1)。fill 为是否填充(默认 false)。

    draw_rectangle_16

    fn draw_rectangle_16(img :
    core
    /types.Image16, x : Int, y : Int, rw : Int, rh : Int, color : Array[Int], thickness? : Int, fill? : Bool) ->
    core
    /types.Image16

    16-bit 绘制矩形。 @see draw_rectangle 8-bit 版本,本函数为 Image16 变体

    draw_rectangle_f

    fn draw_rectangle_f(img :
    core
    /types.ImageF, x : Int, y : Int, rw : Int, rh : Int, color : Array[Float], thickness? : Int, fill? : Bool) ->
    core
    /types.ImageF

    float 绘制矩形。 @see draw_rectangle 8-bit 版本,本函数为 ImageF 变体

    find_horizontal_seam

    fn find_horizontal_seam(energy : Array[Double], w : Int, h : Int) -> Array[Int]

    找水平最小能量 seam(返回每列的行索引,长度为 w)

    find_vertical_seam

    fn find_vertical_seam(energy : Array[Double], w : Int, h : Int) -> Array[Int]

    找垂直最小能量 seam(返回每行的列索引,长度为 h)

    flip_horizontal

    fn flip_horizontal(img :
    core
    /types.Image) ->
    core
    /types.Image

    水平翻转(左右镜像)

    flip_horizontal_16

    fn flip_horizontal_16(img :
    core
    /types.Image16) ->
    core
    /types.Image16

    @see flip_horizontal 8-bit 版本,本函数为 Image16 变体

    flip_horizontal_f

    fn flip_horizontal_f(img :
    core
    /types.ImageF) ->
    core
    /types.ImageF

    @see flip_horizontal 8-bit 版本,本函数为 ImageF 变体

    flip_vertical

    fn flip_vertical(img :
    core
    /types.Image) ->
    core
    /types.Image

    垂直翻转(上下镜像)

    flip_vertical_16

    fn flip_vertical_16(img :
    core
    /types.Image16) ->
    core
    /types.Image16

    16-bit 垂直翻转。上下镜像。 @see flip_vertical 8-bit 版本,本函数为 Image16 变体

    flip_vertical_f

    fn flip_vertical_f(img :
    core
    /types.ImageF) ->
    core
    /types.ImageF

    float 垂直翻转。上下镜像。 @see flip_vertical 8-bit 版本,本函数为 ImageF 变体

    get_affine_transform

    fn get_affine_transform(src : Array[(Float, Float)], dst : Array[(Float, Float)]) -> AffineMatrix?

    从 3 对源点→目标点计算 2×3 仿射变换矩阵。

    get_perspective_transform

    fn get_perspective_transform(src : Array[(Float, Float)], dst : Array[(Float, Float)]) -> PerspectiveMatrix?

    从 4 对源点→目标点计算 3×3 透视变换矩阵。 src 和 dst 均为 4 个 (Float, Float) 点。

    get_rotation_matrix_2d

    fn get_rotation_matrix_2d(center : (Float, Float), angle : Float, scale : Float) -> AffineMatrix

    从中心点、角度和缩放计算 2×3 旋转矩阵。 angle 为弧度,scale 为缩放因子。

    multi_band_blend

    fn multi_band_blend(img_a :
    core
    /types.Image, img_b :
    core
    /types.Image, mask :
    core
    /types.Image, num_bands? : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    多频带融合(Laplacian pyramid blend)。 img_a 和 img_b 尺寸需相同,mask 为灰度图(非零区域取 img_a,零区域取 img_b)。 num_bands 为金字塔层数(默认 5)。

    multi_band_blend_16

    fn multi_band_blend_16(img_a :
    core
    /types.Image16, img_b :
    core
    /types.Image16, mask :
    core
    /types.Image16, num_bands? : Int) ->
    core
    /types.Image16 raise
    core
    /types.LoadError

    多频带融合 16-bit 版本。 @see multi_band_blend 8-bit 版本,本函数为 Image16 变体

    multi_band_blend_f

    fn multi_band_blend_f(img_a :
    core
    /types.ImageF, img_b :
    core
    /types.ImageF, mask :
    core
    /types.ImageF, num_bands? : Int) ->
    core
    /types.ImageF raise
    core
    /types.LoadError

    多频带融合 float 版本。 @see multi_band_blend 8-bit 版本,本函数为 ImageF 变体

    pyr_down

    fn pyr_down(img :
    core
    /types.Image) ->
    core
    /types.Image raise
    core
    /types.LoadError

    高斯金字塔下采样。将图像尺寸减半(宽高各 /2),使用 2x2 均值滤波。

    pyr_down_16

    fn pyr_down_16(img :
    core
    /types.Image16) ->
    core
    /types.Image16 raise
    core
    /types.LoadError

    高斯金字塔下采样 16-bit 版本。 @see pyr_down 8-bit 版本,本函数为 Image16 变体

    pyr_down_f

    fn pyr_down_f(img :
    core
    /types.ImageF) ->
    core
    /types.ImageF raise
    core
    /types.LoadError

    高斯金字塔下采样 float 版本。 @see pyr_down 8-bit 版本,本函数为 ImageF 变体

    pyr_up

    fn pyr_up(img :
    core
    /types.Image) ->
    core
    /types.Image raise
    core
    /types.LoadError

    拉普拉斯金字塔上采样。将图像尺寸加倍(宽高各 *2),使用双线性插值。

    pyr_up_16

    fn pyr_up_16(img :
    core
    /types.Image16) ->
    core
    /types.Image16 raise
    core
    /types.LoadError

    拉普拉斯金字塔上采样 16-bit 版本。 @see pyr_up 8-bit 版本,本函数为 Image16 变体

    pyr_up_f

    fn pyr_up_f(img :
    core
    /types.ImageF) ->
    core
    /types.ImageF raise
    core
    /types.LoadError

    拉普拉斯金字塔上采样 float 版本。 @see pyr_up 8-bit 版本,本函数为 ImageF 变体

    remove_horizontal_seam

    fn remove_horizontal_seam(img :
    core
    /types.Image, seam : Array[Int]) ->
    core
    /types.Image

    移除水平 seam,高度减 1

    remove_horizontal_seam_16

    fn remove_horizontal_seam_16(img :
    core
    /types.Image16, seam : Array[Int]) ->
    core
    /types.Image16

    移除水平 seam 16-bit 版本 @see remove_horizontal_seam 8-bit 版本,本函数为 Image16 变体

    remove_horizontal_seam_f

    fn remove_horizontal_seam_f(img :
    core
    /types.ImageF, seam : Array[Int]) ->
    core
    /types.ImageF

    移除水平 seam float 版本 @see remove_horizontal_seam 8-bit 版本,本函数为 ImageF 变体

    remove_vertical_seam

    fn remove_vertical_seam(img :
    core
    /types.Image, seam : Array[Int]) ->
    core
    /types.Image

    移除垂直 seam,宽度减 1

    remove_vertical_seam_16

    fn remove_vertical_seam_16(img :
    core
    /types.Image16, seam : Array[Int]) ->
    core
    /types.Image16

    移除垂直 seam 16-bit 版本 @see remove_vertical_seam 8-bit 版本,本函数为 Image16 变体

    remove_vertical_seam_f

    fn remove_vertical_seam_f(img :
    core
    /types.ImageF, seam : Array[Int]) ->
    core
    /types.ImageF

    移除垂直 seam float 版本 @see remove_vertical_seam 8-bit 版本,本函数为 ImageF 变体

    resize_16

    fn resize_16(img :
    core
    /types.Image16, new_w : Int, new_h : Int) ->
    core
    /types.Image16

    16-bit 图像缩放。 @see resize 8-bit 版本,本函数为 Image16 变体

    resize_f

    fn resize_f(img :
    core
    /types.ImageF, new_w : Int, new_h : Int) ->
    core
    /types.ImageF

    float 图像缩放。 @see resize 8-bit 版本,本函数为 ImageF 变体

    resize_subsample

    fn resize_subsample(img :
    core
    /types.Image, out_w : Int, out_h : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    面积平均重采样(下采样首选,上采样退化为最近邻)。 每格把源图对应矩形内的像素求平均后写一个输出像素——不建中间缓冲。 失败条件:输入/输出尺寸非正、数据长度与 width*height*channels 不符。

    resize_to_contain

    fn resize_to_contain(img :
    core
    /types.Image, target_w : Int, target_h : Int, fill_color : Array[Byte]) ->
    core
    /types.Image raise
    core
    /types.LoadError

    Resize 到目标尺寸内(contain 模式),保持宽高比,不足部分用 fill_color 填充。

    resize_to_cover

    fn resize_to_cover(img :
    core
    /types.Image, target_w : Int, target_h : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    Resize 并裁剪到精确尺寸(cover 模式)。 先按宽高比缩放使图像"覆盖"目标尺寸,然后居中裁剪多余部分。

    rotate

    fn rotate(img :
    core
    /types.Image, angle_degrees : Float) ->
    core
    /types.Image

    任意角度旋转(绕中心,保留原尺寸,角落填充黑色)。 angle 单位为度,正值逆时针旋转。使用双线性插值。

    rotate_180

    fn rotate_180(img :
    core
    /types.Image) ->
    core
    /types.Image

    旋转 180 度

    rotate_180_16

    fn rotate_180_16(img :
    core
    /types.Image16) ->
    core
    /types.Image16

    @see rotate_180 8-bit 版本,本函数为 Image16 变体

    rotate_180_f

    fn rotate_180_f(img :
    core
    /types.ImageF) ->
    core
    /types.ImageF

    @see rotate_180 8-bit 版本,本函数为 ImageF 变体

    rotate_270

    fn rotate_270(img :
    core
    /types.Image) ->
    core
    /types.Image

    顺时针旋转 270 度(逆时针 90 度)

    rotate_270_16

    fn rotate_270_16(img :
    core
    /types.Image16) ->
    core
    /types.Image16

    @see rotate_270 8-bit 版本,本函数为 Image16 变体

    rotate_270_f

    fn rotate_270_f(img :
    core
    /types.ImageF) ->
    core
    /types.ImageF

    @see rotate_270 8-bit 版本,本函数为 ImageF 变体

    rotate_90

    fn rotate_90(img :
    core
    /types.Image) ->
    core
    /types.Image

    顺时针旋转 90 度

    rotate_90_16

    fn rotate_90_16(img :
    core
    /types.Image16) ->
    core
    /types.Image16

    @see rotate_90 8-bit 版本,本函数为 Image16 变体

    rotate_90_f

    fn rotate_90_f(img :
    core
    /types.ImageF) ->
    core
    /types.ImageF

    @see rotate_90 8-bit 版本,本函数为 ImageF 变体

    seam_carve_resize

    fn seam_carve_resize(img :
    core
    /types.Image, new_w : Int, new_h : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    内容感知缩放(Seam Carving) 支持缩小和放大,放大上限为原尺寸 2 倍

    seam_carve_resize_16

    fn seam_carve_resize_16(img :
    core
    /types.Image16, new_w : Int, new_h : Int) ->
    core
    /types.Image16 raise
    core
    /types.LoadError

    内容感知缩放 16-bit 版本 @see seam_carve_resize 8-bit 版本,本函数为 Image16 变体

    seam_carve_resize_f

    fn seam_carve_resize_f(img :
    core
    /types.ImageF, new_w : Int, new_h : Int) ->
    core
    /types.ImageF raise
    core
    /types.LoadError

    内容感知缩放 float 版本 @see seam_carve_resize 8-bit 版本,本函数为 ImageF 变体

    thumbnail

    fn thumbnail(img :
    core
    /types.Image, max_side : Int) ->
    core
    /types.Image raise
    core
    /types.LoadError

    等比缩略图:长边压到 max_side,短边按比例(四舍五入,至少 1 像素)。 原图两边都不超过 max_side 时原样返回(零分配)。

    thumbnail_budgeted

    fn thumbnail_budgeted(img :
    core
    /types.Image, max_side : Int, budget :
    core
    /types.AllocBudget) ->
    core
    /types.Image raise
    core
    /types.ImageError

    带分配预算的缩略图:先按尺寸算输出字节,超出 budget 直接拒(不分配)。 这是"大图出小图"的推荐入口:预算按输出计,底图内存由解码期 DecodeLimits 把关。

    thumbnail_dims

    fn thumbnail_dims(width : Int, height : Int, max_side : Int) -> (Int, Int)

    等比缩略图的输出尺寸(不分配内存,供预算检查先算)。

    transpose_16

    fn transpose_16(img :
    core
    /types.Image16) ->
    core
    /types.Image16

    16-bit 转置。交换宽高,(x,y) -> (y,x)。 @see transpose 8-bit 版本,本函数为 Image16 变体

    transpose_f

    fn transpose_f(img :
    core
    /types.ImageF) ->
    core
    /types.ImageF

    float 转置。交换宽高,(x,y) -> (y,x)。 @see transpose 8-bit 版本,本函数为 ImageF 变体

    warp_affine

    fn warp_affine(img :
    core
    /types.Image, matrix : (Float, Float, Float, Float, Float, Float), new_w : Int, new_h : Int) ->
    core
    /types.Image

    仿射变换。matrix = (a, b, c, d, e, f) 映射 dst→src: 仿射逆映射 src_x = a * dst_x + b * dst_y + c 仿射逆映射 src_y = d * dst_x + e * dst_y + f 使用双线性插值,超出边界的像素 clamp 到边缘。 输出尺寸为 new_w × new_h,通道数与输入相同。

    warp_affine_16

    fn warp_affine_16(img :
    core
    /types.Image16, matrix : (Float, Float, Float, Float, Float, Float), new_w : Int, new_h : Int) ->
    core
    /types.Image16

    16-bit 仿射变换。 @see warp_affine 8-bit 版本,本函数为 Image16 变体

    warp_affine_f

    fn warp_affine_f(img :
    core
    /types.ImageF, matrix : (Float, Float, Float, Float, Float, Float), new_w : Int, new_h : Int) ->
    core
    /types.ImageF

    float 仿射变换。 @see warp_affine 8-bit 版本,本函数为 ImageF 变体

    warp_perspective

    fn warp_perspective(img :
    core
    /types.Image, matrix : PerspectiveMatrix, new_w : Int, new_h : Int) ->
    core
    /types.Image

    透视变换。使用 3×3 矩阵将图像变换到 new_w × new_h。 采用 dst→src 映射 + 双线性插值。

    warp_perspective_16

    fn warp_perspective_16(img :
    core
    /types.Image16, matrix : PerspectiveMatrix, new_w : Int, new_h : Int) ->
    core
    /types.Image16

    16-bit 透视变换。 @see warp_perspective 8-bit 版本,本函数为 Image16 变体

    warp_perspective_f

    fn warp_perspective_f(img :
    core
    /types.ImageF, matrix : PerspectiveMatrix, new_w : Int, new_h : Int) ->
    core
    /types.ImageF

    float 透视变换。 @see warp_perspective 8-bit 版本,本函数为 ImageF 变体