14#include "boost/timer.hpp"
51 if ((width < 1) || (height < 1)) {
84 typedef afwMath::Kernel::Pixel Pixel;
107 LOGL_DEBUG(
"TRACE1.ip.diffim.BasisLists.makeAlardLuptonBasisList",
108 "Gaussian %d : sigma %.2f degree %d",
i,
sig,
deg);
114 for (
int j = 0, n = 0;
j <=
deg;
j++) {
115 for (
int k = 0; k <= (
deg -
j); k++, n++) {
181 std::string regularizationType =
ps.getAsString(
"regularizationType");
182 int width =
ps.getAsInt(
"kernelSize");
183 int height =
ps.getAsInt(
"kernelSize");
185 bool fitForBackground =
ps.getAsBool(
"fitForBackground");
187 Eigen::MatrixXd
bMat;
188 if (regularizationType ==
"centralDifference") {
189 int stencil =
ps.getAsInt(
"centralRegularizationStencil");
192 else if (regularizationType ==
"forwardDifference") {
200 Eigen::MatrixXd hMat =
bMat.transpose() *
bMat;
212 bool fitForBackground
258 coeffs[0][0] = 1. / 6.;
259 coeffs[0][1] = 4. / 6.;
260 coeffs[0][2] = 1. / 6.;
261 coeffs[1][0] = 4. / 6.;
262 coeffs[1][1] = -20. / 6.;
263 coeffs[1][2] = 4. / 6.;
264 coeffs[2][0] = 1. / 6.;
265 coeffs[2][1] = 4. / 6.;
266 coeffs[2][2] = 1. / 6.;
272 int nBgTerms = fitForBackground ? 1 : 0;
273 Eigen::MatrixXd
bMat = Eigen::MatrixXd::Zero(width * height +
nBgTerms, width * height +
nBgTerms);
275 for (
int i = 0;
i < width*height;
i++) {
276 int const x0 =
i % width;
277 int const y0 =
i / width;
278 int const distX = width - x0 - 1;
279 int const distY = height - y0 - 1;
281 if ( (x0 > 0) && (y0 > 0) && (
distX > 0) && (
distY > 0) ) {
282 for (
int dx = -1;
dx < 2;
dx += 1) {
283 for (
int dy = -1;
dy < 2;
dy += 1) {
293 if (fitForBackground) {
295 if (
bMat.col(width*height).sum() != 0.) {
298 if (
bMat.row(width*height).sum() != 0.) {
314 bool fitForBackground
357 int nBgTerms = fitForBackground ? 1 : 0;
358 Eigen::MatrixXd
bTot = Eigen::MatrixXd::Zero(width * height +
nBgTerms, width * height +
nBgTerms);
365 Eigen::MatrixXd
bMatX = Eigen::MatrixXd::Zero(width * height +
nBgTerms,
367 Eigen::MatrixXd
bMatY = Eigen::MatrixXd::Zero(width * height +
nBgTerms,
370 for (
int i = 0;
i < width*height;
i++) {
371 int const x0 =
i % width;
372 int const y0 =
i / width;
374 int distX = width - x0 - 1;
380 int distY = height - y0 - 1;
390 if (fitForBackground) {
392 if (
bTot.col(width*height).sum() != 0.) {
395 if (
bTot.row(width*height).sum() != 0.) {
415 typedef afwMath::Kernel::Pixel Pixel;
466 for (
int y = 0;
y <
image.getHeight();
y++) {
485 for (
int y = 0;
y <
image.getHeight();
y++) {
571 coeffs[0][0][0] = -2;
577 coeffs[1][0][0] = -2;
579 coeffs[1][0][2] = -1;
583 coeffs[1][2][0] = -1;
588 coeffs[2][0][0] = -2;
590 coeffs[2][0][2] = -3;
596 coeffs[2][2][0] = -3;
616 coeffs[0][0][1] = -1;
619 coeffs[0][1][0] = -1;
640 coeffs[1][1][1] = -4;
657 coeffs[2][0][2] = -1;
667 coeffs[2][2][0] = -1;
670 coeffs[2][2][3] = -2;
675 coeffs[2][3][2] = -2;
689 Eigen::MatrixXd
bMat = Eigen::MatrixXd::Zero(width*height+1, width*height+1);
692 for (
unsigned int i = 0;
i < width*height;
i++) {
694 unsigned int const x0 =
i % width;
695 unsigned int const y0 =
i / width;
697 unsigned int x_edge_distance = (x0 > (width - x0 - 1)) ? width - x0 - 1 : x0;
698 unsigned int y_edge_distance = (y0 > (height - y0 - 1)) ? height - y0 - 1 : y0;
717 if (
y > height - 1 ||
x > width - 1) {
724 x = (width + x0 +
dx -
x_cen) % width;
725 y = (height + y0 +
dy -
y_cen) % height;
741 y = (height + y0 +
dy -
y_cen1) % height;
747 y = (height + y0 +
dy -
y_cen2) % height;
752 x = (width + x0 +
dx -
x_cen) % width;
753 y = (height + y0 +
dy -
y_cen) % height;
771 Eigen::MatrixXd hMat =
bMat.transpose() *
bMat;
#define LOGL_DEBUG(logger, message...)
Subroutines associated with generating, normalising, and regularising Basis functions.
#define LSST_EXCEPT(type,...)
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Asseses the quality of a candidate given a spatial kernel and background model.
lsst::afw::math::KernelList makeDeltaFunctionBasisList(int width, int height)
Build a set of Delta Function basis kernels.
lsst::afw::math::KernelList renormalizeKernelList(lsst::afw::math::KernelList const &kernelListIn)
Renormalize a list of basis kernels.
Eigen::MatrixXd makeFiniteDifferenceRegularizationDeprecated(unsigned int width, unsigned int height, unsigned int order, unsigned int boundary_style, unsigned int difference_style, bool printB)
Generate regularization matrix for delta function kernels.
Eigen::MatrixXd makeRegularizationMatrix(lsst::daf::base::PropertySet const &ps)
Build a regularization matrix for Delta function kernels.
Eigen::MatrixXd makeCentralDifferenceMatrix(int width, int height, int stencil, float borderPenalty, bool fitForBackground)
Build a central difference Laplacian regularization matrix for Delta function kernels.
Eigen::MatrixXd makeForwardDifferenceMatrix(int width, int height, std::vector< int > const &orders, float borderPenalty, bool fitForBackground)
Build a forward difference regularization matrix for Delta function kernels.
lsst::afw::math::KernelList makeAlardLuptonBasisList(int halfWidth, int nGauss, std::vector< double > const &sigGauss, std::vector< int > const °Gauss)
Build a set of Alard/Lupton basis kernels.