Applies an adaptive threshold to an array.
Parameters: |
|
---|
The function transforms a grayscale image to a binary image according to the formulas:
CV_THRESH_BINARY
CV_THRESH_BINARY_INV
where
is a threshold calculated individually for each pixel.
For the method
CV_ADAPTIVE_THRESH_MEAN_C
it is the mean of a
pixel neighborhood, minus
param1
.
For the method
CV_ADAPTIVE_THRESH_GAUSSIAN_C
it is the weighted sum (gaussian) of a
pixel neighborhood, minus
param1
.
Converts an image from one color space to another.
Parameters: |
|
---|
The function converts the input image from one color
space to another. The function ignores the
colorModel
and
channelSeq
fields of the
IplImage
header, so the
source image color space should be specified correctly (including
order of the channels in the case of RGB space. For example, BGR means 24-bit
format with
layout
whereas RGB means 24-format with
layout).
The conventional range for R,G,B channel values is:
Of course, in the case of linear transformations the range can be specific, but in order to get correct results in the case of non-linear transformations, the input image should be scaled.
The function can do the following transformations:
Transformations within RGB space like adding/removing the alpha channel, reversing the channel order, conversion to/from 16-bit 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:
cvCvtColor(src ,bwsrc, CV_RGB2GRAY)
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 floating-point 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 8-bit and 16-bit images
R, G and B are converted to floating-point format and scaled to fit the 0 to 1 range
if
then
On output
,
,
.
The values are then converted to the destination data type:
8-bit images
16-bit 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 8-bit and 16-bit images
R, G and B are converted to floating-point format and scaled to fit the 0 to 1 range.
if
then
On output
,
,
.
The values are then converted to the destination data type:
8-bit images
16-bit 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 8-bit and 16-bit images
R, G and B are converted to floating-point format and scaled to fit the 0 to 1 range
where
and
On output
,
,
The values are then converted to the destination data type:
8-bit 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 8-bit and 16-bit images
R, G and B are converted to floating-point format and scaled to fit 0 to 1 range
On output
,
,
.
The values are then converted to the destination data type:
8-bit 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 Ford98 at the Charles Poynton site.
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 all non-zero pixels of the source image.
Parameters: |
|
---|
The function calculates the approximated
distance from every binary image pixel to the nearest zero pixel.
For zero pixels the function sets the zero distance, for others it
finds the shortest path 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), OpenCV uses the values suggested in
Borgefors86
:
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 |
And below are samples of the distance field (black (0) pixel is in the middle of white square) in the case of a user-defined distance:
User-defined
mask (a=1, b=1.5)
4.5 | 4 | 3.5 | 3 | 3.5 | 4 | 4.5 |
---|---|---|---|---|---|---|
4 | 3 | 2.5 | 2 | 2.5 | 3 | 4 |
3.5 | 2.5 | 1.5 | 1 | 1.5 | 2.5 | 3.5 |
3 | 2 | 1 | 1 | 2 | 3 | |
3.5 | 2.5 | 1.5 | 1 | 1.5 | 2.5 | 3.5 |
4 | 3 | 2.5 | 2 | 2.5 | 3 | 4 |
4.5 | 4 | 3.5 | 3 | 3.5 | 4 | 4.5 |
User-defined
mask (a=1, b=1.5, c=2)
4.5 | 3.5 | 3 | 3 | 3 | 3.5 | 4.5 |
---|---|---|---|---|---|---|
3.5 | 3 | 2 | 2 | 2 | 3 | 3.5 |
3 | 2 | 1.5 | 1 | 1.5 | 2 | 3 |
3 | 2 | 1 | 1 | 2 | 3 | |
3 | 2 | 1.5 | 1 | 1.5 | 2 | 3 |
3.5 | 3 | 2 | 2 | 2 | 3 | 3.5 |
4 | 3.5 | 3 | 3 | 3 | 3.5 | 4 |
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 is used.
When the output parameter labels is not NULL , for every non-zero pixel the function also finds the nearest connected component consisting of zero pixels. The connected components themselves are found as contours in the beginning of the function.
In this mode the processing time is still O(N), where N is the number of pixels. Thus, the function provides a very fast way to compute approximate Voronoi diagram for the binary image.
Connected component, represented as a tuple (area, value, rect), where area is the area of the component as a float, value is the average color as a CvScalar , and rect is the ROI of the component, as a CvRect .
Fills a connected component with the given color.
Parameters: |
|
---|
The function fills a connected component starting from the seed point with the specified color. The connectivity is determined by the closeness of pixel values. 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, to be added to the connected component, a pixel’s color/brightness should be close enough to the:
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.
Calculates the integral of an image.
Parameters: |
|
---|
The function calculates 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 up-right 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 multi-channel images, sums for each channel are accumulated independently.
Does meanshift image segmentation
Parameters: |
|
---|
The function implements the filtering
stage of meanshift segmentation, that is, the output of the function is
the filtered “posterized” image with color gradients and fine-grain
texture flattened. At every pixel
of the input image (or
down-sized input image, see below) the function executes meanshift
iterations, that is, the pixel
neighborhood in the joint
space-color hyperspace is considered:
where (R,G,B) and (r,g,b) are the vectors of color components at (X,Y) and (x,y) , respectively (though, the algorithm does not depend on the color space used, so any 3-component color space can be used instead). Over the neighborhood the average spatial value (X',Y') and average color vector (R',G',B') are found and they act as the neighborhood center on the next iteration:
After the iterations over, the color components of the initial pixel (that is, the pixel from where the iterations started) are set to the final value (average color at the last iteration):
Then
, the gaussian pyramid of
levels is built, and the above procedure is run
on the smallest layer. After that, the results are propagated to the
larger layer and the iterations are run again only on those pixels where
the layer colors differ much (
) from the lower-resolution
layer, that is, the boundaries of the color regions are clarified. Note,
that the results will be actually different from the ones obtained by
running the meanshift procedure on the whole original image (i.e. when
).
Implements image segmentation by pyramids.
Parameters: |
|
---|
The function implements image segmentation by pyramids. The pyramid builds up to the level
level
. The links between any pixel
a
on level
i
and its candidate father pixel
b
on the adjacent level are established if
.
After the connected components are defined, they are joined into several clusters.
Any two segments A and B belong to the same cluster, if
.
If the input image has only one channel, then
.
If the input image has three channels (red, green and blue), then
There may be more than one connected component per a cluster. The images src and dst should be 8-bit single-channel or 3-channel images or equal size.
Applies a fixed-level threshold to array elements.
Parameters: |
|
---|
The function applies fixed-level thresholding to a single-channel array. The function is typically used to get a bi-level (binary) image out of a grayscale image ( CmpS 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 :
CV_THRESH_BINARY
CV_THRESH_BINARY_INV
CV_THRESH_TRUNC
CV_THRESH_TOZERO
CV_THRESH_TOZERO_INV
Also, the special value CV_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 8-bit images.