Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define Xxx ixxG
- Tools::Tools()
- {
- }
- float gF(float val){
- return 1/(1+(val*val)/16);
- }
- float fF(float val){
- return exp(-val);
- }
- float NF(float x,float y){
- return sqrt(x*x+y*y);
- }
- Mat Tools::_Convolution(Mat image,Mat kernel){
- Mat dst;
- image.convertTo(image,CV_64F,1.0/255.0);
- filter2D(image, dst, -1 , kernel, Point( -1, -1 ), 0, BORDER_DEFAULT );
- image.convertTo(image,CV_8UC1,255.0);
- return dst;
- }
- Mat Tools::_DiZenzoGradient(Mat image){
- Mat dst;
- Mat dstChannel[3];
- int progressMCM;
- image.copyTo(dst);
- double ix,iy;
- Mat ixB,iyB;
- Mat ixG,iyG;
- Mat ixR,iyR;
- double g11,g12,g22;
- double lambdaPlus,lambdaMin;
- split(dst,dstChannel);
- ixB = Tools::_Convolution(dstChannel[0],Tools::_Ix());
- iyB = Tools::_Convolution(dstChannel[0],Tools::_Iy());
- ixG = Tools::_Convolution(dstChannel[1],Tools::_Ix());
- iyG = Tools::_Convolution(dstChannel[1],Tools::_Iy());
- ixR = Tools::_Convolution(dstChannel[2],Tools::_Ix());
- iyR = Tools::_Convolution(dstChannel[2],Tools::_Iy());
- Mat cM = Mat::zeros(Size(image.cols, image.rows), CV_64F);
- for(int i = 1; i < image.rows - 1; i++){
- for(int j = 1; j < image.cols - 1; j++){
- g11= pow(ixR.at<double>(i,j),2)+pow(ixG.at<double>(i,j),2)+pow(ixB.at<double>(i,j),2);
- g12= ixR.at<double>(i,j)*iyR.at<double>(i,j)+ixG.at<double>(i,j)*iyG.at<double>(i,j)+ixB.at<double>(i,j)*iyB.at<double>(i,j);
- g22= pow(iyR.at<double>(i,j),2)+pow(iyG.at<double>(i,j),2)+pow(iyB.at<double>(i,j),2);
- lambdaPlus=( g11 + g22 + sqrt( pow( (g11-g22),2 )+4*pow( g12,2 ) ) )/2;
- lambdaMin=( g11 + g22 - sqrt( pow( (g11-g22),2 )+4*pow( g12,2 ) ) )/2;
- cM.at<double>(i,j) = sqrt(lambdaPlus);
- }
- }
- cM.convertTo(cM, CV_8UC1, 255.0/1.0);
- return cM;
- }
- Mat Tools::_SapiroGradient(Mat image){
- Mat dst;
- Mat dstChannel[3];
- int progressMCM;
- image.copyTo(dst);
- double ix,iy;
- Mat ixB,iyB;
- Mat ixG,iyG;
- Mat ixR,iyR;
- double g11,g12,g22;
- double lambdaPlus,lambdaMin;
- split(dst,dstChannel);
- ixB = Tools::_Convolution(dstChannel[0],Tools::_Ix());
- iyB = Tools::_Convolution(dstChannel[0],Tools::_Iy());
- ixG = Tools::_Convolution(dstChannel[1],Tools::_Ix());
- iyG = Tools::_Convolution(dstChannel[1],Tools::_Iy());
- ixR = Tools::_Convolution(dstChannel[2],Tools::_Ix());
- iyR = Tools::_Convolution(dstChannel[2],Tools::_Iy());
- Mat cM = Mat::zeros(Size(image.cols, image.rows), CV_64F);
- for(int i = 1; i < image.rows - 1; i++){
- for(int j = 1; j < image.cols - 1; j++){
- g11= pow(ixR.at<double>(i,j),2)+pow(ixG.at<double>(i,j),2)+pow(ixB.at<double>(i,j),2);
- g12= ixR.at<double>(i,j)*iyR.at<double>(i,j)+ixG.at<double>(i,j)*iyG.at<double>(i,j)+ixB.at<double>(i,j)*iyB.at<double>(i,j);
- g22= pow(iyR.at<double>(i,j),2)+pow(iyG.at<double>(i,j),2)+pow(iyB.at<double>(i,j),2);
- lambdaPlus=( g11 + g22 + sqrt( pow( (g11-g22),2 )+4*pow( g12,2 ) ) )/2;
- lambdaMin=( g11 + g22 - sqrt( pow( (g11-g22),2 )+4*pow( g12,2 ) ) )/2;
- cM.at<double>(i,j) = sqrt(lambdaPlus-lambdaMin);
- }
- }
- cM.convertTo(cM, CV_8UC1, 255.0/1.0);
- return cM;
- }
- Mat Tools::_BlomgrenGradient(Mat image){
- Mat dst;
- Mat dstChannel[3];
- int progressMCM;
- image.copyTo(dst);
- double ix,iy;
- Mat ixB,iyB;
- Mat ixG,iyG;
- Mat ixR,iyR;
- double g11,g12,g22;
- double lambdaPlus,lambdaMin;
- split(dst,dstChannel);
- ixB = Tools::_Convolution(dstChannel[0],Tools::_Ix());
- iyB = Tools::_Convolution(dstChannel[0],Tools::_Iy());
- ixG = Tools::_Convolution(dstChannel[1],Tools::_Ix());
- iyG = Tools::_Convolution(dstChannel[1],Tools::_Iy());
- ixR = Tools::_Convolution(dstChannel[2],Tools::_Ix());
- iyR = Tools::_Convolution(dstChannel[2],Tools::_Iy());
- Mat cM = Mat::zeros(Size(image.cols, image.rows), CV_64F);
- for(int i = 1; i < image.rows - 1; i++){
- for(int j = 1; j < image.cols - 1; j++){
- g11= pow(ixR.at<double>(i,j),2)+pow(ixG.at<double>(i,j),2)+pow(ixB.at<double>(i,j),2);
- g12= ixR.at<double>(i,j)*iyR.at<double>(i,j)+ixG.at<double>(i,j)*iyG.at<double>(i,j)+ixB.at<double>(i,j)*iyB.at<double>(i,j);
- g22= pow(iyR.at<double>(i,j),2)+pow(iyG.at<double>(i,j),2)+pow(iyB.at<double>(i,j),2);
- lambdaPlus=( g11 + g22 + sqrt( pow( (g11-g22),2 )+4*pow( g12,2 ) ) )/2;
- lambdaMin=( g11 + g22 - sqrt( pow( (g11-g22),2 )+4*pow( g12,2 ) ) )/2;
- cM.at<double>(i,j) = sqrt(lambdaPlus+lambdaMin);
- }
- }
- cM.convertTo(cM, CV_8UC1, 255.0/1.0);
- return cM;
- }
- vector<Mat> Tools::_DiZenzoRestoration(Mat image,int iterations,double dt){
- vector<Mat> dst(iterations+1);
- Mat dstChannel[3];
- image.copyTo(dst.at(0));
- double A,D;
- Mat ixyB,ixxB,iyyB,ixB,iyB;
- Mat ixyG,ixxG,iyyG,ixG,iyG;
- Mat ixyR,ixxR,iyyR,ixR,iyR;
- double sum,ixx,iyy,ix,iy,ixy,c;
- Mat N;
- for(int t=0; t<iterations;t++){cout<<t<<endl;
- split(dst.at(t),dstChannel);
- N=_DiZenzoGradient(dst.at(t));
- N.convertTo(N,CV_64F,1.0/255.0);
- ixyB = Tools::_Convolution(dstChannel[0],Tools::_Ixy());
- ixxB = Tools::_Convolution(dstChannel[0],Tools::_Ixx());
- iyyB = Tools::_Convolution(dstChannel[0],Tools::_Iyy());
- ixB = Tools::_Convolution(dstChannel[0],Tools::_Ix());
- iyB = Tools::_Convolution(dstChannel[0],Tools::_Iy());
- ixyG = Tools::_Convolution(dstChannel[1],Tools::_Ixy());
- ixxG = Tools::_Convolution(dstChannel[1],Tools::_Ixx());
- iyyG = Tools::_Convolution(dstChannel[1],Tools::_Iyy());
- ixG = Tools::_Convolution(dstChannel[1],Tools::_Ix());
- iyG = Tools::_Convolution(dstChannel[1],Tools::_Iy());
- ixyR = Tools::_Convolution(dstChannel[2],Tools::_Ixy());
- ixxR = Tools::_Convolution(dstChannel[2],Tools::_Ixx());
- iyyR = Tools::_Convolution(dstChannel[2],Tools::_Iyy());
- ixR = Tools::_Convolution(dstChannel[2],Tools::_Ix());
- iyR = Tools::_Convolution(dstChannel[2],Tools::_Iy());
- dstChannel[0].convertTo(dstChannel[0],CV_64F,1.0/255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_64F,1.0/255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_64F,1.0/255.0);
- for(int i = 1; i < image.rows-1; i++){
- for(int j = 1; j < image.cols-1; j++){
- ixy = ixyB.at<double>(i,j);
- ixx = ixxB.at<double>(i,j);
- iyy = iyyB.at<double>(i,j);
- ix = ixB.at<double>(i,j);
- iy = iyB.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[0].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- ixy = ixyG.at<double>(i,j);
- ixx = ixxG.at<double>(i,j);
- iyy = iyyG.at<double>(i,j);
- ix = ixG.at<double>(i,j);
- iy = iyG.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[1].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- ixy = ixyR.at<double>(i,j);
- ixx = ixxR.at<double>(i,j);
- iyy = iyyR.at<double>(i,j);
- ix = ixR.at<double>(i,j);
- iy = iyR.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[2].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- }
- }
- dstChannel[0].convertTo(dstChannel[0],CV_8UC1,255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_8UC1,255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_8UC1,255.0);
- merge(dstChannel,3,dst.at(t));
- dst.at(t).copyTo(dst.at(t+1));
- }
- return dst;
- }
- vector<Mat> Tools::_SapiroRestoration(Mat image,int iterations,double dt){
- vector<Mat> dst(iterations+1);
- Mat dstChannel[3];
- image.copyTo(dst.at(0));
- double A,D;
- Mat ixyB,ixxB,iyyB,ixB,iyB;
- Mat ixyG,ixxG,iyyG,ixG,iyG;
- Mat ixyR,ixxR,iyyR,ixR,iyR;
- double sum,ixx,iyy,ix,iy,ixy,c;
- Mat N;
- for(int t=0; t<iterations;t++){cout<<t<<endl;
- split(dst.at(t),dstChannel);
- N=_SapiroGradient(dst.at(t));
- N.convertTo(N,CV_64F,1.0/255.0);
- ixyB = Tools::_Convolution(dstChannel[0],Tools::_Ixy());
- ixxB = Tools::_Convolution(dstChannel[0],Tools::_Ixx());
- iyyB = Tools::_Convolution(dstChannel[0],Tools::_Iyy());
- ixB = Tools::_Convolution(dstChannel[0],Tools::_Ix());
- iyB = Tools::_Convolution(dstChannel[0],Tools::_Iy());
- ixyG = Tools::_Convolution(dstChannel[1],Tools::_Ixy());
- ixxG = Tools::_Convolution(dstChannel[1],Tools::_Ixx());
- iyyG = Tools::_Convolution(dstChannel[1],Tools::_Iyy());
- ixG = Tools::_Convolution(dstChannel[1],Tools::_Ix());
- iyG = Tools::_Convolution(dstChannel[1],Tools::_Iy());
- ixyR = Tools::_Convolution(dstChannel[2],Tools::_Ixy());
- ixxR = Tools::_Convolution(dstChannel[2],Tools::_Ixx());
- iyyR = Tools::_Convolution(dstChannel[2],Tools::_Iyy());
- ixR = Tools::_Convolution(dstChannel[2],Tools::_Ix());
- iyR = Tools::_Convolution(dstChannel[2],Tools::_Iy());
- dstChannel[0].convertTo(dstChannel[0],CV_64F,1.0/255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_64F,1.0/255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_64F,1.0/255.0);
- for(int i = 1; i < image.rows-1; i++){
- for(int j = 1; j < image.cols-1; j++){
- ixy = ixyB.at<double>(i,j);
- ixx = ixxB.at<double>(i,j);
- iyy = iyyB.at<double>(i,j);
- ix = ixB.at<double>(i,j);
- iy = iyB.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[0].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- ixy = ixyG.at<double>(i,j);
- ixx = ixxG.at<double>(i,j);
- iyy = iyyG.at<double>(i,j);
- ix = ixG.at<double>(i,j);
- iy = iyG.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[1].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- ixy = ixyR.at<double>(i,j);
- ixx = ixxR.at<double>(i,j);
- iyy = iyyR.at<double>(i,j);
- ix = ixR.at<double>(i,j);
- iy = iyR.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[2].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- }
- }
- dstChannel[0].convertTo(dstChannel[0],CV_8UC1,255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_8UC1,255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_8UC1,255.0);
- merge(dstChannel,3,dst.at(t));
- dst.at(t).copyTo(dst.at(t+1));
- }
- return dst;
- }
- vector<Mat> Tools::_BlomgrenRestoration(Mat image,int iterations,double dt){
- vector<Mat> dst(iterations+1);
- Mat dstChannel[3];
- image.copyTo(dst.at(0));
- double A,D;
- Mat ixyB,ixxB,iyyB,ixB,iyB;
- Mat ixyG,ixxG,iyyG,ixG,iyG;
- Mat ixyR,ixxR,iyyR,ixR,iyR;
- double sum,ixx,iyy,ix,iy,ixy,c;
- Mat N;
- for(int t=0; t<iterations;t++){cout<<t<<endl;
- split(dst.at(t),dstChannel);
- N=_BlomgrenGradient(dst.at(t));
- N.convertTo(N,CV_64F,1.0/255.0);
- ixyB = Tools::_Convolution(dstChannel[0],Tools::_Ixy());
- ixxB = Tools::_Convolution(dstChannel[0],Tools::_Ixx());
- iyyB = Tools::_Convolution(dstChannel[0],Tools::_Iyy());
- ixB = Tools::_Convolution(dstChannel[0],Tools::_Ix());
- iyB = Tools::_Convolution(dstChannel[0],Tools::_Iy());
- ixyG = Tools::_Convolution(dstChannel[1],Tools::_Ixy());
- ixxG = Tools::_Convolution(dstChannel[1],Tools::_Ixx());
- iyyG = Tools::_Convolution(dstChannel[1],Tools::_Iyy());
- ixG = Tools::_Convolution(dstChannel[1],Tools::_Ix());
- iyG = Tools::_Convolution(dstChannel[1],Tools::_Iy());
- ixyR = Tools::_Convolution(dstChannel[2],Tools::_Ixy());
- ixxR = Tools::_Convolution(dstChannel[2],Tools::_Ixx());
- iyyR = Tools::_Convolution(dstChannel[2],Tools::_Iyy());
- ixR = Tools::_Convolution(dstChannel[2],Tools::_Ix());
- iyR = Tools::_Convolution(dstChannel[2],Tools::_Iy());
- dstChannel[0].convertTo(dstChannel[0],CV_64F,1.0/255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_64F,1.0/255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_64F,1.0/255.0);
- for(int i = 1; i < image.rows-1; i++){
- for(int j = 1; j < image.cols-1; j++){
- ixy = ixyB.at<double>(i,j);
- ixx = ixxB.at<double>(i,j);
- iyy = iyyB.at<double>(i,j);
- ix = ixB.at<double>(i,j);
- iy = iyB.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[0].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- ixy = ixyG.at<double>(i,j);
- ixx = ixxG.at<double>(i,j);
- iyy = iyyG.at<double>(i,j);
- ix = ixG.at<double>(i,j);
- iy = iyG.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[1].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- ixy = ixyR.at<double>(i,j);
- ixx = ixxR.at<double>(i,j);
- iyy = iyyR.at<double>(i,j);
- ix = ixR.at<double>(i,j);
- iy = iyR.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- c = A/D;
- dstChannel[2].at<double>(i,j) += exp(-N.at<double>(i,j))*(dt*c);
- }
- }
- dstChannel[0].convertTo(dstChannel[0],CV_8UC1,255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_8UC1,255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_8UC1,255.0);
- merge(dstChannel,3,dst.at(t));
- dst.at(t).copyTo(dst.at(t+1));
- }
- return dst;
- }
- vector<Mat> Tools::_DericheRestoration(Mat image,int iterations,double dt){
- vector<Mat> dst(iterations+1);
- Mat dstChannel[3];
- image.copyTo(dst.at(0));
- double A,D;
- Mat ixyB,ixxB,iyyB,ixB,iyB;
- Mat ixyG,ixxG,iyyG,ixG,iyG;
- Mat ixyR,ixxR,iyyR,ixR,iyR;
- double sum,ixx,iyy,ix,iy,ixy,ee,nn;
- Mat N;
- for(int t=0; t<iterations;t++){cout<<t<<endl;
- split(dst.at(t),dstChannel);
- N=_DiZenzoGradient(dst.at(t));
- N.convertTo(N,CV_64F,1.0/255.0);
- ixyB = Tools::_Convolution(dstChannel[0],Tools::_Ixy());
- ixxB = Tools::_Convolution(dstChannel[0],Tools::_Ixx());
- iyyB = Tools::_Convolution(dstChannel[0],Tools::_Iyy());
- ixB = Tools::_Convolution(dstChannel[0],Tools::_Ix());
- iyB = Tools::_Convolution(dstChannel[0],Tools::_Iy());
- ixyG = Tools::_Convolution(dstChannel[1],Tools::_Ixy());
- ixxG = Tools::_Convolution(dstChannel[1],Tools::_Ixx());
- iyyG = Tools::_Convolution(dstChannel[1],Tools::_Iyy());
- ixG = Tools::_Convolution(dstChannel[1],Tools::_Ix());
- iyG = Tools::_Convolution(dstChannel[1],Tools::_Iy());
- ixyR = Tools::_Convolution(dstChannel[2],Tools::_Ixy());
- ixxR = Tools::_Convolution(dstChannel[2],Tools::_Ixx());
- iyyR = Tools::_Convolution(dstChannel[2],Tools::_Iyy());
- ixR = Tools::_Convolution(dstChannel[2],Tools::_Ix());
- iyR = Tools::_Convolution(dstChannel[2],Tools::_Iy());
- dstChannel[0].convertTo(dstChannel[0],CV_64F,1.0/255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_64F,1.0/255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_64F,1.0/255.0);
- for(int i = 1; i < image.rows-1; i++){
- for(int j = 1; j < image.cols-1; j++){
- ixy = ixyB.at<double>(i,j);
- ixx = ixxB.at<double>(i,j);
- iyy = iyyB.at<double>(i,j);
- ix = ixB.at<double>(i,j);
- iy = iyB.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- ee = A/D;
- A = (ixx*(ix*ix)) + (2*ixy*ix*iy) + (iyy*(iy*iy));
- nn = A/D;
- dstChannel[0].at<double>(i,j) += (exp(-N.at<double>(i,j))*(dt*nn)+(dt*ee));
- ixy = ixyG.at<double>(i,j);
- ixx = ixxG.at<double>(i,j);
- iyy = iyyG.at<double>(i,j);
- ix = ixG.at<double>(i,j);
- iy = iyG.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- ee = A/D;
- A = (ixx*(ix*ix)) + (2*ixy*ix*iy) + (iyy*(iy*iy));
- nn = A/D;
- dstChannel[1].at<double>(i,j) += (exp(-N.at<double>(i,j))*(dt*nn)+(dt*ee));
- ixy = ixyR.at<double>(i,j);
- ixx = ixxR.at<double>(i,j);
- iyy = iyyR.at<double>(i,j);
- ix = ixR.at<double>(i,j);
- iy = iyR.at<double>(i,j);
- A = (ixx*(iy*iy)) - (2*ixy*ix*iy) + (iyy*(ix*ix));
- D = (ix*ix)+(iy*iy);
- ee = A/D;
- A = (ixx*(ix*ix)) + (2*ixy*ix*iy) + (iyy*(iy*iy));
- nn = A/D;
- dstChannel[2].at<double>(i,j) += (exp(-N.at<double>(i,j))*(dt*nn)+(dt*ee));
- }
- }
- dstChannel[0].convertTo(dstChannel[0],CV_8UC1,255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_8UC1,255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_8UC1,255.0);
- merge(dstChannel,3,dst.at(t));
- dst.at(t).copyTo(dst.at(t+1));
- }
- return dst;
- }
- vector<Mat> Tools::_BelfkihRestoration(Mat image,int iterations,double dt){
- vector<Mat> dst(iterations+1);
- Mat dstChannel[3];
- image.copyTo(dst.at(0));
- double A,D;
- Mat _ixyB,_ixxB,_iyyB,_ixB,_iyB;
- Mat _ixyG,_ixxG,_iyyG,_ixG,_iyG;
- Mat _ixyR,_ixxR,_iyyR,_ixR,_iyR;
- double sum,ixx,iyy,ix,iy,ixy,ee,nn;
- double ixyB,ixxB,iyyB,ixB,iyB;
- double ixyG,ixxG,iyyG,ixG,iyG;
- double ixyR,ixxR,iyyR,ixR,iyR;
- double g11,g12,g21,g22;
- double lambdaMin,lambdaMax;
- double xG2,xB2,xR2,yG2,yB2,yR2;
- double dteta_x,dteta_y,dx_s,dy_s,A2,lap;
- double dx,dy,Kval=0.0;
- double eeB,eeG,eeR;
- double nnB,nnG,nnR;
- Mat _GB,_GG,_GR;
- Mat _LBX,_LGX,_LRX;
- Mat _LBY,_LGY,_LRY;
- Mat N;
- Mat cMB = Mat::zeros(Size(image.cols, image.rows), CV_64F);
- Mat cMG = Mat::zeros(Size(image.cols, image.rows), CV_64F);
- Mat cMR = Mat::zeros(Size(image.cols, image.rows), CV_64F);
- for(int t=0; t<iterations;t++){cout<<t<<endl;
- split(dst.at(t),dstChannel);
- N=_DiZenzoGradient(dst.at(t));
- N.convertTo(N,CV_64F,1.0/255.0);
- _ixyB = Tools::_Convolution(dstChannel[0],Tools::_Ixy());
- _ixxB = Tools::_Convolution(dstChannel[0],Tools::_Ixx());
- _iyyB = Tools::_Convolution(dstChannel[0],Tools::_Iyy());
- _ixB = Tools::_Convolution(dstChannel[0],Tools::_Ix());
- _iyB = Tools::_Convolution(dstChannel[0],Tools::_Iy());
- _ixyG = Tools::_Convolution(dstChannel[1],Tools::_Ixy());
- _ixxG = Tools::_Convolution(dstChannel[1],Tools::_Ixx());
- _iyyG = Tools::_Convolution(dstChannel[1],Tools::_Iyy());
- _ixG = Tools::_Convolution(dstChannel[1],Tools::_Ix());
- _iyG = Tools::_Convolution(dstChannel[1],Tools::_Iy());
- _ixyR = Tools::_Convolution(dstChannel[2],Tools::_Ixy());
- _ixxR = Tools::_Convolution(dstChannel[2],Tools::_Ixx());
- _iyyR = Tools::_Convolution(dstChannel[2],Tools::_Iyy());
- _ixR = Tools::_Convolution(dstChannel[2],Tools::_Ix());
- _iyR = Tools::_Convolution(dstChannel[2],Tools::_Iy());
- _GB=Tools::_Convolution(dstChannel[0],Tools::_GaussianKernel(3,1.5));
- _GG=Tools::_Convolution(dstChannel[1],Tools::_GaussianKernel(3,1.5));
- _GR=Tools::_Convolution(dstChannel[2],Tools::_GaussianKernel(3,1.5));
- _LBX=Tools::_Convolution(_GB,Tools::_Ixx());
- _LBY=Tools::_Convolution(_GB,Tools::_Iyy());
- _LGX=Tools::_Convolution(_GG,Tools::_Ixx());
- _LGY=Tools::_Convolution(_GG,Tools::_Iyy());
- _LRX=Tools::_Convolution(_GR,Tools::_Ixx());
- _LRY=Tools::_Convolution(_GR,Tools::_Iyy());
- for(int i=0;i<image.rows;i++){
- for(int j=0;j<image.cols;j++){
- cMB.at<double>(i,j)=sqrt(pow(_LBX.at<double>(i,j),2)+pow(_LBX.at<double>(i,j),2));
- cMG.at<double>(i,j)=sqrt(pow(_LGX.at<double>(i,j),2)+pow(_LGX.at<double>(i,j),2));
- cMR.at<double>(i,j)=sqrt(pow(_LRX.at<double>(i,j),2)+pow(_LRX.at<double>(i,j),2));
- }
- }
- dstChannel[0].convertTo(dstChannel[0],CV_64F,1.0/255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_64F,1.0/255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_64F,1.0/255.0);
- for(int i = 1; i < image.rows-1; i++){
- for(int j = 1; j < image.cols-1; j++){
- ixyB = _ixyB.at<double>(i,j);
- ixxB = _ixxB.at<double>(i,j);
- iyyB = _iyyB.at<double>(i,j);
- ixB = _ixB.at<double>(i,j);
- iyB = _iyB.at<double>(i,j);
- A = (ixxB*(iyB*iyB)) - (2*ixyB*ixB*iyB) + (iyyB*(ixB*ixB));
- D = (ixB*ixB)+(iyB*iyB);
- eeB = A/D;
- A = (ixxB*(ixB*ixB)) + (2*ixyB*ixB*iyB) + (iyyB*(iyB*iyB));
- nnB = A/D;
- //dstChannel[0].at<double>(i,j) += (exp(-N.at<double>(i,j))*(dt*nnB)+(dt*eeB));
- ixyG = _ixyG.at<double>(i,j);
- ixxG = _ixxG.at<double>(i,j);
- iyyG = _iyyG.at<double>(i,j);
- ixG = _ixG.at<double>(i,j);
- iyG = _iyG.at<double>(i,j);
- A = (ixxG*(iyG*iyG)) - (2*ixyG*ixG*iyG) + (iyyG*(ixG*ixG));
- D = (ixG*ixG)+(iyG*iyG);
- eeG = A/D;
- A = (ixxG*(ixG*ixG)) + (2*ixyG*ixG*iyG) + (iyyG*(iyG*iyG));
- nnG = A/D;
- //dstChannel[1].at<double>(i,j) += (exp(-N.at<double>(i,j))*(dt*nnG)+(dt*eeG));
- ixyR = _ixyR.at<double>(i,j);
- ixxR = _ixxR.at<double>(i,j);
- iyyR = _iyyR.at<double>(i,j);
- ixR = _ixR.at<double>(i,j);
- iyR = _iyR.at<double>(i,j);
- A = (ixxR*(iyR*iyR)) - (2*ixyR*ixR*iyR) + (iyyR*(ixR*ixR));
- D = (ixR*ixR)+(iyR*iyR);
- eeR = A/D;
- A = (ixxR*(ixR*ixR)) + (2*ixyR*ixR*iyR) + (iyyR*(iyR*iyR));
- nnR = A/D;
- //dstChannel[2].at<double>(i,j) += (exp(-N.at<double>(i,j))*(dt*nnR)+(dt*eeR));
- g11=ixR*ixR+ixG*ixG+ixB*ixB;
- g22=iyR*iyR+iyG*iyG+iyB*iyB;
- g12=ixR*iyR+ixG*iyG+ixB*iyB;
- A2=A*A;
- lap=A2 + 4*g12*g12;
- if(lap==0)lap=1;
- lambdaMax=(g11 + g22 + sqrt(A2 + 4*g12*g12))/2;
- A=ixB*ixB - iyB*iyB + ixR*ixR - iyR*iyR + ixG*ixG - iyG*iyG;
- dteta_x=(A*ixB*ixyB + A*ixxB*iyB - 2*ixG*ixyG*pow(iyG,2) + 2*pow(ixB,2)*ixxB*iyB +
- 2*ixB*ixyB*pow(iyB,2) - 2*ixB*iyB*ixR*ixxR + A*ixR*ixyR - 2*ixB*ixxB*ixR*iyR +
- 2*ixyB*iyB*ixR*iyR + A*ixxR*iyR - 2*pow(ixR,2)*ixxR*iyR + 2*ixB*iyB*ixyR*iyR +
- 2*ixR*ixyR*pow(iyR,2) - 2*ixB*iyB*ixG*ixxG - 2*ixR*iyR*ixG*ixxG + A*ixG*ixyG - 2*ixB*ixxB*ixG*iyG +
- 2*ixR*ixxR*ixG*iyG + 2*ixyB*iyB*ixG*iyG - A*Xxx*iyG - 2*pow(ixG,2)*ixxG*iyG + 2*ixyR*iyR*ixG*iyG +
- 2*ixB*iyB*ixyG*iyG + 2*ixR*iyR*ixyG*iyG) / (pow(A,2) + 4*pow(ixB*iyB + ixR*iyR + ixG*iyG, 2));
- dteta_y=(A*ixyB*iyB - 2*ixB*ixyB*iyB + A*ixB*iyyB + 2*ixB*iyB*iyB*iyyB - 2*ixB*iyB*ixR*ixyR - 2*ixB*ixyB*ixR*iyR + //??
- 2*iyB*iyyB*ixR*iyR + A*ixyR*iyB - 2*ixR*ixR*ixyR*iyR + 2*ixB*iyB*iyR*iyyR + 2*ixR*iyR*iyR*iyyR - 2*ixB*iyB*ixG*iyG -
- 2*ixR*iyR*ixG*ixyG - 2*ixB*ixyB*ixG*iyG + 2*iyB*iyyB*ixG*iyG - 2*ixR*ixyR*ixyR*ixG*iyG + 2*iyR*iyyR*ixG*iyG + A*ixyG*iyG -
- 2*ixG*ixG*ixyG*iyG + A*ixG*iyyG + 2*ixB*iyB*iyG*iyyG + 2*ixR*iyR*ixG*iyyG + 2*ixG*iyG*iyG*iyyG + //??
- 2*ixB*ixyB*iyB - 2*ixB*ixyB*iyB) / (pow(A,2) + 4*pow(ixB*iyB + ixR*iyR + ixG*iyG, 2));
- dx_s=1/(sqrt(pow(g12,2) + pow(g11-lambdaMax,2)) * (g11 - lambdaMax));
- dy_s=1/(sqrt(pow(g12,2) + pow(g11*lambdaMax,2)) * g12);
- Kval = dteta_x * dx_s + dteta_y * dy_s;
- dstChannel[0].at<double>(i,j) += (gF(cMB.at<double>(i,j)) * (nnB) +gF(Kval)* (eeB))*dt;
- dstChannel[1].at<double>(i,j) += (gF(cMG.at<double>(i,j)) * (nnG) +gF(Kval)* (eeG))*dt;
- dstChannel[2].at<double>(i,j) += (gF(cMR.at<double>(i,j)) * (nnR) +gF(Kval)* (eeR))*dt;
- }
- }
- dstChannel[0].convertTo(dstChannel[0],CV_8UC1,255.0);
- dstChannel[1].convertTo(dstChannel[1],CV_8UC1,255.0);
- dstChannel[2].convertTo(dstChannel[2],CV_8UC1,255.0);
- merge(dstChannel,3,dst.at(t));
- dst.at(t).copyTo(dst.at(t+1));
- }
- return dst;
- }
- double Tools::gaussianOp(int x,int y,double sigma){
- return ( (1/(2*M_PI*pow(sigma,2))) * exp(-(pow(x,2)+pow(y,2)/(2*pow(sigma,2))))) ;
- }
- Mat Tools::_GaussianKernel(int size,double sigma){
- Mat gkernel= Mat(size,size,CV_64F);
- double sumNorm=0;
- for(int i=0;i<size;i++){
- for(int j=0;j<size;j++){
- gkernel.at<double>(i,j)=gaussianOp(i-size/2,j-size/2,sigma);
- sumNorm+=gkernel.at<double>(i,j);
- }
- }
- for(int i=0;i<size;i++){
- for(int j=0;j<size;j++){
- gkernel.at<double>(i,j)/=sumNorm;
- }
- }
- return gkernel;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement