45 #include <Eigen/Dense>
47 #include <opencv2/opencv.hpp>
48 #include <glog/logging.h>
104 Eigen::MatrixXf &noisy_image);
111 static void addSaltPepper(
const Eigen::MatrixXf &image,
float p,
112 Eigen::MatrixXf &noisy_image);
124 static float computePSNR(
const Eigen::MatrixXf &image,
125 const Eigen::MatrixXf &denoised_image,
float range = 1);
143 float sigma,
float lambda);
176 float epsilon,
float lambda);
183 static float g_absoluteUnary(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0);
192 Eigen::MatrixXf &prox_f_x,
float alpha);
199 static float g_squaredUnary(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0);
208 Eigen::MatrixXf &prox_f_x,
float alpha);
225 static float f(
const Eigen::MatrixXf &x,
float epsilon);
232 static void df(
const Eigen::MatrixXf &x, Eigen::MatrixXf &df_x,
243 static float g(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0,
244 float Cp,
float Cm,
float lambda);
256 static void prox_g(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0,
257 Eigen::MatrixXf &prox_g_x,
float Cp,
float Cm,
float lambda,
268 static float g_absolute(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &X_0,
269 float Cp,
float Cm,
float lambda);
281 static void prox_g_absolute(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0,
282 Eigen::MatrixXf &prox_g_x,
float Cp,
float Cm,
float lambda,
289 static float Cp(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0);
295 static float Cm(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0);
311 static float f(
const Eigen::MatrixXf &x,
float epsilon);
318 static void df(
const Eigen::MatrixXf &x, Eigen::MatrixXf &df_x,
329 static float g(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0,
330 const Eigen::Vector3f &
Cp,
const Eigen::Vector3f &
Cm,
float lambda);
342 static void prox_g(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0,
343 Eigen::MatrixXf &prox_g_x,
const Eigen::Vector3f &Cp,
344 const Eigen::Vector3f &Cm,
float lambda,
float alpha);
354 static float g_absolute(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &X_0,
355 const Eigen::Vector3f &Cp,
const Eigen::Vector3f &Cm,
float lambda);
367 static void prox_g_absolute(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0,
368 Eigen::MatrixXf &prox_g_x,
const Eigen::Vector3f &Cp,
const Eigen::Vector3f &Cm,
369 float lambda,
float alpha);
376 static void Cp(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0, Eigen::Vector3f &Cp);
383 static void Cm(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &x_0, Eigen::Vector3f &Cm);
398 static float f(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &A,
399 const Eigen::MatrixXf &y,
float lambda);
406 static void df(
const Eigen::MatrixXf &x,
const Eigen::MatrixXf &A,
407 const Eigen::MatrixXf &y, Eigen::MatrixXf &df_x,
float lambda);
417 static float g(
const Eigen::MatrixXf &x);
429 static void prox_g(
const Eigen::MatrixXf &x, Eigen::MatrixXf &prox_g_x,
440 image.create(matrix.rows(), matrix.cols(), CV_32FC1);
442 for (
int i = 0; i < image.rows; i++)
444 for (
int j = 0; j < image.cols; j++)
446 image.at<
float>(i, j) = matrix(i, j);
457 LOG_IF(FATAL, image.type() != CV_32FC1) <<
"Invalid image type.";
458 LOG_IF(FATAL, image.channels() != 1) <<
"Only one channel supported, use convertOpenCVToEigen_Color instead!";
460 matrix = Eigen::MatrixXf(image.rows, image.cols);
462 for (
int i = 0; i < image.rows; i++)
464 for (
int j = 0; j < image.cols; j++)
466 matrix(i, j) = image.at<
float>(i, j);
477 LOG_IF(FATAL, matrix.rows()%3 != 0) <<
"Eigen matrix expected to encode a color OpenCV matrix, i.e. number of rows needs to be divisible by three!";
479 image.create(matrix.rows()/3, matrix.cols(), CV_32FC3);
481 for (
int i = 0; i < image.rows; i++)
483 for (
int j = 0; j < image.cols; j++)
485 image.at<cv::Vec3f>(i, j)[0] = matrix(i, j);
486 image.at<cv::Vec3f>(i, j)[1] = matrix(image.rows + i, j);
487 image.at<cv::Vec3f>(i, j)[2] = matrix(2*image.rows + i, j);
498 LOG_IF(FATAL, image.type() != CV_32FC3) <<
"Invalid image type.";
499 LOG_IF(FATAL, image.channels() != 3) <<
"Only three channels supported, use convertOpenCVToEigen instead!";
501 matrix = Eigen::MatrixXf(3*image.rows, image.cols);
503 for (
int i = 0; i < image.rows; i++)
505 for (
int j = 0; j < image.cols; j++)
507 matrix(i, j) = image.at<cv::Vec3f>(i, j)[0];
508 matrix(image.rows + i, j) = image.at<cv::Vec3f>(i, j)[1];
509 matrix(2*image.rows + i, j) = image.at<cv::Vec3f>(i, j)[2];
519 float sigma, Eigen::MatrixXf &noisy_image)
521 std::random_device random;
522 std::mt19937 generator(random());
523 std::normal_distribution<float> gaussian(0, sigma);
525 noisy_image = Eigen::MatrixXf::Zero(image.rows(), image.cols());
526 for (
int i = 0; i < image.rows(); i++)
528 for (
int j = 0; j < image.cols(); j++)
530 noisy_image(i, j) = image(i, j) + gaussian(generator);
540 float p, Eigen::MatrixXf &noisy_image)
550 const Eigen::MatrixXf &denoised_image,
float range)
552 LOG_IF(FATAL, image.rows() != denoised_image.rows() || image.cols() != denoised_image.cols())
553 <<
"Image dimensions do not match!";
554 LOG_IF(FATAL, image.rows() == 0 || image.cols() == 0)
560 for (
int i = 0; i < image.rows(); i++)
562 for (
int j = 0; j < image.cols(); j++)
564 psnr += (image(i, j) - denoised_image(i, j))*(image(i, j) - denoised_image(i, j));
568 psnr /= image.rows()*image.cols();
569 psnr = 10*std::log(range/psnr)/std::log(10);
578 float rho(
float z,
float sigma)
580 return std::log(1.f + 1.f/2.f*(z*z)/(sigma*sigma));
587 for (
int i = 0; i < x.rows(); i++)
589 for (
int j = 0; j < x.cols(); j++)
593 f += lambda*rho(x(i, j) - x(i - 1, j), sigma);
598 f += lambda*rho(x(i, j) - x(i, j - 1), sigma);
610 float drho(
float z,
float sigma)
612 return 1.f/(1.f + 1.f/2.f*(z*z)/(sigma*sigma))*(z/(sigma*sigma));
616 float sigma,
float lambda)
618 df_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
620 for (
int i = 0; i < x.rows(); i++)
622 for (
int j = 0; j < x.cols(); j++)
626 df_x(i, j) += lambda*drho(x(i, j) - x(i - 1, j), sigma);
631 df_x(i, j) += lambda*drho(x(i, j) - x(i, j - 1), sigma);
634 if (i < x.rows() - 1)
636 df_x(i, j) -= lambda*drho(x(i + 1, j) - x(i, j), sigma);
639 if (j < x.cols() - 1)
641 df_x(i, j) -= lambda*drho(x(i, j + 1) - x(i, j), sigma);
655 for (
int i = 0; i < x.rows(); i++)
657 for (
int j = 0; j < x.cols(); j++)
661 f += lambda*(x(i, j) - x(i - 1, j))*(x(i, j) - x(i - 1, j));
666 f += lambda*(x(i, j) - x(i, j - 1))*(x(i, j) - x(i, j - 1));
681 df_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
683 for (
int i = 0; i < x.rows(); i++)
685 for (
int j = 0; j < x.cols(); j++)
689 df_x(i, j) += lambda*2*(x(i, j) - x(i - 1, j));
694 df_x(i, j) += lambda*2*(x(i, j) - x(i, j - 1));
697 if (i < x.rows() - 1)
699 df_x(i, j) -= lambda*2*(x(i + 1, j) - x(i, j));
702 if (j < x.cols() - 1)
704 df_x(i, j) -= lambda*2*(x(i, j + 1) - x(i, j));
718 for (
int i = 0; i < x.rows(); i++)
720 for (
int j = 0; j < x.cols(); j++)
722 g += std::abs(x(i, j) - x_0(i, j));
734 template <
typename T>
736 return (T(0) < val) - (val < T(0));
740 Eigen::MatrixXf &prox_g_x,
float alpha)
742 prox_g_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
744 for (
int i = 0; i < x.rows(); i++)
746 for (
int j = 0; j < x.cols(); j++)
748 prox_g_x(i, j) = std::max(0.f, std::abs(x(i, j) - x_0(i, j)) - alpha)*sign(x(i, j) - x_0(i, j)) + x_0(i, j);
761 for (
int i = 0; i < x.rows(); i++)
763 for (
int j = 0; j < x.cols(); j++)
765 g += (x(i, j) - x_0(i, j))*(x(i, j) - x_0(i, j));
777 Eigen::MatrixXf &prox_g_x,
float alpha)
779 prox_g_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
781 for (
int i = 0; i < x.rows(); i++)
783 for (
int j = 0; j < x.cols(); j++)
785 prox_g_x(i, j) = (x(i, j) + alpha*x_0(i, j))/(1 + alpha);
798 for (
int i = 0; i < x.rows(); i++)
800 for (
int j = 0; j < x.cols(); j++)
804 f_x += epsilon*(x(i - 1, j) - x(i, j))*(x(i - 1, j) - x(i, j));
809 f_x += epsilon*(x(i, j - 1) - x(i, j))*(x(i, j - 1) - x(i, j));
812 f_x += (1 - x(i, j)*x(i, j))*(1 - x(i, j)*x(i, j))/epsilon;
826 df_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
828 for (
int i = 0; i < x.rows(); i++)
830 for (
int j = 0; j < x.cols(); j++)
832 df_x(i, j) = - 4*(1 - x(i, j)*x(i, j))*x(i, j)/epsilon;
836 df_x(i, j) -= 2*epsilon*(x(i - 1, j) - x(i, j));
841 df_x(i, j) -= 2*epsilon*(x(i, j - 1) - x(i, j));
844 if (i < x.rows() - 1)
846 df_x(i, j) += 2*epsilon*(x(i, j) - x(i + 1, j));
849 if (j < x.cols() - 1)
851 df_x(i, j) += 2*epsilon*(x(i, j) - x(i, j + 1));
862 float Cp,
float Cm,
float lambda)
866 for (
int i = 0; i < x.rows(); i++)
868 for (
int j = 0; j < x.cols(); j++)
870 g_x += (1 + x(i, j))*(1 + x(i, j))*(x_0(i, j) - Cp)*(x_0(i, j) - Cp)/4
871 + (1 - x(i, j))*(1 - x(i, j))*(x_0(i, j) - Cm)*(x_0(i, j) - Cm)/4;
883 Eigen::MatrixXf &prox_g_x,
float Cp,
float Cm,
float lambda,
float alpha)
885 prox_g_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
887 for (
int i = 0; i < x.rows(); i++)
889 for (
int j = 0; j < x.cols(); j++)
891 float cp = (x_0(i, j) - Cp)*(x_0(i, j) - Cp);
892 float cm = (x_0(i, j) - Cm)*(x_0(i, j) - Cm);
894 prox_g_x(i, j) = (x(i, j) - lambda*alpha*cp/2 + lambda*alpha*cm/2)
895 /(1 + lambda*alpha*cp/2 + lambda*alpha*cm/2);
905 float Cp,
float Cm,
float lambda)
909 for (
int i = 0; i < x.rows(); i++)
911 for (
int j = 0; j < x.cols(); j++)
913 float cp = std::abs(x_0(i, j) - Cp);
914 float cm = std::abs(x_0(i, j) - Cm);
916 g_x += std::abs(1 + x(i, j))*cp + std::abs(1 - x(i, j))*cm;
928 Eigen::MatrixXf &prox_g_x,
float Cp,
float Cm,
float lambda,
float alpha)
930 prox_g_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
932 for (
int i = 0; i < x.rows(); i++)
934 for (
int j = 0; j < x.cols(); j++)
936 float cp = alpha*lambda*std::abs(x_0(i, j) - Cp);
937 float cm = alpha*lambda*std::abs(x_0(i, j) - Cm);
939 if (x(i, j) > 1 + (cp + cm))
941 prox_g_x(i, j) = -(cp + cm) + x(i, j);
943 else if (x(i, j) >= 1 + (cp - cm) && x(i, j) <= 1 + (cp + cm))
947 else if (x(i, j) > -1 + (cp - cm) && x(i, j) < 1 + (cp - cm))
949 prox_g_x(i, j) = (-cp + cm) + x(i, j);
951 else if (x(i, j) >= -1 - (cp + cm) && x(i, j) <= -1 + (cp - cm))
957 LOG_IF(FATAL, x(i, j) >= -1 - (cp + cm)) <<
"Invalid case in PhaseField::prox_g_absolute!";
958 prox_g_x(i, j) = (cp + cm) + x(i, j);
975 for (
int i = 0; i < x.rows(); i++)
977 for (
int j = 0; j < x.cols(); j++)
981 Cp_nom += (1 + x(i, j))*(1 + x(i, j))*x_0(i, j);
982 Cp_denom += (1 + x(i, j))*(1 + x(i, j));
1004 for (
int i = 0; i < x.rows(); i++)
1006 for (
int j = 0; j < x.cols(); j++)
1010 Cm_nom += (1 - x(i, j))*(1 - x(i, j))*x_0(i, j);
1011 Cm_denom += (1 - x(i, j))*(1 - x(i, j));
1032 for (
int i = 0; i < x.rows(); i++)
1034 for (
int j = 0; j < x.cols(); j++)
1038 f_x += epsilon*(x(i - 1, j) - x(i, j))*(x(i - 1, j) - x(i, j));
1043 f_x += epsilon*(x(i, j - 1) - x(i, j))*(x(i, j - 1) - x(i, j));
1046 f_x += (1 - x(i, j)*x(i, j))*(1 - x(i, j)*x(i, j))/epsilon;
1060 df_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
1062 for (
int i = 0; i < x.rows(); i++)
1064 for (
int j = 0; j < x.cols(); j++)
1066 df_x(i, j) = - 4*(1 - x(i, j)*x(i, j))*x(i, j)/epsilon;
1070 df_x(i, j) -= 2*epsilon*(x(i - 1, j) - x(i, j));
1075 df_x(i, j) -= 2*epsilon*(x(i, j - 1) - x(i, j));
1078 if (i < x.rows() - 1)
1080 df_x(i, j) += 2*epsilon*(x(i, j) - x(i + 1, j));
1083 if (j < x.cols() - 1)
1085 df_x(i, j) += 2*epsilon*(x(i, j) - x(i, j + 1));
1096 const Eigen::Vector3f &Cp,
const Eigen::Vector3f &Cm,
float lambda)
1100 for (
int i = 0; i < x.rows(); i++)
1102 for (
int j = 0; j < x.cols(); j++)
1104 float cp = (x_0(i, j) - Cp(0, 0))*(x_0(i, j) - Cp(0, 0))
1105 + (x_0(x.rows() + i, j) - Cp(1, 0))*(x_0(x.rows() + i, j) - Cp(1, 0))
1106 + (x_0(2*x.rows() + i, j) - Cp(2, 0))*(x_0(2*x.rows() + i, j) - Cp(2, 0));
1109 float cm = (x_0(i, j) - Cm(0, 0))*(x_0(i, j) - Cm(0, 0))
1110 + (x_0(x.rows() + i, j) - Cm(1, 0))*(x_0(x.rows() + i, j) - Cm(1, 0))
1111 + (x_0(2*x.rows() + i, j) - Cm(2, 0))*(x_0(2*x.rows() + i, j) - Cm(2, 0));
1114 g_x += (1 + x(i, j))*(1 + x(i, j))*cp/4
1115 + (1 - x(i, j))*(1 - x(i, j))*cm/4;
1127 Eigen::MatrixXf &prox_g_x,
const Eigen::Vector3f &Cp,
const Eigen::Vector3f &Cm,
float lambda,
float alpha)
1129 prox_g_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
1131 for (
int i = 0; i < x.rows(); i++)
1133 for (
int j = 0; j < x.cols(); j++)
1135 float cp = (x_0(i, j) - Cp(0, 0))*(x_0(i, j) - Cp(0, 0))
1136 + (x_0(x.rows() + i, j) - Cp(1, 0))*(x_0(x.rows() + i, j) - Cp(1, 0))
1137 + (x_0(2*x.rows() + i, j) - Cp(2, 0))*(x_0(2*x.rows() + i, j) - Cp(2, 0));
1140 float cm = (x_0(i, j) - Cm(0, 0))*(x_0(i, j) - Cm(0, 0))
1141 + (x_0(x.rows() + i, j) - Cm(1, 0))*(x_0(x.rows() + i, j) - Cm(1, 0))
1142 + (x_0(2*x.rows() + i, j) - Cm(2, 0))*(x_0(2*x.rows() + i, j) - Cm(2, 0));
1145 prox_g_x(i, j) = (x(i, j) - lambda*alpha*cp/2 + lambda*alpha*cm/2)
1146 /(1 + lambda*alpha*cp/2 + lambda*alpha*cm/2);
1156 const Eigen::Vector3f &Cp,
const Eigen::Vector3f &Cm,
float lambda)
1160 for (
int i = 0; i < x.rows(); i++)
1162 for (
int j = 0; j < x.cols(); j++)
1164 float cp = std::abs(x_0(i, j) - Cp(0, 0))
1165 + std::abs(x_0(x.rows() + i, j) - Cp(1, 0))
1166 + std::abs(x_0(2*x.rows() + i, j) - Cp(2, 0));
1168 float cm = std::abs(x_0(i, j) - Cm(0, 0))
1169 + std::abs(x_0(x.rows() + i, j) - Cm(1, 0))
1170 + std::abs(x_0(2*x.rows() + i, j) - Cm(2, 0));
1172 g_x += std::abs(1 + x(i, j))*cp + std::abs(1 - x(i, j))*cm;
1184 Eigen::MatrixXf &prox_g_x,
const Eigen::Vector3f &Cp,
const Eigen::Vector3f &Cm,
1185 float lambda,
float alpha)
1187 prox_g_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
1189 for (
int i = 0; i < x.rows(); i++)
1191 for (
int j = 0; j < x.cols(); j++)
1193 float cp = std::abs(x_0(i, j) - Cp(0, 0))
1194 + std::abs(x_0(x.rows() + i, j) - Cp(1, 0))
1195 + std::abs(x_0(2*x.rows() + i, j) - Cp(2, 0));
1198 float cm = std::abs(x_0(i, j) - Cm(0, 0))
1199 + std::abs(x_0(x.rows() + i, j) - Cm(1, 0))
1200 + std::abs(x_0(2*x.rows() + i, j) - Cm(2, 0));
1203 if (x(i, j) > 1 + (cp + cm))
1205 prox_g_x(i, j) = -(cp + cm) + x(i, j);
1207 else if (x(i, j) >= 1 + (cp - cm) && x(i, j) <= 1 + (cp + cm))
1211 else if (x(i, j) > -1 + (cp - cm) && x(i, j) < 1 + (cp - cm))
1213 prox_g_x(i, j) = (-cp + cm) + x(i, j);
1215 else if (x(i, j) >= -1 - (cp + cm) && x(i, j) <= -1 + (cp - cm))
1217 prox_g_x(i, j) = -1;
1221 LOG_IF(FATAL, x(i, j) >= -1 - (cp + cm)) <<
"Invalid case in PhaseField::prox_g_absolute!";
1222 prox_g_x(i, j) = (cp + cm) + x(i, j);
1235 Eigen::Vector3f &Cp)
1237 Eigen::Vector3f Cp_nom = Eigen::Vector3f::Zero();
1240 for (
int i = 0; i < x.rows(); i++)
1242 for (
int j = 0; j < x.cols(); j++)
1246 Cp_nom(0, 0) += (1 + x(i, j))*(1 + x(i, j))*x_0(i, j);
1247 Cp_nom(1, 0) += (1 + x(i, j))*(1 + x(i, j))*x_0(x.rows() + i, j);
1248 Cp_nom(2, 0) += (1 + x(i, j))*(1 + x(i, j))*x_0(2*x.rows() + i, j);
1250 Cp_denom += (1 + x(i, j))*(1 + x(i, j));
1257 Cp_nom(0, 0) /= Cp_denom;
1258 Cp_nom(1, 0) /= Cp_denom;
1259 Cp_nom(2, 0) /= Cp_denom;
1270 Eigen::Vector3f &Cm)
1272 Eigen::Vector3f Cm_nom = Eigen::Vector3f::Zero();
1275 for (
int i = 0; i < x.rows(); i++)
1277 for (
int j = 0; j < x.cols(); j++)
1281 Cm_nom(0, 0) += (1 - x(i, j))*(1 - x(i, j))*x_0(i, j);
1282 Cm_nom(1, 0) += (1 - x(i, j))*(1 - x(i, j))*x_0(x.rows() + i, j);
1283 Cm_nom(2, 0) += (1 - x(i, j))*(1 - x(i, j))*x_0(2*x.rows() + i, j);
1285 Cm_denom += (1 - x(i, j))*(1 - x(i, j));
1292 Cm_nom(0, 0) /= Cm_denom;
1293 Cm_nom(1, 0) /= Cm_denom;
1294 Cm_nom(2, 0) /= Cm_denom;
1305 const Eigen::MatrixXf &y,
float lambda)
1307 Eigen::MatrixXf y_diff = A*x - y;
1308 return 1.f/lambda*0.5f*y_diff.squaredNorm();
1316 const Eigen::MatrixXf &y, Eigen::MatrixXf &df_x,
float lambda)
1318 df_x = 1.f/lambda*((A.transpose()*A*x) - A.transpose()*y);
1327 return x.lpNorm<1>();
1335 Eigen::MatrixXf &prox_g_x,
float alpha)
1337 prox_g_x = Eigen::MatrixXf::Zero(x.rows(), x.cols());
1339 for (
int i = 0; i < x.rows(); i++)
1341 for (
int j = 0; j < x.cols(); j++)
1343 if (x(i, j) >= alpha)
1345 prox_g_x(i, j) = x(i, j) - alpha;
1347 else if (std::abs(x(i, j)) < alpha)
1353 prox_g_x(i, j) = x(i, j) + alpha;
static float computePSNR(const Eigen::MatrixXf &image, const Eigen::MatrixXf &denoised_image, float range=1)
Compute PSNR to evaluate denoising applications.
Definition: functionals.h:549
static void prox_g_absolute(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, Eigen::MatrixXf &prox_g_x, float Cp, float Cm, float lambda, float alpha)
Proximal map of g_absolute.
Definition: functionals.h:927
static void df(const Eigen::MatrixXf &x, Eigen::MatrixXf &df_x, float epsilon)
Derivative of f.
Definition: functionals.h:823
static void df_lorentzianPairwise(const Eigen::MatrixXf &x, Eigen::MatrixXf &df_x, float sigma, float lambda)
Derivative of Lorentzian pairwise term.
Definition: functionals.h:615
static void prox_g(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, Eigen::MatrixXf &prox_g_x, const Eigen::Vector3f &Cp, const Eigen::Vector3f &Cm, float lambda, float alpha)
Proximal map of g.
Definition: functionals.h:1126
static void Cp(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, Eigen::Vector3f &Cp)
Compute Cp from the given labels x and the image x_0.
Definition: functionals.h:1234
static float g_absolute(const Eigen::MatrixXf &x, const Eigen::MatrixXf &X_0, float Cp, float Cm, float lambda)
Non-differentiable but convex part: |1 +- z| |x_0 + Cpm| dx.
Definition: functionals.h:904
static void addSaltPepper(const Eigen::MatrixXf &image, float p, Eigen::MatrixXf &noisy_image)
Add salt and pepper noise.
Definition: functionals.h:539
static void prox_g(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, Eigen::MatrixXf &prox_g_x, float Cp, float Cm, float lambda, float alpha)
Proximal map of g.
Definition: functionals.h:882
Two Phase-Field for color image segmentation, see [1]; adapted to color. [1] Shen. Gamma-Convergence Approximation to Piecewise Constant Mumford-Shah Segmentation. International Conference on Advanced Concepts of Intelligent Vision Systems, 2005.
Definition: functionals.h:303
static void Cm(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, Eigen::Vector3f &Cm)
Compute Cp::m from the given labels x and the image x_0.
Definition: functionals.h:1269
static void addGaussianAdditive(const Eigen::MatrixXf &image, float sigma, Eigen::MatrixXf &noisy_image)
Add additive Gaussian noise.
Definition: functionals.h:518
static void convertEigenToOpenCV(const Eigen::MatrixXf &eigen, cv::Mat &opencv)
Convert Eigen matrix to OpenCV matrix.
Definition: functionals.h:438
static void df(const Eigen::MatrixXf &x, Eigen::MatrixXf &df_x, float epsilon)
Derivative of f.
Definition: functionals.h:1057
static float f_squaredPairwise(const Eigen::MatrixXf &x, float lambda)
Squared pairwise term.
Definition: functionals.h:651
Denoising functionals (for grayscale images!.
Definition: functionals.h:89
static float g(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, const Eigen::Vector3f &Cp, const Eigen::Vector3f &Cm, float lambda)
Non-differentiable but convex part: (1 +- z)^2/4 (x_0 + Cpm)^2 dx.
Definition: functionals.h:1095
Utilities for using nmiPiano/iPiano for computer vision/image processing.
Definition: functionals.h:59
static float f(const Eigen::MatrixXf &x, float epsilon)
Differentiable but non-convex part: 9 | z|^2 + (1-z^2)^2/(64) dx.
Definition: functionals.h:1028
Generate noisy images.
Definition: functionals.h:94
static float g_squaredUnary(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0)
Squared unary, i.e. data, term.
Definition: functionals.h:757
static void df_smoothAbsolutePairwise(const Eigen::MatrixXf &x, Eigen::MatrixXf &df_x, float epsilon, float lambda)
Derivative of smooth absolute pairwise term.
static void convertEigenToOpenCV_Color(const Eigen::MatrixXf &eigen, cv::Mat &opencv)
Convert Eigen matrix to OpenCV color matrix.
Definition: functionals.h:475
static float f(const Eigen::MatrixXf &x, float epsilon)
Differentiable but non-convex part: 9 | z|^2 + (1-z^2)^2/(64) dx.
Definition: functionals.h:794
static float Cm(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0)
Compute Cp::m from the given labels x and the image x_0.
Definition: functionals.h:999
A collection of functionals for different computer vision/image processing tasks used to demonstrate ...
Definition: functionals.h:54
Two Phase-Field for segmentation, see [1]. [1] Shen. Gamma-Convergence Approximation to Piecewise Con...
Definition: functionals.h:217
static float g(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, float Cp, float Cm, float lambda)
Non-differentiable but convex part: (1 +- z)^2/4 (x_0 + Cpm)^2 dx.
Definition: functionals.h:861
static float g_absolute(const Eigen::MatrixXf &x, const Eigen::MatrixXf &X_0, const Eigen::Vector3f &Cp, const Eigen::Vector3f &Cm, float lambda)
Non-differentiable but convex part: |1 +- z| |x_0 + Cpm| dx.
Definition: functionals.h:1155
static void convertOpenCVToEigen(const cv::Mat &opencv, Eigen::MatrixXf &eigen)
Convert OpenCV matrix to Eigen matrix.
Definition: functionals.h:455
static float g_absoluteUnary(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0)
Absolute unary, i.e. data, term.
Definition: functionals.h:714
Evaluation of denoising functionals.
Definition: functionals.h:116
static void prox_g_squaredUnary(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, Eigen::MatrixXf &prox_f_x, float alpha)
Proximal map of squared unary term.
Definition: functionals.h:776
static float g(const Eigen::MatrixXf &x)
Non-differentiable but convex part: |x|_1.
Definition: functionals.h:1325
static void df(const Eigen::MatrixXf &x, const Eigen::MatrixXf &A, const Eigen::MatrixXf &y, Eigen::MatrixXf &df_x, float lambda)
Derivative of f.
Definition: functionals.h:1315
static void df_squaredPairwise(const Eigen::MatrixXf &x, Eigen::MatrixXf &df_x, float lambda)
Derivative of squared pairwise term.
Definition: functionals.h:678
static void convertOpenCVToEigen_Color(const cv::Mat &opencv, Eigen::MatrixXf &eigen)
Convert OpenCV color matrix to Eigen matrix.
Definition: functionals.h:496
static void prox_g_absolute(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, Eigen::MatrixXf &prox_g_x, const Eigen::Vector3f &Cp, const Eigen::Vector3f &Cm, float lambda, float alpha)
Proximal map of g_absolute.
Definition: functionals.h:1183
static void prox_g(const Eigen::MatrixXf &x, Eigen::MatrixXf &prox_g_x, float alpha)
Proximal map of g.
Definition: functionals.h:1334
static float f(const Eigen::MatrixXf &x, const Eigen::MatrixXf &A, const Eigen::MatrixXf &y, float lambda)
Differentiable but non-convex part: |Ax - y|_2^2.
Definition: functionals.h:1304
Compressive sensing example using convex optimization as discussed in [1]: [1] G. Kutyniok...
Definition: functionals.h:391
static void prox_g_absoluteUnary(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0, Eigen::MatrixXf &prox_f_x, float alpha)
Proximal map of absolute unary term.
Definition: functionals.h:739
static float f_lorentzianPairwise(const Eigen::MatrixXf &x, float sigma, float lambda)
Lorentzian pairwise term.
Definition: functionals.h:583
static float f_smoothAbsolutePairwise(const Eigen::MatrixXf &x, float epsilon, float lambda)
Smooth absolute pairwise term.
static float Cp(const Eigen::MatrixXf &x, const Eigen::MatrixXf &x_0)
Compute Cp from the given labels x and the image x_0.
Definition: functionals.h:970