The image processing --- "pixel index image acquisition, processing pixel range, mask applying"

Image processing --- "picture mask processing -> increase the brightness of the image."

  Learning: For a picture, (1) how to obtain pixel index image, (2) processing pixel range, (3) application of a mask

/ * **************************** ************************************** 
author: @ WP20190612 
environment: VS2010 + OpenCV2.4.3 function : --- masking operation to improve the contrast of the image description: knowledge 1: image acquisition pixel index CV_Assert (myImage.depth () == CV_8U); Mat.ptr <UCHAR> (int I = 0); obtaining the pixel matrix pointers, index i denotes the first few lines, counts from 0 const uchar * current = myImage.ptr <uchar > (row); get a pointer to the current row p (row, col) = current [col]; get the current pixel p (row, col) of the pixel values of points which must be clear --- pixel index may be adjusted, and where not to adjust the knowledge 2: pixel range processing saturate_cast <uchar>, ensure that the RGB values in the range between 0 to 255. saturate_cast <uchar> (- 100) return 0; saturate_cast <UCHAR> (288) returns 255; saturate_cast <UCHAR> (100) returned 100; knowledge 3: --- masking operation to improve the contrast of the image **************************************** **********************************************
* / // ------------------------------- function: to write the function to achieve image mask operation -------- ------------ #include <opencv2 / opencv.hpp> #include <the iostream> #include <math.h> the using namespace CV; int main ( int argc, char ** the argv) // argumentss parameters; number of command line arguments argc; { Mat the src, DST; the src = imread ( " D: \\ \\ test001.png example_opencv work_VS2010 \\ " ); IF (! src.data) { the printf ( "Not Load Image ... Could \ n- " ); return - . 1 ; // return a successful completion of this function is 0; return -1 This function is not completed } namedWindow ( " INPUT Image " , CV_WINDOW_AUTOSIZE); imshow ( " INPUT Image " , src); // ---------------------------- ------------- start processing image -------------------------- // int cols = src.cols; // single channel int cols = (src.cols- . 1 ) * src.channels (); // width of the image the number of rows --- multichannel image int offsetX src.channels = (); // number of channels int rows = src.rows; DST = Mat :: zeros (src.size (), src.type ()); // initialize a uniform matrix size of the original image matrix is 0, the processing for storing the image // start masking function processing for ( int Row = . 1 ; Row <(rows- . 1 ); Row ++ ) { // Get the pixel position pointer const UCHAR * Current = src.ptr <UCHAR> (Row); // current pixel position pointer const UCHAR * = previous src.ptr <UCHAR> (row- . 1 ); // before a pixel of the current pixel location pointer const UCHAR * Next src.ptr = <UCHAR> (Row + . 1 ); //After the current cursor pixel position a pixel UCHAR * Output = dst.ptr <UCHAR> (Row); for ( int COL = offsetX; COL <cols; COL ++ ) { // Output [COL] = Current. 5 * [COL] - (Current [COL-offsetX] + Current [COL + offsetX] + Previous [COL] Next + [COL]); // glitch effect Output [COL] = saturate_cast <UCHAR> ( . 5 * Current [COL] - (Current [ offsetX-COL] + Current [COL + offsetX] + Previous [COL] Next + [COL])); // burr mention the effect } } namedWindow ( " the Image After mask " , CV_WINDOW_AUTOSIZE); imshow ( "After Image mask The " , DST); // save image imwrite ( " D: \\ \\ test001_result.png example_opencv work_VS2010 \\ " , DST); // -------------- -------------- end image processing --------------------------------- ------ waitKey ( 0 ); return 0 ; }

/***************************************************************************************
作者:@WP20190612
功能:掩膜操作---提高图像的对比度 说明: 借用OpenCV中的API---filter2D() 掩膜函数进行 **************************************************************************************
*/ //-------------------------------功能:filter2D() 进行掩膜处理-------------------- #include <opencv2/opencv.hpp> #include <iostream> #include <math.h> using namespace cv; int main (int argc, char** argv) //argumentss 参数;argc命令行参数个数; { Mat src, dst; src = imread("D:\\work_VS2010\\example_opencv\\test001.png"); if (!src.data) { printf("could not load image ...\n"); return -1; //return 0 成功完成本函数;return -1 未能完成本函数 } namedWindow("input image", CV_WINDOW_AUTOSIZE); imshow("input image", src); //----------------------------开始处理图像--------------------------------------- //使用filter2D() 掩膜函数 Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0); filter2D(src, dst, src.depth(), kernel); namedWindow("the image after mask", CV_WINDOW_AUTOSIZE ); imshow("the image after mask",dst); //保存图像 imwrite("D:\\work_VS2010\\example_opencv\\test001_result.png", dst); //----------------------------结束处理图像--------------------------------------- waitKey(0); return 0; }

 

Guess you like

Origin www.cnblogs.com/carle-09/p/11027863.html