package bimage

  1. Overview
  2. Docs

The Image module defines a simple interface for manipulating image data

type layout =
  1. | Planar
  2. | Interleaved
    (*

    Image pixel layout. Planar is RRRGGGBBB and Interleaved is RGBRGBRGB

    *)
type ('a, 'b, 'c) t = {
  1. width : int;
  2. height : int;
  3. color : 'c Color.t;
  4. layout : layout;
  5. data : ('a, 'b) Data.t;
}

Image type

val create : ?layout:layout -> ('a, 'b) kind -> 'c Color.t -> int -> int -> ('a, 'b, 'c) t

create kind color width height makes a new image with the given kind, color and dimensions

val compare : ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> int
val equal : ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> bool
val data : ('a, 'b, 'c) t -> ('a, 'b) Data.t
val of_data : 'c Color.t -> int -> int -> layout -> ('a, 'b) Data.t -> ('a, 'b, 'c) t

of_data color width height layout data makes a new image from existing image data with the given kind, color, layout, and dimensions

val like : ('a, 'b, 'c) t -> ('a, 'b, 'c) t

like img creates a new image with the same dimensions, color and kind as img

val like_with_color : 'd Color.t -> ('a, 'b, 'c) t -> ('a, 'b, 'd) t
val like_with_kind : ('d, 'e) kind -> ('a, 'b, 'c) t -> ('d, 'e, 'c) t
val like_with_layout : layout -> ('a, 'b, 'c) t -> ('a, 'b, 'c) t
val copy : ('a, 'b, 'c) t -> ('a, 'b, 'c) t

Makes a copy of an image and underlying image data

val copy_to : dest:('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit

Copy pixels from one image to another

val channels : ('a, 'b, 'c) t -> int

Returns the number of channels in an image

val layout : ('a, 'b, 'c) t -> layout

Returns the image layout type

val length : ('a, 'b, 'c) t -> int

Returns the number of values contained in an image

val kind : ('a, 'b, 'c) t -> ('a, 'b) kind

Returns the image kind

val color : ('a, 'b, 'c) t -> 'c Color.t

Returns the image color type

val shape : ('a, 'b, 'c) t -> int * int * int

Returns the width, height and channels

val convert_to : dest:('d, 'e, 'c) t -> ('a, 'b, 'c) t -> unit

Convert an image to an existing image of another kind

val convert : ('d, 'e) kind -> ('a, 'b, 'c) t -> ('d, 'e, 'c) t

Convert an image to a new image of another kind

val of_any_color : ('a, 'b, any) t -> 'c Color.t -> (('a, 'b, 'c) t, Error.t) result

Convert from any color to the given color

val get : ('a, 'b, 'c) t -> int -> int -> int -> 'a

get image x y c returns a the value at (x, y, c)

val set : ('a, 'b, 'c) t -> int -> int -> int -> 'a -> unit

Set a single channel of the given image at (x, y)

val get_f : ('a, 'b, 'c) t -> int -> int -> int -> float

get_f image x y c returns the float value at (x, y, c)

val set_f : ('a, 'b, 'c) t -> int -> int -> int -> float -> unit

Set a single channel of the given image at (x, y) using a float value

val get_n : ('a, 'b, 'c) t -> int -> int -> int -> float

get_f image x y c returns the normalized float value at (x, y, c)

val set_n : ('a, 'b, 'c) t -> int -> int -> int -> float -> unit

Set a single channel of the given image at (x, y) using a normalized float value

val get_pixel : ('a, 'b, 'c) t -> ?dest:Pixel.t -> int -> int -> Pixel.t

get_pixel image x y returns a pixel representation of image data at (x, y)

val set_pixel : ('a, 'b, 'c) t -> int -> int -> Pixel.t -> unit

set_pixel image x y px sets the value of image at (x, y) to px

val get_data : ('a, 'b, 'c) t -> ?dest:('a, 'b) Data.t -> int -> int -> ('a, 'b) Data.t

get_data image x y returns image data at (x, y)

val set_data : ('a, 'b, 'c) t -> int -> int -> ('a, 'b) Data.t -> unit

set_data image x y px sets the value of image at (x, y) to px

val for_each : (int -> int -> ('a, 'b) Data.t -> unit) -> ?x:int -> ?y:int -> ?width:int -> ?height:int -> ('a, 'b, 'c) t -> unit

Iterate over each pixel in an image, or a rectangle segment of an image specified by x, y, width, and height. The data segment used in the callback is mutable and will write directly to the underlying image data.

val for_each_pixel : (int -> int -> Pixel.t -> unit) -> ?x:int -> ?y:int -> ?width:int -> ?height:int -> ('a, 'b, 'c) t -> unit
val kernel : Kernel.t -> ?output:('a, 'b, 'c) t -> ('a, 'b, 'c) t -> ('a, 'b, 'c) t

Apply a kernel directly to the provided image. Note that this implementation is much slower than `Op.kernel`, it is mostly provided for convenience

val avg : ?x:int -> ?y:int -> ?width:int -> ?height:int -> ('a, 'b, 'c) t -> (float, f32) Data.t

Get the average pixel of an image or region of an image

val convert_layout : layout -> ('a, 'b, 'c) t -> ('a, 'b, 'c) t

Convert an image to the given layout

val crop : ('a, 'b, 'c) t -> x:int -> y:int -> width:int -> height:int -> ('a, 'b, 'c) t

Extract the sub-image specified by the given dimensions

val rotate_90 : ('a, 'b, 'c) t -> ('a, 'b, 'c) t

Rotate an image 90 degrees

val rotate_180 : ('a, 'b, 'c) t -> ('a, 'b, 'c) t

Rotate an image 180 degrees

val rotate_270 : ('a, 'b, 'c) t -> ('a, 'b, 'c) t

Rotate an image 270 degrees

val resize : int -> int -> ('a, 'b, 'c) t -> ('a, 'b, 'c) t

Scale an image to the given size

val mean_std : ?channel:int -> ('a, 'b, 'c) t -> float * float

Calculate the mean and standard deviation of an image

val fold : ('a -> 'd -> 'd) -> ('a, 'b, 'c) t -> 'd -> 'd
val fold2 : ('a -> 'e -> 'd -> 'd) -> ('a, 'b, 'c) t -> ('e, 'f, 'c) t -> 'd -> 'd
val fold_data : (int -> int -> ('a, 'b) Data.t -> 'd -> 'd) -> ('a, 'b, 'c) t -> 'd -> 'd
val fold_data2 : (int -> int -> ('a, 'b) Data.t -> ('e, 'f) Data.t -> 'd -> 'd) -> ('a, 'b, 'c) t -> ('e, 'f, 'c) t -> 'd -> 'd
val map_inplace : ('a -> 'a) -> ('a, 'b, 'c) t -> unit
val map : ('a -> 'a) -> ('a, 'b, 'c) t -> ('a, 'b, 'c) t
val map2_inplace : ('a -> 'd -> 'a) -> ('a, 'b, 'c) t -> ('d, 'e, 'f) t -> unit
val map2 : ('a -> 'd -> 'a) -> ('a, 'b, 'c) t -> ('d, 'e, 'f) t -> ('a, 'b, 'c) t
module Diff : sig ... end
val diff : ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> Diff.diff
OCaml

Innovation. Community. Security.