opencv影象增強demo
阿新 • • 發佈:2018-12-18
opencv影象增強demo
https://blog.csdn.net/jacke121/article/details/54706279
#include <QCoreApplication> #include<opencv2/highgui/highgui.hpp> #include<opencv2/core/core.hpp> #include<opencv2/imgproc/imgproc.hpp> #include<opencv/ml.h> #include<opencv2/photo/photo.hpp> using namespace cv; using namespace std; cv::Mat image_clahe; int erosion_elem = 0; int erosion_size = 0; int dilation_elem = 0; int dilation_size = 0; void Erosion( int, void* ) {Mat dst1; int erosion_type; namedWindow( "Erosion Demo", CV_WINDOW_AUTOSIZE ); if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; } else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; } else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; } Mat element = getStructuringElement( erosion_type, Size( 2*erosion_size + 1, 2*erosion_size+1 ), Point( erosion_size, erosion_size ) ); /// Apply the erosion operation erode( image_clahe, image_clahe, element,Point(0,0),3000 ); fastNlMeansDenoisingColored( image_clahe, dst1, 3, 3, 7, 21 ); imshow( "Erosion Demo", dst1); imwrite("/home/sukhad/Downloads/Nipun.jpg",dst1); } /** @function Dilation */ void Dilation( int, void* ) { int dilation_type; namedWindow( "Dilation Demo", CV_WINDOW_AUTOSIZE ); if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; } else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; } else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; } Mat element = getStructuringElement( dilation_type, Size( 2*dilation_size + 1, 2*dilation_size+1 ), Point( dilation_size, dilation_size ) ); /// Apply the dilation operation dilate( image_clahe, image_clahe, element,Point(0,0),3000 ); imshow( "Dilation Demo", image_clahe ); } int main(int argc, char** argv) { QCoreApplication a(argc, argv); // READ RGB color image and convert it to Lab cv::Mat bgr_image; cv::Mat lab_image; bgr_image=imread("051246060311637.png"); cv::cvtColor(bgr_image, lab_image, CV_BGR2Lab); cv::Mat dst1; // Extract the L channel std::vector<cv::Mat> lab_planes(3); cv::split(lab_image, lab_planes); // now we have the L image in lab_planes[0] // apply the CLAHE algorithm to the L channel cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE(); clahe->setClipLimit(4); cv::Mat dst; clahe->apply(lab_planes[0], dst); // Merge the the color planes back into an Lab image dst.copyTo(lab_planes[0]); cv::merge(lab_planes, lab_image); // convert back to RGB cv::cvtColor(lab_image, image_clahe, CV_Lab2BGR); namedWindow( "image original", CV_WINDOW_AUTOSIZE ); namedWindow( "image CLAHE", CV_WINDOW_AUTOSIZE ); // display the results (you might also want to see lab_planes[0] before and after). Erosion( 0, 0 ); Dilation( 0, 0 ); imshow("image original", bgr_image); imshow("image CLAHE", image_clahe); return a.exec(); } //#include <iostream> //#include <iomanip> //#include <math.h> //#include <ctime> //void checkTripletASM(float* aptr,float* bptr,float* cptr,int& o) //{ // _asm { // push eax // push ebx // mov eax, aptr // mov ebx, bptr // movaps xmm0, [eax] // movaps xmm1, [ebx] // movaps xmm7, xmm0 // mulps xmm7, xmm0 // movaps xmm2, xmm7 // movaps xmm7, xmm1 // mulps xmm7, xmm1 // movaps xmm3, xmm7 // movaps xmm4, xmm2 // addps xmm4, xmm3 // movaps xmm5, xmm4 // sqrtps xmm5, xmm5 // roundps xmm5, xmm5, 1 // mulps xmm5, xmm5 // subps xmm5, xmm4 // mov eax, cptr // movaps[eax], xmm5 // pop ebx // pop eax // } // for (int i = 0; i < 4;i++) // if (*(cptr + i) == 0.0) // { // o++; // //std::cout << *(aptr + i) << " " << *(bptr + i) << " " << *(aptr + i) * *(aptr + i) + // //*(bptr + i) * *(bptr + i) << std::endl; // } //} //void checkTripletC(float* aptr, float* bptr, float* cptr, int& o) //{ // for (int i = 0 ; i < 4;i++) // { // float a = aptr[i] * aptr[i] + bptr[i] * bptr[i]; // if (sqrt(a) == round(sqrt(a))) // { // o++; // //std::cout << aptr[i] << " " << bptr[i] <<" "<< a << std::endl; // } // } //} //float Experiment( void(*fun)(float*, float*, float*, int&), int& countas,int pr) //{ // int n = pr; // __declspec(align(16)) float pa[4] = { 1,1,6,1 }; // __declspec(align(16)) float pb[4] = { 4096,1,8,1 }; // __declspec(align(16)) float ts[4] = { 0,0,0,0 }; // float* aptr = &pa[0]; // float* bptr = &pb[0]; // float* cptr = &ts[0]; // int c = 0; // int o = 0; // std::clock_t b = std::clock(); // for (int i = 1; i <= n; i++) // for (int j = i; j <= n;j++) // { // pa[c] = i; pb[c] = j; c++; // if (c == 4) // { // c = 0; // fun(aptr, bptr, cptr, o); // } // } // std::clock_t end = std::clock(); // float ats = (float)(end - b) / CLOCKS_PER_SEC ; // countas = o; // return ats; //} //int main() //{ // int n = 100; // int pr = 2000; // float m = 0; // void(*fun)(float*,float*,float*,int&); // fun = &checkTripletASM; // int c = 0; // std::cout << "RUNS: " << n << " PER RUN: " << pr << std::endl; // std::cout << "TEST BEGINS! \n"; // for (int i = 0; i < n;i++) // m += Experiment(fun,c,pr); // std::cout <<"SSE/FLOAT TIME: "<< m / (float)n << " ENTRYS: " << c << std::endl; // m = 0; // fun = &checkTripletC; // for (int i = 0; i < n;i++) // m += Experiment(fun,c,pr); // std::cout << "C++/FLOAT TIME: " << m / (float)n << " ENTRYS: " << c << std::endl; // std::cout << "TEST END!"; // std::cin.ignore(); //} 目標效果如下,但是本demo好像達不到
專案地址:https://github.com/sukhad-app/under-water-image-enhancement
這個效果也一般:
http://download.csdn.net/download/mashang666/9555191
http://download.csdn.net/detail/dbc12345666/8092531,這個影象增強後效果: