The Library

- Algorithms
- API Wrappers
- Bayesian Nets
- Compression
- Containers
- Graph Tools
- Image Processing
- Linear Algebra
- Machine Learning
- Metaprogramming
- Miscellaneous
- Networking
- Optimization
- Parsing

Help/Info

- Examples: C++
  - Assignment_Learning
  - Base64_Encoder
  - Bayesian_Network
  - Bayesian_Network_From_Disk
  - Bayesian_Network_GUI
  - Bridge
  - BSP
  - Cmd_Line_Parser
  - Compress_Stream
  - Config_File_Reader
  - Custom_Trainers
  - Directory_Navigation
  - Empirical_Kernel_Map
  - Graph_Labeling
  - GUI
  - HTTP_Server
  - Image
  - IO Socket Streams
  - IO Streams Server
  - Kernel_Centroid
  - Kernel_K-Means_Clustering
  - Kernel_Ridge_Regression
  - Kernel_RLS_Filtering
  - Kernel_RLS_Regression
  - KRR_Classification
  - Linear_Manifold_Regularizer
  - Logger
  - Logger_Advanced
  - Matrix
  - Matrix_Expressions
  - Member_Function_Pointer
  - Model_Selection
  - Multiclass_Classification
  - Multithreaded_Object
  - Neural_Network
  - Non-Linear Least Squares
  - Numerical_Integration
  - Object_Detector
  - Object_Detector_Advanced
  - One_Class_Classifiers
  - Online_SVM
  - Optimization
  - Parallel_For_Loops
  - Pipe
  - Pipe_2
  - Quantum_Computing
  - Queue
  - Rank_Features
  - Relevance_Vector_Classification
  - Relevance_Vector_Regression
  - Running_Stats
  - Sequence_Labeling
  - Sequence_Segmentation
  - Sockets
  - Sockstreambuf
  - Sparse_Vectors
  - Std_C++_Allocator
  - Structural_Support_Vector_Machines
  - Support_Vector_Machine
  - Support_Vector_Regression
  - SURF
  - SVM-Rank
  - Threaded_Object
  - Threads
  - Thread_Function
  - Thread_Pool
  - Timer
  - Train_Object_Detector
  - Using_Custom_Kernels
  - XML_Parser
- Examples: Python
  - Linear_Assignment_Problems
  - Sequence_Segmenter
  - Structural_Support_Vector_Machines
  - SVM-Rank
- FAQ
- Home
- How to compile
- How to contribute
- Index
- Introduction
- License
- Python API
- Suggested Books

Current Release

- Change Log
- Release Notes
- Version: 18.4

Last Modified: Apr 23, 2013

# Image Processing

This page documents the functionality present in this library that deals with the management and manipulation of images. One thing to note is that there is no explicit image object. Instead, everything deals with array2d objects that contain various kinds of pixels.

## Pixel Types

Most image handling routines in dlib will accept images containing any pixel type. This is made possible by defining a traits class, pixel_traits, for each possible pixel type. This traits class enables image processing routines to determine how to handle each kind of pixel and therefore only pixels which have a pixel_traits definition may be used. The following list defines all the pixel types which come with pixel_traits definitions.

- RGB
  There are two RGB pixel types in dlib, rgb_pixel and bgr_pixel. Each defines a 24bit RGB pixel type. The bgr_pixel is identical to rgb_pixel except that it lays the color channels down in memory in BGR order rather than RGB order and is therefore useful for interfacing with other image processing tools which expect this format (e.g. OpenCV).
- RGB Alpha
  The rgb_alpha_pixel is an 8bit per channel RGB pixel with an 8bit alpha channel.
- HSI
  The hsi_pixel is a 24bit pixel which represents a point in the Hue Saturation Intensity (HSI) color space.
- Grayscale
  Any built in scalar type may be used as a grayscale pixel type. For example, unsigned char, int, double, etc.

Pixels

- assign_pixel
- assign_pixel_intensity
- bgr_pixel
- get_pixel_intensity
- hsi_pixel
- pixel_traits
- rgb_alpha_pixel
- rgb_pixel

Image I/O

- jpeg_loader
- load_bmp
- load_dng
- load_image
- load_jpeg
- load_png
- png_loader
- save_bmp
- save_dng
- save_png

Object Detection

