Skip to content

dlib.image.image

Timur Gafarov edited this page Jul 7, 2018 · 18 revisions

dlib.image.image

This module implements raster image classes. Note that floating point image class is defined in a separate module, dlib.image.hdri.

enum PixelFormat

An enum that holds supported pixel formats:

  • PixelFormat.L8 - 8-bit luminance
  • PixelFormat.LA8 - 8-bit luminance/alpha
  • PixelFormat.RGB8 - 8-bit RGB
  • PixelFormat.RGBA8 - 8-bit RGBA
  • PixelFormat.L16 - 16-bit luminance
  • PixelFormat.LA16 - 16-bit luminance/alpha
  • PixelFormat.RGB16 - 16-bit RGB
  • PixelFormat.RGBA16 - 16-bit RGBA
  • PixelFormat.RGBA_FLOAT - 32-bit floating point RGBA

interface SuperImage

Defines generalized interface of an image that abstracts from specific pixel format. It is recommended to use SuperImage when implementing new filters.

Properties:

  • uint width - width of an image in pixels
  • uint height - height of an image in pixels
  • uint channels - number of channels per pixel
  • uint bitDepth - bits per channel
  • uint pixelSize - size of a pixel in bytes
  • uint pixelFormat - pixel format. Values from 0 to 255 are reserved for dlib, values 256 and above are application-specific. Built-in images return a value of dlib.image.image.PixelFormat or dlib.image.hdri.FloatPixelFormat enum
  • ubyte[] data - raw pixel data
  • auto row - a range that represents 0..width (a row)
  • auto col - a range that represents 0..height (a column)

Methods:

  • SuperImage dup() - create a copy of the image
  • SuperImage createSameFormat(uint w, uint h) - create a blank image of the same format and with specified width and height

Operators:

  • Color4f opIndex(int x, int y) - read a pixel with subscript (square bracket) syntax (e.g. color = img[x, y])
  • Color4f opIndexAssign(Color4f c, int x, int y) - write a pixel with subscript (square bracket) syntax (e.g. img[x, y] = color)

Usage example:

/* 
 * Create an image using a factory
 * and draw a red pixel at position 100, 100
 */
SuperImage img = image(320, 240);
img[100, 100] = Color4f(1.0f, 0.0f, 0.0f);

class Image

A class template that derives from SuperImage and implements a corresponding image type for each supported integer pixel format:

  • Image!(PixelFormat.L8) - aliased as ImageL8
  • Image!(PixelFormat.LA8) - ImageLA8
  • Image!(PixelFormat.RGB8) - ImageRGB8
  • Image!(PixelFormat.RGBA8) - ImageRGBA8
  • Image!(PixelFormat.L16) - ImageL16
  • Image!(PixelFormat.LA16) - ImageLA16
  • Image!(PixelFormat.RGB16) - ImageRGB16
  • Image!(PixelFormat.RGBA16) - ImageRGBA16

Methods:

  • Color4 setPixel(Color4 col, int x, int y)
  • Color4 getPixel(int x, int y)

set and get a pixel using an integer color value. This methods are used internally by subscript operator after converting floating-point color to appropriate pixel format. They are made public for optimization reasons, but generally they are not preferred/idiomatic way of accessing image data - use subscript operator instead.

Free functions

  • SuperImage image(uint w, uint h, uint channels = 3, uint bitDepth = 8) - all-in-one image factory function
  • T convert(T)(SuperImage img) - Convert image to specified pixel format. T stands for image type (e.g. ImageRGB8, ImageRGBA16 etc.)
Clone this wiki locally