001 #include <opencv2/opencv.hpp> 002 #include <opencv2/opencv_lib.hpp> 003 004 using namespace cv; 005 006 Vec3b MyBiLinearPixel(InputArray _imgSrc, double px, double py) { 007 Mat imgSrc = _imgSrc.getMat(); 008 009 Vec3b p00, p01, p10, p11; 010 p00 = imgSrc.ptr<Vec3b>((int)py)[(int)px], p01 = imgSrc.ptr<Vec3b>((int)py)[(int)px + 1]; 011 p10 = imgSrc.ptr<Vec3b>((int)py + 1)[(int)px], p11 = imgSrc.ptr<Vec3b>((int)py + 1)[(int)px + 1]; 012 013 double r, g, b; 014 double dx = px - (int)px, dy = py - (int)py; 015 double dx1 = (1.0 - dx), dy1 = (1.0 - dy); 016 double w00 = dx1 * dy1, w01 = dx * dy1; 017 double w10 = dx1 * dy, w11 = dx * dy; 018 019 b = w00 * p00[0] + w01 * p01[0] + w10 * p10[0] + w11 * p11[0]; 020 g = w00 * p00[1] + w01 * p01[1] + w10 * p10[1] + w11 * p11[1]; 021 r = w00 * p00[2] + w01 * p01[2] + w10 * p10[2] + w11 * p11[2]; 022 023 return(Vec3b((uchar)b, (uchar)g, (uchar)r)); 024 } 025 026 void MyLogPolarImage(InputArray _imgSrc, OutputArray _imgDst, double M) { 027 Mat imgSrc = _imgSrc.getMat(); 028 029 int wx = imgSrc.cols, wy = imgSrc.rows; 030 int cx = (wx / 2), cy = (wy / 2); 031 032 _imgDst.create(wy, wx, imgSrc.type()); 033 Mat imgDst = _imgDst.getMat(); 034 035 for(int dy = 0; dy < wy; dy++) { 036 Vec3b* dstData = imgDst.ptr<Vec3b>(dy); 037 for(int dx = 0; dx < wx; dx++) { 038 double reference = exp((double)dx / M); 039 double theta = dy * 2.0 * CV_PI / wy; 040 double sx = reference * cos(theta) + cx, sy = reference * sin(theta) + cy; 041 if ((0.0 < sx) && (sx < wx - 1.0) && (0.0 < sy) && (sy < wy - 1.0)) { 042 dstData[dx] = MyBiLinearPixel(imgSrc, sx, sy); 043 } else { 044 dstData[dx] = Vec3b(0, 0, 0); 045 } 046 } 047 } 048 049 return; 050 }