Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <opencv2/core/core.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <math.h>
- #include <complex>
- using namespace std;
- using namespace cv;
- void wipe(Mat &image)
- {
- int i = image.cols;
- int j = image.rows; int k; int l;
- for(k=0;k<j;k++)
- {
- for(l=0;l<i;l++)
- {
- image.at<Vec3b>(k,l)[0] = 0;//image1.at<Vec3b>(k,l)[0] + image2.at<Vec3b>(k,l)[0];
- image.at<Vec3b>(k,l)[1] = 0;//image1.at<Vec3b>(k,l)[1] - image2.at<Vec3b>(k,l)[1];
- image.at<Vec3b>(k,l)[2] = 0;//image1.at<Vec3b>(k,l)[2] + image2.at<Vec3b>(k,l)[2];
- }
- }
- }
- void move_to_centre(Mat &input_image, Mat &target_image, int* row_start, int* col_start)
- {
- //Declaration of variables
- int input_x = input_image.cols;
- int input_y = input_image.rows;
- int target_x = target_image.cols;
- int target_y = target_image.rows;
- int input_row = 0; int input_col=0;
- int target_row = 0; int target_col = (target_y/2) - input_y;
- //The next two lines of code return the starting position of the
- //image to be transformed by our complex function.
- *row_start = target_y/2 - input_y;
- *col_start = target_x/2;
- cout<<"From inside the function: \n";
- cout<<"The row_start value is: " << target_y/2 - input_y<<" \n ";
- cout<<"The col_start value is: " << target_x/2 << "\n";
- //Loop that moves the image to be transformed to the centre of a temporary image of the same dimensions as
- //the result image. This makes it easier to perform the transformation.
- for(input_row=0, target_row=target_y/2 - input_y; input_row<input_y; input_row++, target_row++ )
- {
- for(input_col=0, target_col=target_x/2; input_col<input_x; input_col++, target_col++)
- {
- target_image.at<Vec3b>(target_row,target_col)[0] = input_image.at<Vec3b>(input_row,input_col)[0];
- target_image.at<Vec3b>(target_row,target_col)[1] = input_image.at<Vec3b>(input_row,input_col)[1];
- target_image.at<Vec3b>(target_row,target_col)[2] = input_image.at<Vec3b>(input_row,input_col)[2];
- }
- }
- }
- int main(int argc, char** argv)
- {
- Mat image1 = imread(argv[1], 1);
- Mat image2 = imread(argv[2], 1);
- Mat result;
- image1.copyTo(result);
- //int i = image2.cols;
- //int j = image2.rows;
- int k; int l;
- complex<double> one(1,0);
- complex<double> rot(0.4,0);
- complex<double> trans(400, 0);
- complex<double> coord_transform(-(image1.cols)/2, (image1.rows)/2); //This is the coordinate transformation that superimposes axes at the centre of the image.
- complex<double> dom1(0,0); //First domain
- complex<double> dom2(0,0); //After coord_stransform
- complex<int> rang(0,0); // Final image coordinates
- complex<double> rang_inter(0,0); //image coords in the transformed system.
- int row_start=0; int col_start=0; //Starting positions of image
- wipe(result);
- wipe(image1);
- //This function moves the image to be transformed to the centre of a temporary image of same dimensions as the result.
- move_to_centre(image2, image1, &row_start, &col_start);
- cout<<"\n\nFrom outside the function: \n";
- cout<<"The row_start value is: " << row_start <<" \n ";
- cout<<"The col_start value is: " << col_start << "\n";
- k = 28; l = 960;
- cout<<"\n";
- imag(dom1) = -k; real(dom2) = l;
- cout<<"Step 1: "<<dom1<<"\n";
- dom2 = dom1 + coord_transform;
- cout<<"Step 2:"<<dom2<<"\n";
- rang_inter = dom2;
- cout<<"Step 3: "<<rang_inter<<"\n";
- rang = rang_inter - coord_transform;
- cout<<"Step 3: "<< rang<<"\n";
- imag(rang) = -1*imag(rang);
- cout<<"Step 4:"<<rang<<"\n";
- for(k = row_start; k < row_start + image2.rows; k++)
- {
- for(l = col_start; l < col_start + image2.cols; l++)
- {
- imag(dom1) = -k; real(dom1) = l;
- dom2 = dom1 + coord_transform;
- //Complex transforms. Uncomment the one you want to apply transform.
- rang_inter = (1/abs(dom2))*dom2*dom2; //w=z**2 transform
- //rang_inter = (1/exp(real(dom2)))*exp(dom2);//exponential
- //rang_inter = (one/dom2)*abs(dom2); //Joujouwski transform
- rang = rang_inter - coord_transform;
- imag(rang) = -1*imag(rang);
- //cout<<rang;
- if((imag(rang)<result.rows)&&(real(rang)<result.cols)&&(imag(rang)>0)&&(real(rang)>0))
- {
- result.at<Vec3b>(imag(rang),real(rang))[0] = image1.at<Vec3b>(k, l)[0];//image1.at<Vec3b>(k,l)[0] + image2.at<Vec3b>(k,l)[0];
- result.at<Vec3b>(imag(rang),real(rang))[1] = image1.at<Vec3b>(k, l)[1];//image1.at<Vec3b>(k,l)[1] - image2.at<Vec3b>(k,l)[1];
- result.at<Vec3b>(imag(rang),real(rang))[2] = image1.at<Vec3b>(k, l)[2];//image1.at<Vec3b>(k,l)[2] + image2.at<Vec3b>(k,l)[2];
- }
- }
- }
- namedWindow(argv[1]);
- namedWindow(argv[2]);
- namedWindow("Result");
- imshow(argv[1], image1);
- imshow(argv[2], image2);
- imshow("Result", result);
- imwrite("Result.png",result);
- waitKey(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement