Applies an adaptive threshold to an array.
Parameters: 


The function transforms a grayscale image to a binary image according to the formulas:
THRESH_BINARY
THRESH_BINARY_INV
where is a threshold calculated individually for each pixel.
The function can process the image inplace.
See also: threshold() , blur() , GaussianBlur()
Converts image from one color space to another
Parameters: 


The function converts the input image from one color space to another. In the case of transformation tofrom RGB color space the ordering of the channels should be specified explicitly (RGB or BGR).
The conventional ranges for R, G and B channel values are:
Of course, in the case of linear transformations the range does not matter, but in the nonlinear cases the input RGB image should be normalized to the proper value range in order to get the correct results, e.g. for RGB L*u*v* transformation. For example, if you have a 32bit floatingpoint image directly converted from 8bit image without any scaling, then it will have 0..255 value range, instead of the assumed by the function 0..1. So, before calling cvtColor , you need first to scale the image down:
img *= 1./255;
cvtColor(img, img, CV_BGR2Luv);
The function can do the following transformations:
Transformations within RGB space like adding/removing the alpha channel, reversing the channel order, conversion to/from 16bit RGB color (R5:G6:B5 or R5:G5:B5), as well as conversion to/from grayscale using:
and
The conversion from a RGB image to gray is done with:
cvtColor(src, bwsrc, CV_RGB2GRAY);
Some more advanced channel reordering can also be done with mixChannels() .
RGB CIE XYZ.Rec 709 with D65 white point ( CV_BGR2XYZ, CV_RGB2XYZ, CV_XYZ2BGR, CV_XYZ2RGB ):
, and cover the whole value range (in the case of floatingpoint images may exceed 1).
RGB YCrCb JPEG (a.k.a. YCC) ( CV_BGR2YCrCb, CV_RGB2YCrCb, CV_YCrCb2BGR, CV_YCrCb2RGB )
where
Y, Cr and Cb cover the whole value range.
RGB HSV ( CV_BGR2HSV, CV_RGB2HSV, CV_HSV2BGR, CV_HSV2RGB )
in the case of 8bit and 16bit images R, G and B are converted to floatingpoint format and scaled to fit the 0 to 1 range
if then On output , , .
The values are then converted to the destination data type:
8bit images
16bit images (currently not supported)
H, S, V are left as is
RGB HLS ( CV_BGR2HLS, CV_RGB2HLS, CV_HLS2BGR, CV_HLS2RGB ).
in the case of 8bit and 16bit images R, G and B are converted to floatingpoint format and scaled to fit the 0 to 1 range.
if then On output , , .
The values are then converted to the destination data type:
8bit images
16bit images (currently not supported)
H, S, V are left as is
RGB CIE L*a*b* ( CV_BGR2Lab, CV_RGB2Lab, CV_Lab2BGR, CV_Lab2RGB )
in the case of 8bit and 16bit images R, G and B are converted to floatingpoint format and scaled to fit the 0 to 1 range
where
and
On output , , The values are then converted to the destination data type:
8bit images
currently not supported
L, a, b are left as is
RGB CIE L*u*v* ( CV_BGR2Luv, CV_RGB2Luv, CV_Luv2BGR, CV_Luv2RGB )
in the case of 8bit and 16bit images R, G and B are converted to floatingpoint format and scaled to fit 0 to 1 range
On output , , .
The values are then converted to the destination data type:
8bit images
currently not supported
L, u, v are left as is
The above formulas for converting RGB to/from various color spaces have been taken from multiple sources on Web, primarily from the Charles Poynton site http://www.poynton.com/ColorFAQ.html
Bayer RGB ( CV_BayerBG2BGR, CV_BayerGB2BGR, CV_BayerRG2BGR, CV_BayerGR2BGR, CV_BayerBG2RGB, CV_BayerGB2RGB, CV_BayerRG2RGB, CV_BayerGR2RGB ) The Bayer pattern is widely used in CCD and CMOS cameras. It allows one to get color pictures from a single plane where R,G and B pixels (sensors of a particular component) are interleaved like this:
The output RGB components of a pixel are interpolated from 1, 2 or 4 neighbors of the pixel having the same color. There are several modifications of the above pattern that can be achieved by shifting the pattern one pixel left and/or one pixel up. The two letters and in the conversion constants CV_Bayer 2BGR and CV_Bayer 2RGB indicate the particular pattern type  these are components from the second row, second and third columns, respectively. For example, the above pattern has very popular “BG” type.
Calculates the distance to the closest zero pixel for each pixel of the source image.
Parameters: 