- find_candidate_object_locations
- find_points_above_thresh
- full_object_detection
- object_detector
- remove_unobtainable_rectangles
- Scan Image Pyramid Tools
  - compute_box_dimensions
  - create_grid_detection_template
  - create_overlapped_2x2_detection_template
  - create_single_box_detection_template
  - determine_object_boxes
  - setup_grid_detection_templates
  - setup_grid_detection_templates_verbose
- scan_image
- scan_image_boxes
- scan_image_movable_parts
- scan_image_pyramid
- setup_hashed_features
- test_box_overlap

Feature Extraction

- binned_vector_feature_image
- fine_hog_image
- get_surf_points
- hashed_feature_image
- hog_image
- nearest_neighbor_feature_image
- poly_image
- randomly_sample_image_features
- SURF Tools
  - compute_dominant_angle
  - compute_surf_descriptor
  - draw_surf_points
  - get_interest_points
  - haar_x
  - haar_y
  - hessian_pyramid
  - interest_point
  - surf_point

Edges and Thresholds

- auto_threshold_image
- edge_orientation
- hysteresis_threshold
- sobel_edge_detector
- suppress_non_maximum_edges
- threshold_image

Morphology

- binary_close
- binary_complement
- binary_difference
- binary_dilation
- binary_erosion
- binary_intersection
- binary_open
- binary_union
- label_connected_blobs
- segment_image

Filtering

- gaussian_blur
- max_filter
- separable_3x3_filter_block_grayscale
- separable_3x3_filter_block_rgb
- spatially_filter_image
- spatially_filter_image_separable
- spatially_filter_image_separable_down
- sum_filter
- sum_filter_assign

Scaling and Rotating

- flip_image_left_right
- flip_image_up_down
- interpolate_bilinear
- interpolate_nearest_neighbor
- interpolate_quadratic
- pyramid_disable
- pyramid_down
- pyramid_down_3_2
- pyramid_down_4_3
- pyramid_down_5_4
- pyramid_up
- resize_image
- rotate_image
- transform_image

Colormaps

- heatmap
- jet
- randomly_color_image

Miscellaneous

- assign_all_pixels
- assign_border_pixels
- assign_image
- assign_image_scaled
- cv_image
- draw_line
- equalize_histogram
- fill_rect
- get_histogram
- integral_image
- integral_image_generic
- toMat
- zero_border_pixels

[top]

# assign_all_pixels

This global function assigns all the pixels in an image a specific value.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# assign_border_pixels

This global function assigns all the pixels in the border of an image to a specific value.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# assign_image

This global function copies one image into another and performs any necessary color space conversions to make it work right.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# assign_image_scaled

This global function copies one image into another and performs any necessary color space conversions to make it work right. Additionally, if the dynamic range of the source image is too big to fit into the destination image then it will attempt to perform the appropriate scaling.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# assign_pixel

assign_pixel() is a templated function that can assign any pixel type to another pixel type. It will perform whatever conversion is necessary to make the assignment work. (E.g. color to grayscale conversion)
`#include <dlib/pixel.h>`
Detailed Documentation
[top]

# assign_pixel_intensity

assign_pixel_intensity() is a templated function that can change the intensity of a pixel. So if the pixel in question is a grayscale pixel then it simply assigns that pixel the given value. However, if the pixel is not a grayscale pixel then it converts the pixel to the HSI color space and sets the I channel to the given intensity and then converts this HSI value back to the original pixel's color space.
`#include <dlib/pixel.h>`
Detailed Documentation
[top]

# auto_threshold_image

This global function performs a simple binary thresholding on an image. Instead of taking a user supplied threshold it computes one from the image using k-means clustering.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# bgr_pixel

This is a simple struct that represents a BGR colored graphical pixel.

The difference between this object and the rgb_pixel is just that this struct lays its pixels down in memory in BGR order rather than RGB order. You only care about this if you are doing something like using the cv_image object to map an OpenCV image into a more object oriented form.

`#include <dlib/pixel.h>`
Detailed Documentation
[top]

# binary_close

This global function performs a morphological closing on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# binary_complement

This global function computes the complement of a binary image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# binary_difference

This global function computes the difference of two binary images.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# binary_dilation

This global function performs the morphological operation of dilation on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# binary_erosion

This global function performs the morphological operation of erosion on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# binary_intersection

