We operate in the practical application of the image, is often not the image as a whole operates, but the image point all points or special operations, so it is very important to traverse the image, how to efficiently traverse the image is A very worth exploring. A traversal of the image in four ways: at \u0026 lt; typename \u0026 gt; (i, j) Mat class provides a method at for get points Nike Lunarglide+ 3 on the image, it is a template function that can take on any type of image points ʱ?? Here we have an image to illustrate the actual process of its usage. In practice, we often need to drop the color image, since Mens Nike Free 3.0 Wool Skin Shoes Red Grey 256 * 256 * 256 too much, when the image color clustering or color histogram, we need to use some color instead of the typical rich color space, Our idea is to 256 colors for each channel with 64 kinds of substitute, soon had 256 colors 64 colors divided into segments, each color segment to take the middle of the color value as the representative color. void colorReduce (Mat \u0026 amp; image, int div) {for (int i = 0; i \u0026 lt; image.rows; i ++) {for (int j = 0; j \u0026 lt; image.cols; j ++) {image.at \u0026 lt; Vec3b \u0026 gt; ( i, j) [0] = image.at \u0026 lt; Vec3b \u0026 gt; (i, j) [0] / div * div + div / 2; image.at \u0026 lt; Vec3b \u0026 gt; (i, j) [1] = image.at \u0026 lt; Vec3b \u0026 gt; (i, j) [1] / div * div + div / 2; image.at \u0026 lt; Vec3b \u0026 gt; (i, j) Nike Lunareclipse [2] = image.at \u0026 lt; Vec3b \u0026 gt; (i, j) [2] / div * div + div / 2;}}} Through the above examples we can see, at a point in the image Methods of usage: image.at \u0026 lt; uchar \u0026 gt; (i, j): Remove the gray scale image in row i and column j point. image.at \u0026 lt; Vec3b \u0026 gt; (i, j) [k]: Remove color dot color image column i and the row j of the k-th channel. Where the type uchar, Vec3b all image pixel values, do not feel Vec3b this type of fear, in fact, in the core where it is through the typedef Vec \u0026 lt; T, N \u0026 gt; defined, N representative of the number of elements, T representation type. Some of the more simple approach: OpenCV Mat template defines a subclass of Mat_, it overloaded operator () so that we can more easily take the point on the image. Mat_ \u0026 lt; uchar \u0026 gt; im = image; im (i, j) = im (i, j) / div * div + div / 2; Second, efficient point: pointer to traverse the image above routine you can see, we actually like the original pass into the inner function, but in the function of our original image has been modified, but the original output as a result, a lot of times we need to retain the original image, so we need a copy of the original. void colorReduce (const Mat \u0026 amp; image, Mat \u0026 amp; outImage, int div) {// create an image of the original image size, etc. outImage.create (image.size (), image.type ()); int nr = image.rows; // will be converted to 3-channel 1 channel int nl = image.cols * image.channels (); for (int k = 0; k \u0026 lt; nr; k ++) {// for each line of the image pointer const uchar * inData = image. ptr \u0026 lt; uchar \u0026 gt; (k); uchar * outData = outImage.ptr \u0026 lt; uchar \u0026 gt; (k); for (int i = 0; i \u0026 lt; nl; i ++) {outData [i] = inData [i] / div * div + div / 2;}}} The above example can be seen in the i-th row removed image data pointers: image.ptr \u0026 lt; uchar \u0026 gt; (i). Worthy of note are: the program will be a three-channel data into a 1-channel, each line is established between the data elements are stored contiguously in memory, with each pixel three-channel pixels are stored sequentially. That Nike Running is an image data of three values the beginning, is the value of that pixel in the top left corner of the three channels. But this usage can not be used between the rows and rows, because there may be gaps between the cells in the image in OpenCV storage mechanism, rows and rows. These blank cells on the image is meaningless, just to be able to Nike KD 7 Kids be more efficient on some architectures, such as intel MMX can more effectively deal with the kind of number is a multiple of 4 or 8 rows. But we can affirm a continuous space to store images, introduced the topic to the most efficient mechanism to traverse below the image. Third, more efficient method already mentioned above, the memory is not continuous often between general image from row to row, but some images may be continuous, Mat provides a continuous function to detect whether the image isContinuous () ʱ?? When Nike Running the image is communicated, we can put the image fully expanded, as a line. void colorReduce (const Mat \u0026 amp; image, Mat \u0026 amp; outImage, int div) {int nr = image.rows; int nc = image.cols; outImage.create (image.size (), image.type ()); if (image .isContinuous () \u0026 amp; \u0026 amp; outImage.isContinuous ()) {nr = 1; nc = nc * image.rows * image.channels ();} for (int i = 0; i \u0026 lt; nr; i ++) {const uchar * inData = image.ptr \u0026 lt; uchar \u0026 gt; (i); uchar * outData = outImage.ptr \u0026 lt; uchar \u0026 gt; (i); for (int j = 0; j \u0026 lt; nc; j ++) {* outData ++ = * inData ++ / div * div + div / 2;}}} pointer in addition to using the above method, you can also use the pointer to the index pixel fixed location: image.step returns the number of elements in a row of pixels image (including blank element), image.elemSize () It returns the size of an image pixel. \u0026 Amp; image.at \u0026 lt; uchar \u0026 gt; (i, j) = image.data + i * image.step + j * image.elemSize (); four, still available? Use iterators to traverse. The following method allows us to image pixels declare an iterator: MatIterator_ \u0026 lt; Vec3b \u0026 gt; it; Mat_ \u0026 lt; Vec3b \u0026 gt; :: iterator it; Nike Air Max if the iterator to a const image, you can use the following statement: MatConstIterator \u0026 lt; Vec3b \u0026 gt ; it; or Mat_ \u0026 lt; Vec3b \u0026 gt; :: const_iterator it; let's use an iterator to simplify the above colorReduce program: void colorReduce (const Mat \u0026 amp; Mens Nike Free Run 3 Shoes Blue 3 image, Mat \u0026 amp; outImage, int div) {outImage.create (image.size () , image.type ()); MatConstIterator_ \u0026 lt; Vec3b \u0026 gt; it_in = image.begin \u0026 lt; Vec3b \u0026 gt; (); MatConstIterator_ \u0026 lt; Vec3b \u0026 gt; itend_in = image.end \u0026 lt; Vec3b \u0026 gt; (); MatIterator_ \u0026 lt; Vec3b \u0026 gt; it_out = outImage.begin \u0026 lt; Vec3b \u0026 gt; (); MatIterator_ \u0026 lt; Vec3b \u0026 gt; itend_out = outImage.end \u0026 lt; Vec3b \u0026 gt; (); while (! it_in = itend_in) 579765-700 Sonic Yellow / Sail - Cool Grey - Tour Yellow Nike Air Max LeBron 10 Low Sonic Yellow Online {(* it_out) [0] = (* it_in) [0] / div * div + div / 2; (* it_out) [1] = (* it_in) [1] / div * div + div / 2; (* it_out) [2] = (* it_in) [2] / div * div + div / 2; it_in ++; it_out ++;}} if you want to start from the second row, you can from image.begin \u0026 lt; Vec3b \u0026 gt; () + image.rows start. The above four kinds of methods, the most efficient method of third! Fifth, the operation of the image of the neighborhood very often, we are talking about image processing, to consider its neighbors, such as 3 * 3 is our common, which is most common in image filtering, de-noising, Here we introduce if in a picture traversal operation carried out neighborhood. Here we make a simple filtering operation, filtering operator is [0-10; -15-1; 0-10]. It allows the image becomes sharp, and the edge is more prominent. I.e., the core formula: sharp (ij) = 5 * image (i, j) -image (i-1, j) -image (i + 1, j) -image (i, j-1) -image Nike Free 3.0 V5 (i, j +1). void ImgFilter2d (const Mat \u0026 amp; image, Mat \u0026 amp; result) {result.create (image.size (), image.type ()); int Nike Free 3.0 V4 nr = image.rows; int nc = image.cols * image.channels () ; for (int i = 1; i \u0026 lt; nr-1; i ++) {const uchar * up_line = image.ptr \u0026 lt; uchar \u0026 gt; (i-1); // point to the line const uchar * mid_line = image.ptr \u0026 lt; uchar \u0026 gt; (i); // current row const uchar * down_line = image.ptr \u0026 lt; uchar \u0026 gt; (i + 1); // next line uchar * cur_line = result.ptr \u0026 lt; uchar \u0026 gt; (i); for (int j = 1; j \u0026 lt; nc-1; j ++) {cur_line [j] = saturate_cast \u0026 lt; uchar \u0026 gt; (5 * mid_line [j] -mid_line [j-1] -mid_line [j + 1] - up_line [j] -down_line [j]) ;}} // edge of the image pixel is set to 0 result.row (0) 2015 Mens Nike Free 3.0 Wool Skin Shoes Red Grey Nike Free 5.0 .setTo (Scalar (0)); result.row (result.rows-1) .setTo (Scalar (0)); result.col ( 0) .setTo (Scalar (0)); result.col (result.cols-1) .setTo (Scalar (0));} The above program has the following points should be noted: 1, staturate_cast \u0026 lt; typename \u0026 gt; is a type conversion functions, program operation results to ensure uchar still within range. 2, row and col image method returns some rows or columns, the return Mens Nike Free 3.0 Wool Skin Shoes Grey Navy value is a Mat. 3, setTo method Mat on the image of the point is set to a value, Scalar (n) is a gray value, Scalar (a, b, c) as a color value. Sixth, the image arithmetic Mat class put a lot of arithmetic operators have been overloaded, let them to meet certain matrix operations, if +, -, dot and so on. Let us look with a bit of basic arithmetic operations and to complete this article colorReduce program, it is simpler and more efficient. The 256 kinds of shades of gray dropped 64 actually abandoned the binary rearmost four, so we can do this step using a bit manipulation process. First, we calculate 2 ^ 8 down 2 ^ n of n: int n = static_cast \u0026 lt; int \u0026 gt; (log (static_cast \u0026 lt; double \u0026 gt; (div)) / log (2.0)); then you can get the mask, mask = 0xFF \u0026 lt; \u0026 lt ; n; with the following is simply a statement that you can get the results we want: result = (image \u0026 amp; Scalar (mask, mask, mask)) + Scalar (div / 2, div / 2, div / 2); many times we need to communicate the image of a separate operation, such as in the HSV color model, we often consider the three channels separately. vector \u0026 lt; Mat \u0026 gt; planes; // the planes in the three images into one three-channel image merge; // the image into three Air Jordan Outlet channels of images stored in the planes of the split (image, planes); planes [0] + = image2 (planes, result); (2)OpenCV growth path: image traversal