Skip to content

dlib.image.image

Timur Gafarov edited this page Jan 16, 2014 · 18 revisions

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

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

class 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
  • PixelFormat pixelFormat - pixel format
  • 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)
  • float progress - a value ranging from 0 to 1 that represents processing persentage

Methods:

  • SuperImage dup() - create a copy of the image
  • SuperImage createSameFormat(uint w, uint h) - create an image of the same format and with specified width and height
  • void updateProgress() - make one processing step (increase progress)
  • void resetProgress() - reset progress to 0

Operators:

  • Color4f opIndex(int x, int y) - read a pixel with square bracket syntax (e.g. color = img[x, y])
  • Color4f opIndexAssign(Color4f c, int x, int y) - write a pixel with 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 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

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