Class Image

Constructors

  • Construct a new Image knowing its dimensions.

    Parameters

    • width: number

      Image width.

    • height: number

      Image height.

    • options: ImageOptions = {}

      Image options.

    Returns Image

Properties

alpha: boolean

Whether the image has an alpha channel or not.

bitDepth: BitDepth

The number of bits per value in each channel.

channels: number

The total number of channels in the image, including the alpha channel.

colorModel: ImageColorModel

The color model of the image.

components: number

The number of color channels in the image, excluding the alpha channel. A GREY image has 1 component. An RGB image has 3 components.

height: number

The number of rows of the image.

maxValue: number

The maximum value that a pixel channel can have.

origin: Point

Origin of the image relative to a the parent image.

size: number

The total number of pixels in the image (width × height).

width: number

The number of columns of the image.

Methods

  • Apply Canny edge detection to an image.

    Parameters

    Returns Mask

    The processed image.

  • Modify all the values of the image using the given callback.

    Parameters

    • cb: ((value) => number)

      Callback that modifies a given value.

        • (value): number
        • Parameters

          • value: number

          Returns number

    Returns void

  • Correct the colors in an image using the reference colors.

    Parameters

    • measuredColors: RgbColor[]

      Colors from the image, which will be compared to the reference.

    • referenceColors: RgbColor[]

      Reference colors.

    Returns Image

    Image with the colors corrected.

  • Crop the input image to a desired size.

    Parameters

    Returns Image

    The new cropped image.

  • Crops the image based on the alpha channel This removes lines and columns where the alpha channel is lower than a threshold value.

    Parameters

    Returns Image

    The cropped image.

  • Crop an oriented rectangle from the image. If the rectangle's length or width are not an integers, its dimension is expanded in both directions such as the length and width are integers.

    Parameters

    Returns Image

    The cropped image. The orientation of the image is the one closest to the rectangle passed as input.

  • Draw a circle defined by center and radius onto an image.

    Parameters

    Returns Image

    The image with the circle drawing.

  • Draw a line defined by two points onto an image.

    Parameters

    Returns Image

    The mask with the line drawing.

  • Draw a marker on the image.

    Parameters

    Returns Image

    The image with the marker drawing.

  • Draw markers on the image.

    Parameters

    Returns Image

    The image with the markers drawing.

  • Draw a polygon defined by an array of points onto an image.

    Parameters

    Returns Image

    The image with the polygon drawing.

  • Draw a polyline defined by an array of points on an image.

    Parameters

    Returns Image

    The image with the polyline drawing.

  • Draw a rectangle defined by position of the top-left corner, width and height.

    Parameters

    Returns Image

    The image with the rectangle drawing.

  • Extract the pixels of an image, as specified in a mask.

    Parameters

    • mask: Mask

      The mask defining which pixels to keep.

    • Optional options: ExtractOptions

      Extract options.

    Returns Image

    The extracted image.

  • Fill the image with a value or a color.

    Parameters

    • value: number | number[]

      Value or color.

    Returns Image

    The image instance.

  • Fill the alpha channel with the specified value.

    Parameters

    • value: number

      New channel value.

    Returns Image

    The image instance.

  • Fill one channel with a value.

    Parameters

    • channel: number

      The channel to fill.

    • value: number

      The new value.

    Returns Image

    The image instance.

  • Get one channel of the image as an array.

    Parameters

    • channel: number

      The channel to fill.

    Returns number[]

    Array with the channel values.

  • Parameters

    • column: number

    Returns number[][]

  • Get the coordinates of a point in the image. The reference is the top-left corner.

    Parameters

    • coordinates: ImageCoordinates

      The point for which you want the coordinates.

    • round: boolean = false

      Whether the coordinates should be rounded. This is useful when you want the center of the image.

    Returns Point

    Coordinates of the point in the format [column, row].

  • Get all the channels of a pixel.

    Parameters

    • column: number

      Column index.

    • row: number

      Row index.

    Returns number[]

    Channels of the pixel.

  • Get all the channels of a pixel using its index.

    Parameters

    • index: number

      Index of the pixel.

    Returns number[]

    Channels of the pixel.

  • Return the raw image data.

    Returns {
        bitDepth: BitDepth;
        channels: number;
        data: ImageDataArray;
        height: number;
        width: number;
    }

    The raw data.

  • Parameters

    • row: number

    Returns number[][]

  • Get the value of a specific pixel channel. Select pixel using coordinates.

    Parameters

    • column: number

      Column index.

    • row: number

      Row index.

    • channel: number

      Channel index.

    Returns number

    Value of the specified channel of one pixel.

  • Get the value of a specific pixel channel. Select pixel using index.

    Parameters

    • index: number

      Index of the pixel.

    • channel: number

      Channel index.

    Returns number

    Value of the channel of the pixel.

  • Get the value of a specific pixel channel. Select pixel using a point.

    Parameters

    • point: Point

      Coordinates of the desired pixel.

    • channel: number

      Channel index.

    Returns number

    Value of the channel of the pixel.

  • Calculate a new image that is the hypotenuse between the current image and the other.

    Parameters

    Returns Image

    Hypotenuse of the two images.

  • Increase the contrast of an image by spanning each channel on the range [0, image.maxValue].

    Parameters

    Returns Image

    The enhanced image.

  • Level the image using the optional input and output value. This function allows you to enhance the image's contrast.

    Parameters

    Returns Image

    The levelled image.

  • Compute the mean pixel of an image.

    Returns number[]

    The mean pixel.

  • Compute the median pixel of an image.

    Returns number[]

    The median pixel.

  • Find the min and max values of each channel of the image.

    Returns {
        max: number[];
        min: number[];
    }

    An object with arrays of the min and max values.

    • max: number[]
    • min: number[]
  • Paint a mask onto an image and the given position and with the given color.

    Parameters

    Returns Image

    The painted image.

  • Compute direct convolution of an image and return an array with the raw values.

    Parameters

    • kernel: number[][]

      Kernel used for the convolution.

    • Optional options: ConvolutionOptions

      Convolution options.

    Returns Float64Array

    Array with the raw convoluted values.

  • Set the value of a specific pixel channel. Select pixel using coordinates. If the value is out of range it is set to the closest extremety.

    Parameters

    • column: number

      Column index.

    • row: number

      Row index.

    • channel: number

      Channel index.

    • value: number

      Value to set.

    Returns void

  • Set the value of a specific pixel channel. Select pixel using index. If the value is out of range it is set to the closest extremety.

    Parameters

    • index: number

      Index of the pixel.

    • channel: number

      Channel index.

    • value: number

      Value to set.

    Returns void

  • Set all the channels of a pixel.

    Parameters

    • column: number

      Column index.

    • row: number

      Row index.

    • value: number[]

      New color of the pixel to set.

    Returns void

  • Set all the channels of a pixel using its index.

    Parameters

    • index: number

      Index of the pixel.

    • value: number[]

      New channel values of the pixel to set.

    Returns void

  • Set the value of a specific pixel channel. Select pixel using coordinates.

    Parameters

    • column: number

      Column index.

    • row: number

      Row index.

    • channel: number

      Channel index.

    • value: number

      Value to set.

    Returns void

  • Set the value of a specific pixel channel. Select pixel using index.

    Parameters

    • index: number

      Index of the pixel.

    • channel: number

      Channel index.

    • value: number

      Value to set.

    Returns void

  • Set the value of a specific pixel channel. Select pixel using a point.

    Parameters

    • point: Point

      Coordinates of the pixel.

    • channel: number

      Channel index.

    • value: number

      Value to set.

    Returns void

  • Set all the channels of a pixel if the coordinates are inside the image.

    Parameters

    • column: number

      Column index.

    • row: number

      Row index.

    • value: number[]

      New color of the pixel to set.

    Returns void

  • Compute the variance of each channel of an image.

    Returns number[]

    The variance of the channels of the image.