This global function computes the intersection of two binary images.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# binary_open

This global function performs a morphological opening on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# binary_union

This global function computes the union of two binary images.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# binned_vector_feature_image

This object is a tool for performing image feature extraction. In particular, it wraps another image feature extractor and converts the wrapped image feature vectors into a high dimensional sparse vector. For example, if the lower level feature extractor outputs the vector [3,4,5] and this vector is hashed into the second bin of four bins then the output sparse vector is:

> [0,0,0,0, 3,4,5,1, 0,0,0,0, 0,0,0,0].

That is, the output vector has a dimensionality that is equal to the number of hash bins times the dimensionality of the lower level vector plus one. The value in the extra dimension concatenated onto the end of the vector is always a constant value of of 1 and serves as a bias value. This means that, if there are N hash bins, these vectors are capable of representing N different linear functions, each operating on the vectors that fall into their corresponding hash bin.
The following feature extractors can be wrapped by the binned_vector_feature_image:

- hog_image
- fine_hog_image
- poly_image

`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# compute_box_dimensions

This function is a tool for computing a rectangle with a particular width/height ratio and area.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# compute_dominant_angle

Computes and returns the dominant angle (i.e. the angle of the dominant gradient) at a given point and scale in an image. This function is part of the main processing of the SURF algorithm.
`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# compute_surf_descriptor

Computes the 64 dimensional SURF descriptor vector of a box centered at a given center point, tilted at a given angle, and sized according to a given scale.
`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# create_grid_detection_template

This function is a tool for creating a detection template usable by the scan_image_pyramid object. This particular function creates a detection template with a grid of feature extraction regions.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# create_overlapped_2x2_detection_template

This function is a tool for creating a detection template usable by the scan_image_pyramid object. This particular function creates a detection template with four overlapping feature extraction regions.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# create_single_box_detection_template

This function is a tool for creating a detection template usable by the scan_image_pyramid object. This particular function creates a detection template with exactly one feature extraction region.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# cv_image

This object is meant to be used as a simple wrapper around the OpenCV IplImage struct or Mat object. Using this class template you can turn an OpenCV image into something that looks like a normal dlib style image object.

So you should be able to use cv_image objects with many of the image processing functions in dlib as well as the GUI tools for displaying images on the screen.

Note that you can do the reverse conversion, from dlib to OpenCV, using the toMat routine. Also note that you have to #include OpenCV's header before you #include dlib/opencv.h.

`#include <dlib/opencv.h>`
Detailed Documentation
[top]

# determine_object_boxes

The scan_image_pyramid object represents a sliding window classifier system. For it to work correctly it needs to be given a set of object boxes which define the size and shape of each sliding window and these windows need to be able to match the sizes and shapes of targets the user wishes to detect. Therefore, the determine_object_boxes() routine is a tool for computing a set of object boxes which can meet this requirement.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# draw_line

This global function draws a line on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# draw_surf_points

This routine adds a bunch of surf_point objects onto an image_window object so they can be visualized.
`#include <dlib/image_keypoint/draw_surf_points.h>`
Detailed Documentation
C++ Example Programs: surf_ex.cpp
[top]

# edge_orientation

This global function takes horizontal and vertical gradient magnitude values and returns the orientation of the gradient.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# equalize_histogram

This global function performs histogram equalization on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# fill_rect

This global function draws a solid rectangle on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# find_candidate_object_locations

This function takes an input image and generates a set of candidate rectangles which are expected to bound any objects in the image. It does this by running a version of the segment_image routine on the image and then reports rectangles containing each of the segments as well as rectangles containing unions of adjacent segments. The basic idea is described in the paper:

> Segmentation as Selective Search for Object Recognition by Koen E. A. van de Sande, et al.

Note that this function deviates from what is described in the paper slightly. See the code for details.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# find_points_above_thresh

This routine finds all points in an image with a pixel value above a threshold. It also has the ability to produce an efficient random subsample of such points if the number of them is very large.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# fine_hog_image

