// phaseinter.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"#include#include #include "opencv2/core/core.hpp"#include "opencv2/features2d/features2d.hpp"#include "opencv2/highgui/highgui.hpp"#include #include "opencv2/imgproc/imgproc.hpp"#include "opencv2/nonfree/nonfree.hpp"#include "opencv2/legacy/legacy.hpp"#include #include using namespace cv;using namespace std;int _tmain(int argc, _TCHAR* argv[]){ int M = 0; int N = 0; Mat img = imread("test.png",0);//灰度图 if(img.empty()) { cout << "图像加载失败!" << endl; //system("pause"); return -1; }; M=img.rows;//行数、图像高度 N=img.cols;//列数、图像宽度// std::cout< <<"行"<< std::endl; // std::cout< <<"列"<< std::endl; //利用64相位4*4的模板 cv::Mat F= (cv::Mat_ (64,4) << 0,32,0, 0, 0,32,1,-1, 0,32,1,-1, -1,32,1, 0, -1,32,2,-1, //6-10 -1,32,2,-1, -2,32,3,-1, -2,32,3,-1, -3,32,4,-1, -3,32,4,-1, //11-15 -3,32,4,-1, -3,32,5,-2, -3,31,6,-2, -3,30,7,-2, -3,30,7,-2, //16-20 -4 ,30 , 8 ,-2, -4 ,29 , 9 ,-2, -4 ,29 , 9 ,-2, -4 ,28 ,10 ,-2, -4 ,27 ,11 ,-2, //21-25 -4 ,27 ,11 ,-2, -4 ,27 ,11 ,-2, -4 ,26 ,13 ,-3, -4 ,26 ,13 ,-3, -4 ,25 ,14 ,-3, //26-30 -4 ,24 ,15 ,-3, -4 ,24 ,15 ,-3, -4 ,24 ,15 ,-3, -4 ,22 ,17 ,-3, -4 ,21 ,18 ,-3, //31-35 -4 ,21 ,18 ,-3, -4 ,21 ,19 ,-4, -8 ,24 ,24 ,-8, -4 ,19 ,21 ,-4, -3 ,18 ,21 ,-4, //36-40 -3 ,18 ,21 ,-4, -3 ,17 ,22 ,-4, -3 ,15 ,24 ,-4, -3 ,15 ,24 ,-4, -3 ,15 ,24 ,-4, //41-45 -3 ,14 ,25 ,-4, -3 ,13 ,26 ,-4, -3 ,13 ,26 ,-4, -2 ,11 ,27 ,-4, -2 ,11 ,27 ,-4, //46-50 -2 ,11 ,27 ,-4, -2 ,10 ,28 ,-4, -2 , 9 ,29 ,-4, -2 , 9 ,29 ,-4, -2 , 8 ,30 ,-4, //51-55 -2 ,7 ,30 ,-3, -2 ,7 ,30 ,-3, -2 ,6 ,31 ,-3, -2 ,5 ,32 ,-3, -1 ,4 ,32 ,-3, //56-60 -1 ,4 ,32 ,-3, -1 ,4 ,32 ,-3, -1 ,3 ,32 ,-2, -1 ,3 ,32 ,-2, -1 ,2 ,32 ,-1, //61-64 -1 ,2 ,32 ,-1, 0 ,1 ,32 ,-1, -1 ,1 ,32 , 0, -1 ,1 ,32 , 0 );// std::cout< (0,0)<< std::endl; // std::cout< (0,1)<< std::endl; //Mat img = imread("test.png", CV_LOAD_IMAGE_UNCHANGED); //创建一个名字为MyWindow的窗口来显示图片// namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);// imshow("MyWindow",img);// waitKey(0);// destroyWindow("MyWindow"); int col=0;//列数、图像宽度;对应N int row=0;// Mat out;//放大高后的图 Mat out(2*M,N,CV_8UC1,Scalar(0)); std::cout<<(int)img.at (1,1)<< std::endl; // Mat scaler;//整体放大后的图Mat scaler(2*M,2*N,CV_8UC1,Scalar(255));std::cout< << std::endl; std::cout< << std::endl; //getchar();// Mat img = imread("test.png", CV_LOAD_IMAGE_UNCHANGED); //创建一个名字为MyWindow的窗口来显示图片 for(col=0;col (row,col)= (float)img.at (1,col)*F.at (phaseNum,1)+ (float)img.at (1,col)*F.at (phaseNum,2)+ (float)img.at (2,col)*F.at (phaseNum,3)+ (float)img.at (3,col)*F.at (phaseNum,4); } else if(i+2==M) { out.at (row,col)= (float)img.at (i,col)*F.at (phaseNum,1)+ (float)img.at (i+1,col)*F.at (phaseNum,2)+ (float)img.at (i+2,col)*F.at (phaseNum,3)+ (float)img.at (i+2,col)*F.at (phaseNum,4); } else if(i+1==M||i==M) { out.at (row,col)= (float)img.at (i,col)*F.at (phaseNum,1)+ (float)img.at (i+1,col)*F.at (phaseNum,2)+ (float)img.at (i+1,col)*F.at (phaseNum,3)+ (float)img.at (i+1,col)*F.at (phaseNum,4); } else { out.at (row,col)= (float)img.at (i,col)*F.at (phaseNum,1)+ (float)img.at (i+1,col)*F.at (phaseNum,2)+ (float)img.at (i+2,col)*F.at (phaseNum,3)+ (float)img.at (i+3,col)*F.at (phaseNum,4); } } } namedWindow("MyWindow",CV_WINDOW_AUTOSIZE); imshow("MyWindow",out); waitKey(0); destroyWindow("MyWindow"); for(row=0;row<2*M;row++) { for(col=0;col<2*N;col++) { double tmp=(col-1)/N+1/(2*64); int i=floor(tmp); int phaseNum=floor((tmp-i)*64)+1; if(i==0) { scaler.at (row,col)= out.at (row,1)*F.at (phaseNum,1)+ out.at (row,1)*F.at (phaseNum,2)+ out.at (row,2)*F.at (phaseNum,3)+ out.at (row,3)*F.at (phaseNum,4); } else if(i+2==N) { scaler.at (row,col)= out.at (row,i)*F.at (phaseNum,1)+ out.at (row,i+1)*F.at (phaseNum,2)+ out.at (row,i+2)*F.at (phaseNum,3)+ out.at (row,i+2)*F.at (phaseNum,4); } else if(i+1==N||i==N) { scaler.at (row,col)= out.at (row,i)*F.at (phaseNum,1)+ out.at (row,i+1)*F.at (phaseNum,2)+ out.at (row,i+1)*F.at (phaseNum,3)+ out.at (row,i+1)*F.at (phaseNum,4); } else { scaler.at (row,col)= out.at (row,i)*F.at (phaseNum,1)+ out.at (row,i+1)*F.at (phaseNum,2)+ out.at (row,i+2)*F.at (phaseNum,3)+ out.at (row,i+3)*F.at (phaseNum,4); } } } namedWindow("MyWindow2",CV_WINDOW_AUTOSIZE); imshow("MyWindow2",scaler); waitKey(0); destroyWindow("MyWindow2"); //std::cout<< M.at (0,0)[0]<< std::endl; std::cout< << std::endl; getchar(); return 0;}