Filter and color conversion
Hunnish Note:
This translation is to translate directly according to the OpenCV Beta 4.0 version of the user manual, the original file is:
There must be many mistakes in the translation, and some terms and original semantic understandings are not accurate or wrong, please also enlighten me. Translation The purpose of these English reference is to improve the actual application level of OpenCV in computer vision, pattern recognition, and image processing with enthusiasts of OpenCV.
Smooth
The image smoothing of various methods
Void CvsuMooth (Const Cvarr * SRC, CVARR * DST,
Int SmoothType = CV_GAUSSIAN,
INT param1 = 3, int param2 = 0, double param3 = 0);
SRC
Enter the image.
DST
Output image.
SmoothType
Smooth method:
CV_BLUR_NO_SCALE (Fuzzy Duty Transformation) - Asked for PARAM1 × param2 for each pixel field. If the neighborhood size is changing, the function Cvintegral calculates the integral image in advance. CV_BLUR (Simple BLUR) - For each pixel neighbor param1 × param2 and do scale transformation 1 / (param1 • param2). CV_GAUSSIAN (Gaussian BLUR) - Size of the image of param1 × param2 CV_MEDian (Median Blur) - Discovery of neighbor param1 × param1 (IE neighborhood). CV_bilateral (double filtering) - Application two-way 3x3 filter, color Sigma = param1, space sigma = param2. About two-way filtering, refer to Http://www.dai.ed.ac.uk/cvonline/local_copies/manduchi1/bilateral_filtering.html
PARAM1
The first parameter of smooth operation.
PARAM2
The second parameter of smoothing operation.
PARAM2 is zero corresponding simple scale transformation and Gaussian blur.
PARAM3
Gaussian Sigma (standard deviation) corresponding to Gaussian parameters. If zero, this calculates the following core:
Sigma = (N / 2 - 1) * 0.3 0.8, where n = param1 corresponds to the level core,
n = param2 corresponds to the vertical core.
The standard SIGMA speed will be quickly used for small convolutionary nucleus (3 × 3 to 7 × 7). in case
PARAM3 is not zero, but
PARAM1 and
PARAM2 is zero, then the core size has Sigma calculations (to ensure enough exact operation).
The function Cvsmooth can smooth the image with any of the above methods. Each method has its own characteristics and limitations.
The image that is not scaled only supports single-channel images and supports 8 bits, 16-bit, 32-bit, and 32-bit floating point formats.
Simple blurred and Gaussian ambiguity support 1- or 3-channel, 8-bits, and 32-bit floating point images. These two methods can be processed (in-place).
Medium value and bidirectional filtering work in 1- or 3-channel, 8-bit image, but cannot process images in in-Place.
Filter2d
Volume
Void Cvfilter2D (Const Cvarr * SRC, CVARR * DST, Const Cvmat * Kernel,
CvPoint Anchor = CVPOINT (-1, -1));
#define cvconvolve2d cvfilter2d
SRC
Enter the image.
DST
Output image.
kernel
Convolutionary nuclear, single-channel floating point matrix. If you want to apply different cores different channels, use
The CVSPLIT function breaks down on a single color channel and then processed separately.
Anchor
The anchor of the core represents a position that is filtered in the nucleus. The anchor should be in the nucleus inside. The default (-1, -1) represents an anchor in the nuclear center.
The function CVFILTER2D is linearly filtered on the image, supports in-place operation. When the opening portion is outside the image, the function is from the nearest adjacent image of the pixel value to the pixel value outside the boundary.
Integral
Calculate points image
Void Cvintegral (Const Cvarr * Image, Cvarr * SUM, CVARR * SQSUM = NULL, CVARR * TILTED_SUM = NULL);
Image
Enter an image,
W ×
H, single channel, 8-bit or floating point (32F or 64F).
Sum
Point image,
W 1 ×
H 1, single channel, 32-bit integer or Double precision floating point number (64f).
SQSum
Points of interest images in parallel value
W 1 ×
H 1, single channel, 32-bit integer or Double precision floating point number (64f).
TILTED_SUM
Rotate 45 degrees of integral image, single channel, 32-bit integer or Double precision floating point number (64f).
Function Cvintegral calculates a time or high complex point image:
SUM (X, Y) = Sumx SQSUM (X, Y) = SUMX Tilted_sum (x, y) = SUMY With the integral image, you can easily get a certain area pixel point and a mean, standard variance, or a selection angle of 0 (1). E.g: SUMX1 <= x Therefore, you can do a quick and smooth or window in the changed window. Cvtcolor Color space conversion Void CVCVTCOLOR (Const Cvarr * SRC, CVARR * DST, INT CODE); SRC Entered 8-bit or floating point image. DST 8-bit or floating point image output. code Color space conversion, by defining CV_ Function CVCVTColor converts an image from a color space to another color space. The function ignores the ColorModel and the ChannelSeq domain defined in the iPlimage head, so the color space of the input image should be specified correctly (including the order of the channel. For RGB space, BGR means 24-bit format, which is arranged for B0 G0 R0 B1 G1 R1 ... laminated, and RGB means 24-bit format, which is arranged to be R0 G0 B0 R1 G1 B1 ... laminated). The function is as follows: Transform interior inside the RGB space, such as an increase / removal of Alpha channel, inverting channel sequence, 16-bit RGB color transformation (RX5: GX6: RX5), and grayscale image transformation, use: RGB [A] -> Gray: y = 0.212671 * R 0.715160 * G 0.072169 * B 0 * agray-> RGB [A]: r = yg = yb = ya = 0 All possible image color spaces are listed as follows: RGB <=> XYZ (CV_BGR2xyz, CV_RGB2xyz, CV_XYZ2BGR, CV_XYZ2RGB): | x | | 0.412411 0.357585 0.180454 | R | | Y | = | 0.212649 0.715169 0.072182 | * | g | | Z | 0.019332 0.119195 0.950390 | | B | | R | 3.240479 -1.53715 -0.498535 | | x | | G | = | -0.969256 1.875991 0.041556 | * | Y | | B | 0.055648 -0.204043 1.057311 | | z | RGB <=> YCRCB (CV_BGR2YCRB, CV_RGB2YCRCB, CV_YCRCB2BGR, CV_YCRCB2RGB) Y = 0.299 * R 0.587 * G 0.114 * B Cr = (r-y) * 0.713 128 CB = (b-y) * 0.564 128 R = Y 1.403 * (CR - 128) G = Y - 0.344 * (CR - 128) - 0.714 * (CB - 128) B = Y 1.773 * (CB - 128) RGB => HSV (CV_BGR2HSV, CV_RGB2HSV) V = Max (R, G, B) S = (V-min (r, g, b)) * 255 / v if v! = 0, 0 Otherwise (G - b) * 60 / s, if v = r H = 180 (B - r) * 60 / s, if v = g 240 (r - g) * 60 / s, if v = B IF h <0 THEN H = H 360 The color tone (hue) value is calculated using the formula from 0 ° to 360 °, ensuring that they can be tried to 8 bits after 2. RGB => Lab (CV_BGR2LAB, CV_RGB2LAB) | X | | 0.433910 0.376220 0.189860 | | R / 255 | | Y | = | 0.212649 0.715169 0.072182 | * | g / 255 | | Z | 0.017756 0.109478 0.872915 | | B / 255 | L = 116 * Y1 / 3 for y> 0.008856 L = 903.3 * y for y <= 0.008856 A = 500 * (f (x) -f (y)) B = 200 * (f (y) -f (z)) WHERE F (T) = T1 / 3 for t> 0.008856 f (t) = 7.787 * T 16/116 for t <= 0.008856 The above formula can reference http://www.cica.indiana.edu/cica/faq/color_spaces/color.spaces.html Bayer => RGB (CV_BayerBG2BGR, CV_BayerGB2BGR, CV_BayerRG2BGR, CV_BayerGR2BGR, CV_BayerBG2RGB, CV_BayerRG2BGR, CV_BayerGB2RGB, CV_BayerGR2BGR, CV_BayerRG2RGB , CV_BayerBG2BGR, CV_BayerGR2RGB, CV_BayerGB2BGR) Bayer mode is widely used in CCD and CMOS cameras. It allows to get color images from a separate plane, the R / G / B pixel point in this plane is arranged as follows: RgrgrGBGRGRGRGBGBGR GRGRGBGBG 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 C1 and C2 in the conversion constants CV_BayerC1C22 {BGR | RGB} 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.. Threshold Fixed threshold operation for array elements Void Cvthreshold (Const Cvarr * SRC, CVARR * DST, Double Threshold, Double Max_Value, int threshold_type; SRC Original array (single channel, 8-bit of 32-bit floating point). DST Output arrays, must The type of SRC is consistent, or is 8-bits. Threshold Threshold Max_Value use CV_thresh_binary and The maximum value of CV_THRESH_BINARY_INV. Threshold_type Threshold type (see discussion) Functions Cvthresh Allows a fixed threshold operation for single-channel arrays. Typically, the grayscale image is threshold to obtain a binary image. (CVCMPS can also reach this) or remove noise, such as an image point that is small or very pixel value. There are several ways to take a threshold of the image. The method supported by this function is determined by threshold_type: Threshold_type = cv_thresh_binary: DST (x, y) = max_value, IF src (x, y)> Threshold 0, Otherwise Threshold_type = cv_thresh_binary_inv: DST (X, Y) = 0, IF SRC (X, Y)> Threshold Max_Value, OtherWise Threshold_type = cv_thresh_trunc: DST (X, Y) = Threshold, IF SRC (X, Y)> Threshold SRC (X, Y), Otherwise Threshold_Type = CV_THRESH_TOZERO: DST (X, Y) = SRC (X, Y), IF (X, Y)> Threshold 0, Otherwise Threshold_type = CV_thresh_tozero_inv: DST (X, Y) = 0, IF SRC (X, Y)> Threshold SRC (X, Y), Otherwise The following is a graphical threshold description: AdaptiveThreshold Adaptive threshold method Void CvadaptiveTHRESHOLD (Const Cvarr * SRC, CVARR * DST, Double Max_Value, Int adaptive_method = CV_ADAPTIVE_THRESH_MEAN_C, INT THRESHOLD_TYPE = CV_THRESH_BINARY, INT block_size = 3, double param1 = 5); SRC Enter the image. DST Output image. Max_Value use CV_thresh_binary and The maximum value of CV_THRESH_BINARY_INV. Adaptive_method Adaptive threshold algorithm use: CV_ADAPTIVE_THRESH_MEAN_C or CV_ADAPTIVE_THRESH_GAUSSIAN_C (see discussion). Threshold_type Take threshold type: must be one of the people CV_thresh_binary, cv_thresh_binary_inv Block_size Pixel neighborhood size used to calculate the threshold: 3, 5, 7, ... PARAM1 Parameters related to methods. Method CV_ADAPTIVE_THRESH_MEAN_C and CV_ADAPTIVE_THRESH_GAUSSIAN_C, it is a constant extracted from a mean or weighting mean (see discussion), although it can be negative. The function cvadaptivethreshold converts the grayscale image to a binary image, using the following formula: Threshold_type = cv_thresh_binary: DST (x, y) = max_value, IF SRC (X, Y)> T (X, Y) 0, Otherwise Threshold_type = cv_thresh_binary_inv: DST (x, y) = 0, IF SRC (X, Y)> T (X, Y) Max_Value, OtherWise Where Ti is a threshold calculated for each pixel point Method CV_ADAPTIVE_THRESH_MEAN_C, it is the pixel point in the block_size × block_size block, which is reduced by parameter param1, and the average obtained. Method CV_ADAPTIVE_THRESH_GAUSSIAN_C It is a pixel point in the block_size × block_size block, which is reduced by parameter param1, obtained, and gaussian.