This object is a version of the hog_image that allows you to extract HOG features at a finer resolution.
`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# flip_image_left_right

This is a routine which can flip an image from left to right. (e.g. as if viewed through a mirror).
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# flip_image_up_down

This routine flips an image upside down.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# full_object_detection

This object represents the location of an object in an image along with the positions of each of its constituent parts.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# gaussian_blur

This global function blurs an image by convolving it with a Gaussian filter.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# get_histogram

This global function computes an image's histogram and returns it in the form of a column or row matrix object.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# get_interest_points

This function extracts interest points from a hessian_pyramid.
`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# get_pixel_intensity

get_pixel_intensity() is a templated function that returns the grayscale intensity of a pixel. If the pixel isn't a grayscale pixel then it converts the pixel to grayscale and returns that value.
`#include <dlib/pixel.h>`
Detailed Documentation
[top]

# get_surf_points

This function runs the complete SURF algorithm on an input image and returns the points it found. For a description of what exactly the SURF algorithm does you should read the following paper:

> SURF: Speeded Up Robust Features By Herbert Bay, Tinne Tuytelaars, and Luc Van Gool

Also note that there are numerous flavors of the SURF algorithm you can put together using the functions in dlib. The get_surf_points() function is just an example of one way you might do so.

`#include <dlib/image_keypoint.h>`
Detailed Documentation
C++ Example Programs: surf_ex.cpp
[top]

# haar_x

This is a function that operates on an integral_image and allows you to compute the response of a Haar wavelet oriented along the X axis.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# haar_y

This is a function that operates on an integral_image and allows you to compute the response of a Haar wavelet oriented along the Y axis.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# hashed_feature_image

This object is a tool for performing image feature extraction. In particular, it wraps another image feature extractor and converts the wrapped image feature vectors into sparse indicator vectors. It does this by hashing each feature vector and then returns a new vector which is zero everywhere except for the position determined by the hash.
The following feature extractors can be wrapped by the hashed_feature_image:

- hog_image
- fine_hog_image
- poly_image

`#include <dlib/image_keypoint.h>`
Detailed Documentation
C++ Example Programs: object_detector_ex.cpp, train_object_detector.cpp
[top]

# heatmap

Converts a grayscale image into a heatmap. This is useful if you want to display a grayscale image with more than 256 values. In particular, this function uses the following color mapping:
`#include <dlib/image_transforms.h>`
Detailed Documentation
C++ Example Programs: image_ex.cpp
[top]

# hessian_pyramid

This object represents an image pyramid where each level in the pyramid holds determinants of Hessian matrices for the original input image. This object can be used to find stable interest points in an image.
This object is an implementation of the fast Hessian pyramid as described in the paper:

> SURF: Speeded Up Robust Features By Herbert Bay, Tinne Tuytelaars, and Luc Van Gool

This implementation was also influenced by the very well documented OpenSURF library and its corresponding description of how the fast Hessian algorithm functions:

> Notes on the OpenSURF Library by Christopher Evans

`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# hog_image

This object is a tool for performing the image feature extraction algorithm described in the following paper:

> Histograms of Oriented Gradients for Human Detection by Navneet Dalal and Bill Triggs

`#include <dlib/image_keypoint.h>`
Detailed Documentation
C++ Example Programs: object_detector_ex.cpp, train_object_detector.cpp
[top]

# hsi_pixel

This is a simple struct that represents an HSI colored graphical pixel.
`#include <dlib/pixel.h>`
Detailed Documentation
[top]

# hysteresis_threshold

This global function performs hysteresis thresholding on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# integral_image

This is a specialization of the integral_image_generic template for the case where sums of pixel values should be represented with longs. E.g. if you use 8bit pixels in your original images then this is the appropriate kind of integral image to use with them.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# integral_image_generic

This object is an alternate way of representing image data that allows for very fast computations of sums of pixels in rectangular regions. To use this object you load it with a normal image and then you can use the get_sum_of_area() member function to compute sums of pixels in a given area in constant time.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# interest_point

This is a simple struct used to represent the interest points returned by the get_interest_points function.
`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# interpolate_bilinear

This object is a tool for performing bilinear interpolation on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# interpolate_nearest_neighbor

This object is a tool for performing nearest neighbor interpolation on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# interpolate_quadratic

This object is a tool for performing quadratic interpolation on an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# jet

Converts a grayscale image into an image using the jet color scheme. This is useful if you want to display a grayscale image with more than 256 values. In particular, this function uses the following color mapping:
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# jpeg_loader

This object loads a JPEG image file into an array2d of pixels.

Note that you must define DLIB_JPEG_SUPPORT if you want to use this object. You must also set your build environment to link to the libjpeg library. However, if you use CMake and dlib's default CMakeLists.txt file then it will get setup automatically (assuming libjpeg is properly installed in your system).

`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# label_connected_blobs

