opencv on mbed
Miscellaneous Image Transformations
[Image processing]
Enumerations | |
enum | DistanceTypes { DIST_USER = -1, DIST_L1 = 1, DIST_L2 = 2, DIST_C = 3, DIST_L12 = 4, DIST_FAIR = 5, DIST_WELSCH = 6, DIST_HUBER = 7 } |
Distance types for Distance Transform and M-estimators. More... | |
enum | DistanceTransformMasks { DIST_MASK_3 = 3, DIST_MASK_5 = 5 } |
Mask size for distance transform. More... | |
enum | ThresholdTypes { THRESH_BINARY = 0, THRESH_BINARY_INV = 1, THRESH_TRUNC = 2, THRESH_TOZERO = 3, THRESH_TOZERO_INV = 4 , THRESH_OTSU = 8, THRESH_TRIANGLE = 16 } |
type of the threshold operation ![threshold types](pics/threshold.png) More... | |
enum | AdaptiveThresholdTypes { ADAPTIVE_THRESH_MEAN_C = 0, ADAPTIVE_THRESH_GAUSSIAN_C = 1 } |
adaptive threshold algorithm see cv::adaptiveThreshold More... | |
enum | UndistortTypes |
cv::undistort mode More... | |
enum | GrabCutClasses { GC_BGD = 0, GC_FGD = 1, GC_PR_BGD = 2, GC_PR_FGD = 3 } |
class of the pixel in GrabCut algorithm More... | |
enum | GrabCutModes { GC_INIT_WITH_RECT = 0, GC_INIT_WITH_MASK = 1, GC_EVAL = 2 } |
GrabCut algorithm flags. More... | |
enum | DistanceTransformLabelTypes { DIST_LABEL_CCOMP = 0, DIST_LABEL_PIXEL = 1 } |
distanceTransform algorithm flags More... | |
enum | FloodFillFlags { FLOODFILL_FIXED_RANGE = 1 << 16, FLOODFILL_MASK_ONLY = 1 << 17 } |
floodfill algorithm flags More... | |
enum | ColorConversionCodes { COLOR_BGR2BGRA = 0 , COLOR_BGRA2BGR = 1 , COLOR_BGR2RGBA = 2 , COLOR_BGR2GRAY = 6 , COLOR_BGR2BGR565 = 12 , COLOR_GRAY2BGR565 = 20 , COLOR_BGR2BGR555 = 22 , COLOR_GRAY2BGR555 = 30 , COLOR_BGR2XYZ = 32 , COLOR_BGR2YCrCb = 36 , COLOR_BGR2HSV = 40 , COLOR_BGR2Lab = 44 , COLOR_BGR2Luv = 50 , COLOR_BGR2HLS = 52 , COLOR_HSV2BGR = 54 , COLOR_BGR2YUV = 82 , COLOR_YUV2RGB_NV12 = 90 , COLOR_YUV2RGB_UYVY = 107 , COLOR_RGBA2mRGBA = 125 , COLOR_RGB2YUV_I420 = 127 , COLOR_BayerBG2BGR = 46 , COLOR_BayerBG2BGR_VNG = 62 , COLOR_BayerBG2BGR_EA = 135 } |
the color conversion code More... | |
Functions | |
CV_EXPORTS_W void | integral (InputArray src, OutputArray sum, int sdepth=-1) |
CV_EXPORTS_AS (integral2) void integral(InputArray src | |
CV_EXPORTS_AS (integral3) void integral(InputArray src | |
Calculates the integral of an image. | |
CV_EXPORTS_W double | threshold (InputArray src, OutputArray dst, double thresh, double maxval, int type) |
Applies a fixed-level threshold to each array element. | |
CV_EXPORTS_W void | adaptiveThreshold (InputArray src, OutputArray dst, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double C) |
Applies an adaptive threshold to an array. | |
CV_EXPORTS_W void | watershed (InputArray image, InputOutputArray markers) |
Performs a marker-based image segmentation using the watershed algorithm. | |
CV_EXPORTS_W void | grabCut (InputArray img, InputOutputArray mask, Rect rect, InputOutputArray bgdModel, InputOutputArray fgdModel, int iterCount, int mode=GC_EVAL) |
Runs the GrabCut algorithm. | |
CV_EXPORTS_AS (distanceTransformWithLabels) void distanceTransform(InputArray src | |
Calculates the distance to the closest zero pixel for each pixel of the source image. | |
CV_EXPORTS_W void | distanceTransform (InputArray src, OutputArray dst, int distanceType, int maskSize, int dstType=CV_32F) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
CV_EXPORTS int | floodFill (InputOutputArray image, Point seedPoint, Scalar newVal, CV_OUT Rect *rect=0, Scalar loDiff=Scalar(), Scalar upDiff=Scalar(), int flags=4) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. variant without `mask` parameter. | |
CV_EXPORTS_W int | floodFill (InputOutputArray image, InputOutputArray mask, Point seedPoint, Scalar newVal, CV_OUT Rect *rect=0, Scalar loDiff=Scalar(), Scalar upDiff=Scalar(), int flags=4) |
Fills a connected component with the given color. | |
CV_EXPORTS_W void | cvtColor (InputArray src, OutputArray dst, int code, int dstCn=0) |
Converts an image from one color space to another. |
Enumeration Type Documentation
enum AdaptiveThresholdTypes |
adaptive threshold algorithm see cv::adaptiveThreshold
- Enumerator:
Definition at line 323 of file imgproc.hpp.
enum ColorConversionCodes |
the color conversion code
- See also:
- imgproc_color_conversions
- Enumerator:
Definition at line 494 of file imgproc.hpp.
enum DistanceTransformLabelTypes |
distanceTransform algorithm flags
- Enumerator:
Definition at line 362 of file imgproc.hpp.
enum DistanceTransformMasks |
Mask size for distance transform.
Definition at line 302 of file imgproc.hpp.
enum DistanceTypes |
Distance types for Distance Transform and M-estimators.
- See also:
- cv::distanceTransform, cv::fitLine
- Enumerator:
Definition at line 290 of file imgproc.hpp.
enum FloodFillFlags |
floodfill algorithm flags
- Enumerator:
Definition at line 371 of file imgproc.hpp.
enum GrabCutClasses |
class of the pixel in GrabCut algorithm
- Enumerator:
GC_BGD an obvious background pixels
GC_FGD an obvious foreground (object) pixel
GC_PR_BGD a possible background pixel
GC_PR_FGD a possible foreground pixel
Definition at line 341 of file imgproc.hpp.
enum GrabCutModes |
GrabCut algorithm flags.
- Enumerator:
Definition at line 349 of file imgproc.hpp.
enum ThresholdTypes |
type of the threshold operation ![threshold types](pics/threshold.png)
- Enumerator:
Definition at line 310 of file imgproc.hpp.
enum UndistortTypes |
cv::undistort mode
Definition at line 335 of file imgproc.hpp.
Function Documentation
CV_EXPORTS_W void cv::adaptiveThreshold | ( | InputArray | src, |
OutputArray | dst, | ||
double | maxValue, | ||
int | adaptiveMethod, | ||
int | thresholdType, | ||
int | blockSize, | ||
double | C | ||
) |
Applies an adaptive threshold to an array.
The function transforms a grayscale image to a binary image according to the formulae:
- **THRESH_BINARY**
- **THRESH_BINARY_INV**
The function can process the image in-place.
- Parameters:
-
src Source 8-bit single-channel image. dst Destination image of the same size and the same type as src. maxValue Non-zero value assigned to the pixels for which the condition is satisfied adaptiveMethod Adaptive thresholding algorithm to use, see cv::AdaptiveThresholdTypes thresholdType Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV, see cv::ThresholdTypes. blockSize Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on. C Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well.
- See also:
- threshold, blur, GaussianBlur
cv::CV_EXPORTS_AS | ( | integral2 | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
cv::CV_EXPORTS_AS | ( | distanceTransformWithLabels | ) |
Calculates the distance to the closest zero pixel for each pixel of the source image.
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 == DIST_MASK_PRECISE and distanceType == DIST_L2 , the function runs the algorithm described in Felzenszwalb04 . This algorithm is parallelized with the TBB library.
In other cases, the algorithm Borgefors86 is used. This means that for a 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. Since the distance function should be symmetric, all of the horizontal and vertical shifts must have the same cost (denoted as a ), all the diagonal shifts must have the same cost (denoted as `b`), and all knight's moves must have the same cost (denoted as `c`). For the cv::DIST_C and cv::DIST_L1 types, the distance is calculated precisely, whereas for cv::DIST_L2 (Euclidean distance) the distance can be calculated only with a relative error (a mask gives more accurate results). For `a`,`b`, and `c`, OpenCV uses the values suggested in the original paper:
- DIST_L1: `a = 1, b = 2`
- DIST_L2:
- `3 x 3`: `a=0.955, b=1.3693`
- `5 x 5`: `a=1, b=1.4, c=2.1969`
- DIST_C: `a = 1, b = 1`
Typically, for a fast, coarse distance estimation DIST_L2, a mask is used. For a more accurate distance estimation 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.
This variant of the function does not only compute the minimum distance for each pixel but also identifies the nearest connected component consisting of zero pixels (labelType==DIST_LABEL_CCOMP) or the nearest zero pixel (labelType==DIST_LABEL_PIXEL). Index of the component/pixel is stored in `labels(x, y)`. When labelType==DIST_LABEL_CCOMP, the function automatically finds connected components of zero pixels in the input image and marks them with distinct labels. When labelType==DIST_LABEL_CCOMP, the function scans through the input image and marks all the zero pixels with distinct labels.
In this mode, the complexity is still linear. That is, the function provides a very fast way to compute the Voronoi diagram for a binary image. Currently, the second variant can use only the approximate distance transform algorithm, i.e. maskSize=DIST_MASK_PRECISE is not supported yet.
- Parameters:
-
src 8-bit, single-channel (binary) source image. dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, single-channel image of the same size as src. labels Output 2D array of labels (the discrete Voronoi diagram). It has the type CV_32SC1 and the same size as src. distanceType Type of distance, see cv::DistanceTypes maskSize Size of the distance transform mask, see cv::DistanceTransformMasks. DIST_MASK_PRECISE is not supported by this variant. In case of the DIST_L1 or DIST_C distance type, the parameter is forced to 3 because a mask gives the same result as or any larger aperture. labelType Type of the label array to build, see cv::DistanceTransformLabelTypes.
cv::CV_EXPORTS_AS | ( | integral3 | ) |
Calculates the integral of an image.
The functions calculate one or more integral images for the source image as follows:
Using these integral images, you can 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 a variable window size, for example. In case of multi-channel 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 .
![integral calculation example](pics/integral.png)
- Parameters:
-
src input image as , 8-bit or floating-point (32f or 64f). sum integral image as , 32-bit integer or floating-point (32f or 64f). sqsum integral image for squared pixel values; it is , double-precision floating-point (64f) array. tilted integral for the image rotated by 45 degrees; it is array with the same data type as sum. sdepth desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or CV_64F. sqdepth desired depth of the integral image of squared pixel values, CV_32F or CV_64F.
CV_EXPORTS_W void cv::cvtColor | ( | InputArray | src, |
OutputArray | dst, | ||
int | code, | ||
int | dstCn = 0 |
||
) |
Converts an image from one color space to another.
The function converts an input image from one color space to another. In case of a transformation to-from RGB color space, the order of the channels should be specified explicitly (RGB or BGR). Note that the default color format in OpenCV is often referred to as RGB but it is actually BGR (the bytes are reversed). So the first byte in a standard (24-bit) color image will be an 8-bit Blue component, the second byte will be Green, and the third byte will be Red. The fourth, fifth, and sixth bytes would then be the second pixel (Blue, then Green, then Red), and so on.
The conventional ranges for R, G, and B channel values are:
- 0 to 255 for CV_8U images
- 0 to 65535 for CV_16U images
- 0 to 1 for CV_32F images
In case of linear transformations, the range does not matter. But in case of a non-linear transformation, an input RGB image should be normalized to the proper value range to get the correct results, for example, for RGB L\*u\*v\* transformation. For example, if you have a 32-bit floating-point image directly converted from an 8-bit image without any scaling, then it will have the 0..255 value range instead of 0..1 assumed by the function. So, before calling cvtColor , you need first to scale the image down:
img *= 1./255; cvtColor(img, img, COLOR_BGR2Luv);
If you use cvtColor with 8-bit images, the conversion will have some information lost. For many applications, this will not be noticeable but it is recommended to use 32-bit images in applications that need the full range of colors or that convert an image before an operation and then convert back.
If conversion adds the alpha channel, its value will set to the maximum of corresponding channel range: 255 for CV_8U, 65535 for CV_16U, 1 for CV_32F.
- Parameters:
-
src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision floating-point. dst output image of the same size and depth as src. code color space conversion code (see cv::ColorConversionCodes). dstCn number of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code.
- See also:
- imgproc_color_conversions
CV_EXPORTS_W void cv::distanceTransform | ( | InputArray | src, |
OutputArray | dst, | ||
int | distanceType, | ||
int | maskSize, | ||
int | dstType = CV_32F |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
-
src 8-bit, single-channel (binary) source image. dst Output image with calculated distances. It is a 8-bit or 32-bit floating-point, single-channel image of the same size as src . distanceType Type of distance, see cv::DistanceTypes maskSize Size of the distance transform mask, see cv::DistanceTransformMasks. In case of the DIST_L1 or DIST_C distance type, the parameter is forced to 3 because a mask gives the same result as or any larger aperture. dstType Type of output image. It can be CV_8U or CV_32F. Type CV_8U can be used only for the first variant of the function and distanceType == DIST_L1.
CV_EXPORTS_W int cv::floodFill | ( | InputOutputArray | image, |
InputOutputArray | mask, | ||
Point | seedPoint, | ||
Scalar | newVal, | ||
CV_OUT Rect * | rect = 0 , |
||
Scalar | loDiff = Scalar() , |
||
Scalar | upDiff = Scalar() , |
||
int | flags = 4 |
||
) |
Fills a connected component with the given color.
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:
- in case of a grayscale image and floating range
- in case of a grayscale image and fixed range
- in case of a color image and floating range
- in case of a color image and 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 color/brightness of the pixel should be close enough to:
- Color/brightness of one of its neighbors that already belong to the connected component in case of a floating range.
- Color/brightness of the seed point in case of a fixed range.
Use these functions to either mark a connected component with the specified color in-place, or build a mask and then extract the contour, or copy the region to another image, and so on.
- Parameters:
-
image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the function unless the FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See the details below. mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller than image. Since this is both an input and output parameter, you must take responsibility of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags as described below. It is therefore possible to use the same mask in multiple calls to the function to make sure the filled areas do not overlap. seedPoint Starting point. newVal New value of the repainted domain pixels. loDiff Maximal lower brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component. upDiff Maximal upper brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component. rect Optional output parameter set by the function to the minimum bounding rectangle of the repainted domain. flags Operation flags. The first 8 bits contain a connectivity value. The default value of 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill the mask (the default value is 1). For example, 4 | ( 255 << 8 ) will consider 4 nearest neighbours and fill the mask with a value of 255. The following additional options occupy higher bits and therefore may be further combined with the connectivity and mask fill values using bit-wise or (|), see cv::FloodFillFlags.
- Note:
- Since the mask is larger than the filled image, a pixel in image corresponds to the pixel in the mask .
- See also:
- findContours
CV_EXPORTS int cv::floodFill | ( | InputOutputArray | image, |
Point | seedPoint, | ||
Scalar | newVal, | ||
CV_OUT Rect * | rect = 0 , |
||
Scalar | loDiff = Scalar() , |
||
Scalar | upDiff = Scalar() , |
||
int | flags = 4 |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. variant without `mask` parameter.
CV_EXPORTS_W void cv::grabCut | ( | InputArray | img, |
InputOutputArray | mask, | ||
Rect | rect, | ||
InputOutputArray | bgdModel, | ||
InputOutputArray | fgdModel, | ||
int | iterCount, | ||
int | mode = GC_EVAL |
||
) |
Runs the GrabCut algorithm.
The function implements the [GrabCut image segmentation algorithm](http://en.wikipedia.org/wiki/GrabCut).
- Parameters:
-
img Input 8-bit 3-channel image. mask Input/output 8-bit single-channel mask. The mask is initialized by the function when mode is set to GC_INIT_WITH_RECT. Its elements may have one of the cv::GrabCutClasses. rect ROI containing a segmented object. The pixels outside of the ROI are marked as "obvious background". The parameter is only used when mode==GC_INIT_WITH_RECT . bgdModel Temporary array for the background model. Do not modify it while you are processing the same image. fgdModel Temporary arrays for the foreground model. Do not modify it while you are processing the same image. iterCount Number of iterations the algorithm should make before returning the result. Note that the result can be refined with further calls with mode==GC_INIT_WITH_MASK or mode==GC_EVAL . mode Operation mode that could be one of the cv::GrabCutModes
CV_EXPORTS_W void cv::integral | ( | InputArray | src, |
OutputArray | sum, | ||
int | sdepth = -1 |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
CV_EXPORTS_W double cv::threshold | ( | InputArray | src, |
OutputArray | dst, | ||
double | thresh, | ||
double | maxval, | ||
int | type | ||
) |
Applies a fixed-level threshold to each array element.
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 ( cv::compare could be also used for this purpose) or for removing a noise, that is, filtering out pixels with too small or too large values. There are several types of thresholding supported by the function. They are determined by type parameter.
Also, the special values cv::THRESH_OTSU or cv::THRESH_TRIANGLE may be combined with one of the above values. In these cases, the function determines the optimal threshold value using the Otsu's or Triangle algorithm and uses it instead of the specified thresh . The function returns the computed threshold value. Currently, the Otsu's and Triangle methods are implemented only for 8-bit images.
- Parameters:
-
src input array (single-channel, 8-bit or 32-bit floating point). dst output array of the same size and type as src. thresh threshold value. maxval maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding types. type thresholding type (see the cv::ThresholdTypes).
- See also:
- adaptiveThreshold, findContours, compare, min, max
CV_EXPORTS_W void cv::watershed | ( | InputArray | image, |
InputOutputArray | markers | ||
) |
Performs a marker-based image segmentation using the watershed algorithm.
The function implements one of the variants of watershed, non-parametric marker-based segmentation algorithm, described in Meyer92 .
Before passing the image to the function, you have to roughly outline the desired regions in the image markers with positive (>0) indices. So, every region is represented as one or more connected components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary mask using findContours and drawContours (see the watershed.cpp demo). The markers are "seeds" of the future image regions. All the other pixels in markers , whose relation to the outlined regions is not known and should be defined by the algorithm, should be set to 0's. In the function output, each pixel in markers is set to a value of the "seed" components or to -1 at boundaries between the regions.
- Note:
- Any two neighbor connected components are not necessarily separated by a watershed boundary (-1's pixels); for example, they can touch each other in the initial marker image passed to the function.
- Parameters:
-
image Input 8-bit 3-channel image. markers Input/output 32-bit single-channel image (map) of markers. It should have the same size as image .
- See also:
- findContours
Generated on Tue Jul 12 2022 16:42:42 by 1.7.2