The functions distanceTransform calculate the approximate or precise distance from every binary image pixel to the nearest zero pixel. (for zero image pixels the distance will obviously be zero).
When maskSize == CV_DIST_MASK_PRECISE and distanceType == CV_DIST_L2 , the function runs the algorithm described in [Felzenszwalb04] .
In other cases the algorithm [Borgefors86] is used, that is, for pixel the function finds the shortest path to the nearest zero pixel consisting of basic shifts: horizontal, vertical, diagonal or knight’s move (the latest is available for a mask). The overall distance is calculated as a sum of these basic distances. Because the distance function should be symmetric, all of the horizontal and vertical shifts must have the same cost (that is denoted as a ), all the diagonal shifts must have the same cost (denoted b ), and all knight’s moves must have the same cost (denoted c ). For CV_DIST_C and CV_DIST_L1 types the distance is calculated precisely, whereas for CV_DIST_L2 (Euclidian distance) the distance can be calculated only with some relative error (a mask gives more accurate results). For a , b and c OpenCV uses the values suggested in the original paper:
CV_DIST_C  a = 1, b = 1  

CV_DIST_L1  a = 1, b = 2  
CV_DIST_L2  a=0.955, b=1.3693  
CV_DIST_L2  a=1, b=1.4, c=2.1969 
Typically, for a fast, coarse distance estimation CV_DIST_L2 , a mask is used, and for a more accurate distance estimation CV_DIST_L2 , a mask or the precise algorithm is used. Note that both the precise and the approximate algorithms are linear on the number of pixels.
The second variant of the function does not only compute the minimum distance for each pixel , but it also identifies the nearest the nearest connected component consisting of zero pixels. Index of the component is stored in . The connected components of zero pixels are also found and marked by the function.
In this mode the complexity is still linear. That is, the function provides a very fast way to compute Voronoi diagram for the binary image. Currently, this second variant can only use the approximate distance transform algorithm.
Fills a connected component with the given color.
Parameters: 


The functions floodFill fill a connected component starting from the seed point with the specified color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The pixel at is considered to belong to the repainted domain if:
grayscale image, floating range
grayscale image, fixed range
color image, floating range
color image, fixed range
where is the value of one of pixel neighbors that is already known to belong to the component. That is, to be added to the connected component, a pixel’s color/brightness should be close enough to the:
By using these functions you can either mark a connected component with the specified color inplace, or build a mask and then extract the contour or copy the region to another image etc. Various modes of the function are demonstrated in floodfill.c sample.
See also: findContours()
Inpaints the selected region in the image.
Parameters: 


The function reconstructs the selected image area from the pixel near the area boundary. The function may be used to remove dust and scratches from a scanned photo, or to remove undesirable objects from still images or video. See http://en.wikipedia.org/wiki/Inpainting for more details.
Calculates the integral of an image.
Parameters: 


The functions integral calculate one or more integral images for the source image as following:
Using these integral images, one may calculate sum, mean and standard deviation over a specific upright or rotated rectangular region of the image in a constant time, for example:
It makes possible to do a fast blurring or fast block correlation with variable window size, for example. In the case of multichannel images, sums for each channel are accumulated independently.
As a practical example, the next figure shows the calculation of the integral of a straight rectangle Rect(3,3,3,2) and of a tilted rectangle Rect(5,1,2,3) . The selected pixels in the original image are shown, as well as the relative pixels in the integral images sum and tilted .
begin{center}
end{center}
Applies a fixedlevel threshold to each array element
Parameters: 


The function applies fixedlevel thresholding to a singlechannel array. The function is typically used to get a bilevel (binary) image out of a grayscale image ( compare() could be also used for this purpose) or for removing a noise, i.e. filtering out pixels with too small or too large values. There are several types of thresholding that the function supports that are determined by thresholdType :
THRESH_BINARY
THRESH_BINARY_INV
THRESH_TRUNC
THRESH_TOZERO
THRESH_TOZERO_INV
Also, the special value THRESH_OTSU may be combined with one of the above values. In this case the function determines the optimal threshold value using Otsu’s algorithm and uses it instead of the specified thresh . The function returns the computed threshold value. Currently, Otsu’s method is implemented only for 8bit images.
See also: adaptiveThreshold() , findContours() , compare() , min() , max()
Does markerbased image segmentation using watershed algrorithm
Parameters: 


The function implements one of the variants of watershed, nonparametric markerbased segmentation algorithm, described in [Meyer92] . Before passing the image to the function, user has to outline roughly the desired regions in the image markers with positive ( ) indices, i.e. every region is represented as one or more connected components with the pixel values 1, 2, 3 etc (such markers can be retrieved from a binary mask using findContours() and drawContours() , see watershed.cpp demo). The markers will be “seeds” of the future image regions. All the other pixels in markers , which relation to the outlined regions is not known and should be defined by the algorithm, should be set to 0’s. On the output of the function, each pixel in markers is set to one of values of the “seed” components, or to 1 at boundaries between the regions.
Note, that it is not necessary that every two neighbor connected components are separated by a watershed boundary (1’s pixels), for example, in case when such tangent components exist in the initial marker image. Visual demonstration and usage example of the function can be found in OpenCV samples directory; see watershed.cpp demo.
See also: findContours()