This function labels each of the connected blobs in an image with a unique integer label.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# load_bmp

This global function loads a MS Windows BMP file into an array2d of pixels.
`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# load_dng

This global function loads a dlib DNG file (a lossless compressed image format) into an array2d of pixels.
`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# load_image

This global function takes a file name, looks at its extension, and then loads it into an array2d of pixels using the appropriate image loading routine. The supported types are BMP, PNG, JPEG, and the dlib DNG file format.

Note that you can only load PNG and JPEG files if you link against libpng and libjpeg respectively.

`#include <dlib/image_io.h>`
Detailed Documentation
C++ Example Programs: image_ex.cpp
[top]

# load_jpeg

This function loads a JPEG image file into an array2d of pixels.

Note that you must define DLIB_JPEG_SUPPORT if you want to use this object. You must also set your build environment to link to the libjpeg library. However, if you use CMake and dlib's default CMakeLists.txt file then it will get setup automatically (assuming libjpeg is properly installed in your system).

`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# load_png

This function loads a Portable Network Graphics (PNG) image file into an array2d of pixels.

Note that you must define DLIB_PNG_SUPPORT if you want to use this object. You must also set your build environment to link to the libpng library. However, if you use CMake and dlib's default CMakeLists.txt file then it will get setup automatically (assuming libpng is properly installed on your system).

`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# max_filter

This function slides a rectangle over an input image and outputs a new image which contains the maximum valued pixel found inside the rectangle at each position in the input image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# nearest_neighbor_feature_image

This object is a tool for performing image feature extraction. In particular, it wraps another image feature extractor and converts the wrapped image feature vectors into sparse indicator vectors. It does this by finding the nearest neighbor for each feature vector and returning an indicator vector that is zero everywhere except for the position indicated by the nearest neighbor.
The following feature extractors can be wrapped by the nearest_neighbor_feature_image:

- hog_image
- fine_hog_image
- poly_image

`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# object_detector

This object is a tool for detecting the positions of objects in an image. In particular, it is a simple container to aggregate an instance of the scan_image_pyramid or scan_image_boxes classes, the weight vector needed by one of these image scanners, and finally an instance of test_box_overlap. The test_box_overlap object is used to perform non-max suppression on the output of the image scanner object.

Note that you can use the structural_object_detection_trainer to learn the parameters of an object_detector. See the example programs for an introduction.

`#include <dlib/image_processing.h>`
Detailed Documentation
C++ Example Programs: object_detector_ex.cpp, object_detector_advanced_ex.cpp, train_object_detector.cpp
[top]

# pixel_traits

As the name implies, this is a traits class for pixel types. It allows you to determine what sort of pixel type you are dealing with.
`#include <dlib/pixel.h>`
Detailed Documentation
[top]

# png_loader

This object loads a Portable Network Graphics (PNG) image file into an array2d of pixels.

Note that you must define DLIB_PNG_SUPPORT if you want to use this object. You must also set your build environment to link to the libpng library. However, if you use CMake and dlib's default CMakeLists.txt file then it will get setup automatically (assuming libpng is properly installed on your system).

`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# poly_image

This object is a tool for extracting local feature descriptors from an image. In particular, it fits polynomials to local pixel patches and allows you to query the coefficients of these polynomials.
`#include <dlib/image_keypoint.h>`
Detailed Documentation
[top]

# pyramid_disable

This object downsamples an image at a ratio of infinity to 1. That means it always outputs an image of size zero. This is useful because it can be supplied to routines which take a pyramid_down function object and it will essentially disable pyramid processing. This way, a pyramid oriented function can be turned into a regular routine which processes just the original undownsampled image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# pyramid_down

This is a simple function object to help create image pyramids. It downsamples an image by half.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# pyramid_down_3_2

This is a simple function object to help create image pyramids. It downsamples an image by a ratio of 3 to 2.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# pyramid_down_4_3

This is a simple function object to help create image pyramids. It downsamples an image by a ratio of 4 to 3.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# pyramid_down_5_4

