Fast Element Access =================== .. highlight:: cpp Historically, OpenCV provided many different ways to access image and matrix elements, and none of them was both fast and convenient. With the new data structures, OpenCV 2.x introduces a few more alternatives, hopefully more convenient than before. For detailed description of the operations, please, check :ref:`Mat` and description. Here is part of the retro-photo-styling example rewritten (in simplified form) using the element access operations: :: ... // split the image into separate color planes vector planes; split(img_yuv, planes); // method 1. process Y plane using an iterator MatIterator_ it = planes[0].begin(), it_end = planes[0].end(); for(; it != it_end; ++it) { double v = *it*1.7 + rand() *it = saturate_cast(v*v/255.); } // method 2. process the first chroma plane using pre-stored row pointer. // method 3. process the second chroma plane using // individual element access operations for( int y = 0; y < img_yuv.rows; y++ ) { uchar* Uptr = planes[1].ptr(y); for( int x = 0; x < img_yuv.cols; x++ ) { Uptr[x] = saturate_cast((Uptr[x]-128)/2 + 128); uchar& Vxy = planes[2].at(y, x); Vxy = saturate_cast((Vxy-128)/2 + 128); } } merge(planes, img_yuv); ... ..