This is a simple function object to help create image pyramids. It downsamples an image by a ratio of 5 to 4.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# pyramid_up

This routine upsamples an image. In particular, it takes one of the pyramid_down objects as an argument and performs an upsampling which is the inverse of the supplied pyramid_down object.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# randomly_color_image

Randomly generates a mapping from gray level pixel values to the RGB pixel space and then uses this mapping to create a colored version an image.

This function is useful for displaying the results of some image segmentation. For example, the output of label_connected_blobs or segment_image.

`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# randomly_sample_image_features

Given a feature extractor such as the hog_image, this routine selects a random subsample of local image feature vectors from a set of images.
`#include <dlib/statistics.h>`
Detailed Documentation
[top]

# remove_unobtainable_rectangles

Recall that the scan_image_pyramid and scan_image_boxes objects can't produce all possible rectangles as object detections since they only consider a limited subset of all possible object positions. Therefore, when training an object detector that uses these tools you must make sure the training data does not contain any object locations that are unobtainable by the image scanning model. The remove_unobtainable_rectangles() routine is a tool to filter out these unobtainable rectangles from the training.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# resize_image

This is a routine capable of resizing or stretching an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# rgb_alpha_pixel

This is a simple struct that represents an RGB colored graphical pixel with an alpha channel.
`#include <dlib/pixel.h>`
Detailed Documentation
[top]

# rgb_pixel

This is a simple struct that represents an RGB colored graphical pixel.
`#include <dlib/pixel.h>`
Detailed Documentation
[top]

# rotate_image

This is a routine for rotating an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# save_bmp

This global function saves an image as a MS Windows BMP file.

This routine can save images containing any type of pixel. However, it will convert all color pixels into rgb_pixel and grayscale pixels into uint8 type before saving to disk.

`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# save_dng

This global function saves an image as a dlib DNG file (a lossless compressed image format).

This routine can save images containing any type of pixel. However, the DNG format can natively store only the following pixel types: rgb_pixel, hsi_pixel, rgb_alpha_pixel, uint8, uint16, float, and double. All other pixel types will be converted into one of these types as appropriate before being saved to disk.

`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# save_png

This global function writes an image to disk as a PNG (Portable Network Graphics) file.

Note that you must define DLIB_PNG_SUPPORT if you want to use this function. You must also set your build environment to link to the libpng library. However, if you use CMake and dlib's default CMakeLists.txt file then it will get setup automatically (assuming libpng is properly installed in your system).

This routine can save images containing any type of pixel. However, save_png() can only natively store the following pixel types: rgb_pixel, rgb_alpha_pixel, uint8, and uint16. All other pixel types will be converted into one of these types as appropriate before being saved to disk.

`#include <dlib/image_io.h>`
Detailed Documentation
[top]

# scan_image

This global function is a tool for sliding a set of rectangles over an image space and finding the locations where the sum of pixels in the rectangles exceeds a threshold. It is useful for implementing certain kinds of sliding window classifiers.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# scan_image_boxes

This object is a tool for running a classifier over an image with the goal of localizing each object present. The localization is in the form of the bounding box around each object of interest.

Unlike the scan_image_pyramid object which scans a fixed sized window over an image pyramid, the scan_image_boxes tool allows you to define your own list of "candidate object locations" which should be evaluated. This is simply a list of rectangle objects which might contain objects of interest. The scan_image_boxes object will then evaluate the classifier at each of these locations and return the subset of rectangles which appear to have objects in them.

This object can also be understood as a general tool for implementing the spatial pyramid models described in the paper:

> Beyond Bags of Features: Spatial Pyramid Matching for Recognizing Natural Scene Categories by Svetlana Lazebnik, Cordelia Schmid, and Jean Ponce

The following feature extractors can be used with the scan_image_boxes object:

- hashed_feature_image
- binned_vector_feature_image
- nearest_neighbor_feature_image

`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# scan_image_movable_parts

This global function is a tool for sliding a set of rectangles over an image space and finding the locations where the sum of pixels in the rectangles exceeds a threshold. It is useful for implementing certain kinds of sliding window classifiers. The behavior of this routine is similar to scan_image except that it can also handle movable parts in addition to rigidly placed parts within the sliding window.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# scan_image_pyramid

This object is a tool for running a sliding window classifier over an image pyramid. This object can also be understood as a general tool for implementing the spatial pyramid models described in the paper:

> Beyond Bags of Features: Spatial Pyramid Matching for Recognizing Natural Scene Categories by Svetlana Lazebnik, Cordelia Schmid, and Jean Ponce

It also includes the ability to represent movable part models.
The following feature extractors can be used with the scan_image_pyramid object:

- hashed_feature_image
- binned_vector_feature_image
- nearest_neighbor_feature_image

`#include <dlib/image_processing.h>`
Detailed Documentation
C++ Example Programs: object_detector_ex.cpp, object_detector_advanced_ex.cpp
[top]

# segment_image

Attempts to segment an image into regions which have some visual consistency to them. In particular, this function implements the algorithm described in the paper:

> Efficient Graph-Based Image Segmentation by Felzenszwalb and Huttenlocher.

`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# separable_3x3_filter_block_grayscale

This routine filters part of an image with a user supplied 3x3 separable filter. The output is a grayscale sub-image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# separable_3x3_filter_block_rgb

This routine filters part of an image with a user supplied 3x3 separable filter. The output is a RGB sub-image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# setup_grid_detection_templates

This routine uses determine_object_boxes to obtain a set of object boxes and then adds them to a scan_image_pyramid object as detection templates. It also uses create_grid_detection_template to create each feature extraction region. Therefore, the detection templates will extract features from a regular grid inside each object box.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# setup_grid_detection_templates_verbose

This function is identical to setup_grid_detection_templates except that it also outputs information regarding the selected detection templates to standard out.
`#include <dlib/image_processing.h>`
Detailed Documentation
C++ Example Programs: object_detector_ex.cpp, train_object_detector.cpp
[top]

# setup_hashed_features

This is a tool for configuring the hashed_feature_image or binned_vector_feature_image object with a random projection hash.
`#include <dlib/image_processing.h>`
Detailed Documentation
C++ Example Programs: object_detector_ex.cpp, train_object_detector.cpp
[top]

# sobel_edge_detector

This global function performs spatial filtering on an image using the sobel edge detection filters.
`#include <dlib/image_transforms.h>`
Detailed Documentation
C++ Example Programs: image_ex.cpp
[top]

# spatially_filter_image

This global function performs spatial filtering on an image with a user supplied filter.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# spatially_filter_image_separable

This global function performs spatial filtering on an image with a user supplied separable filter.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# spatially_filter_image_separable_down

This global function performs spatial filtering on an image with a user supplied separable filter. Additionally, it produces a downsampled output.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# sum_filter

This function slides a rectangle over an input image and adds the sum of pixel values in each rectangle location to another image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# sum_filter_assign

This function slides a rectangle over an input image and outputs a new image which contains the sum of pixels inside the rectangle at each position in the input image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# suppress_non_maximum_edges

This global function performs non-maximum suppression on a gradient image.
`#include <dlib/image_transforms.h>`
Detailed Documentation
C++ Example Programs: image_ex.cpp
[top]

# surf_point

This is a simple struct used to represent the SURF points returned by the get_surf_points function.
`#include <dlib/image_keypoint.h>`
Detailed Documentation
C++ Example Programs: surf_ex.cpp
[top]

# test_box_overlap

This object is a simple function object for determining if two rectangles overlap.
`#include <dlib/image_processing.h>`
Detailed Documentation
[top]

# threshold_image

This global function performs a simple binary thresholding on an image with a user supplied threshold.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# toMat

This routine converts a dlib style image into an instance of OpenCV's cv::Mat object. This is done by setting up the Mat object to point to the same memory as the dlib image.

Note that you can do the reverse conversion, from OpenCV to dlib, using the cv_image object. Also note that you have to #include OpenCV's header before you #include dlib/opencv.h.

`#include <dlib/opencv.h>`
Detailed Documentation
[top]

# transform_image

This routine is a tool for transforming images using some kind of point mapping function (e.g. point_transform_affine) and pixel interpolation tool (e.g. interpolate_quadratic). An example application of this routine is for image rotation. Indeed, it is how rotate_image is implemented.
`#include <dlib/image_transforms.h>`
Detailed Documentation
[top]

# zero_border_pixels

This global function zeros the pixels on the border of an image.
`#include <dlib/image_transforms.h>`
Detailed Documentation