49 if ((width < 1) || (height < 1)) {
52 const int signedWidth =
static_cast<int>(width);
53 const int signedHeight =
static_cast<int>(height);
55 for (
int row = 0; row < signedHeight; ++row) {
56 for (
int col = 0; col < signedWidth; ++col) {
62 return kernelBasisList;
88 if (nGauss !=
static_cast<int>(sigGauss.
size())) {
91 if (nGauss !=
static_cast<int>(degGauss.
size())) {
94 int fullWidth = 2 * halfWidth + 1;
98 for (
int i = 0; i < nGauss; i++) {
102 double sig = sigGauss[i];
103 int deg = degGauss[i];
105 LOGL_DEBUG(
"TRACE1.ip.diffim.BasisLists.makeAlardLuptonBasisList",
106 "Gaussian %d : sigma %.2f degree %d", i, sig, deg);
112 for (
int j = 0, n = 0; j <= deg; j++) {
113 for (
int k = 0; k <= (deg - j); k++, n++) {
126 for (
int y = 0, v = -halfWidth; y <
image.getHeight(); y++, v++) {
128 for (
auto ptr =
image.row_begin(y), end =
image.row_end(y); ptr != end; ++ptr, ++u) {
130 *ptr = *ptr * polynomial(u/
static_cast<double>(halfWidth),
131 v/
static_cast<double>(halfWidth));
180 int width = ps.
getAsInt(
"kernelSize");
181 int height = ps.
getAsInt(
"kernelSize");
182 float borderPenalty = ps.
getAsDouble(
"regularizationBorderPenalty");
183 bool fitForBackground = ps.
getAsBool(
"fitForBackground");
185 Eigen::MatrixXd bMat;
186 if (regularizationType ==
"centralDifference") {
187 int stencil = ps.
getAsInt(
"centralRegularizationStencil");
190 else if (regularizationType ==
"forwardDifference") {
198 Eigen::MatrixXd hMat = bMat.transpose() * bMat;
210 bool fitForBackground
233 if (borderPenalty < 0)
254 else if (stencil == 9) {
256 coeffs[0][0] = 1. / 6.;
257 coeffs[0][1] = 4. / 6.;
258 coeffs[0][2] = 1. / 6.;
259 coeffs[1][0] = 4. / 6.;
260 coeffs[1][1] = -20. / 6.;
261 coeffs[1][2] = 4. / 6.;
262 coeffs[2][0] = 1. / 6.;
263 coeffs[2][1] = 4. / 6.;
264 coeffs[2][2] = 1. / 6.;
270 int nBgTerms = fitForBackground ? 1 : 0;
271 Eigen::MatrixXd bMat = Eigen::MatrixXd::Zero(width * height + nBgTerms, width * height + nBgTerms);
273 for (
int i = 0; i < width*height; i++) {
274 int const x0 = i % width;
275 int const y0 = i / width;
276 int const distX = width - x0 - 1;
277 int const distY = height - y0 - 1;
279 if ( (x0 > 0) && (y0 > 0) && (distX > 0) && (distY > 0) ) {
280 for (
int dx = -1; dx < 2; dx += 1) {
281 for (
int dy = -1; dy < 2; dy += 1) {
282 bMat(i, i + dx + dy * width) += coeffs[dx+1][dy+1];
287 bMat(i, i) = borderPenalty;
291 if (fitForBackground) {
293 if (bMat.col(width*height).sum() != 0.) {
296 if (bMat.row(width*height).sum() != 0.) {
312 bool fitForBackground
331 if (borderPenalty < 0)
338 coeffs[0][0] = borderPenalty;
355 int nBgTerms = fitForBackground ? 1 : 0;
356 Eigen::MatrixXd bTot = Eigen::MatrixXd::Zero(width * height + nBgTerms, width * height + nBgTerms);
358 std::vector<int>::const_iterator order;
359 for (order = orders.
begin(); order != orders.
end(); order++) {
360 if ((*order < 1) || (*order > 3))
363 Eigen::MatrixXd bMatX = Eigen::MatrixXd::Zero(width * height + nBgTerms,
364 width * height + nBgTerms);
365 Eigen::MatrixXd bMatY = Eigen::MatrixXd::Zero(width * height + nBgTerms,
366 width * height + nBgTerms);
368 for (
int i = 0; i < width*height; i++) {
369 int const x0 = i % width;
370 int const y0 = i / width;
372 int distX = width - x0 - 1;
373 int orderToUseX =
std::min(distX, *order);
374 for (
int j = 0; j < orderToUseX+1; j++) {
375 bMatX(i, i + j) = coeffs[orderToUseX][j];
378 int distY = height - y0 - 1;
379 int orderToUseY =
std::min(distY, *order);
380 for (
int j = 0; j < orderToUseY+1; j++) {
381 bMatY(i, i + j * width) = coeffs[orderToUseY][j];
388 if (fitForBackground) {
390 if (bTot.col(width*height).sum() != 0.) {
393 if (bTot.row(width*height).sum() != 0.) {
441 if (kernelListIn.
size() == 0) {
442 return kernelListOut;
445 Image image0(kernelListIn[0]->getDimensions());
446 for (
unsigned int i = 0; i < kernelListIn.
size(); i++) {
449 (void)kernelListIn[i]->computeImage(image0,
true);
458 Image
image(kernelListIn[i]->getDimensions());
459 (void)kernelListIn[i]->computeImage(
image,
false);
464 for (
int y = 0; y <
image.getHeight(); y++) {
465 for (
auto ptr =
image.row_begin(y), end =
image.row_end(y); ptr != end; ++ptr) {
483 for (
int y = 0; y <
image.getHeight(); y++) {
484 for (
auto ptr =
image.row_begin(y), end =
image.row_end(y); ptr != end; ++ptr) {
495 return kernelListOut;
507 unsigned int boundary_style,
508 unsigned int difference_style,
514 if (boundary_style > 2) {
517 if (difference_style > 1) {
553 unsigned int x_cen = 0, y_cen = 0;
554 unsigned int x_cen1 = 0, y_cen1 = 0;
555 unsigned int x_cen2 = 0, y_cen2 = 0;
556 unsigned int x_size = 0, y_size = 0;
559 if (difference_style == 0) {
565 x_size = y_size = order + 2;
569 coeffs[0][0][0] = -2;
575 coeffs[1][0][0] = -2;
577 coeffs[1][0][2] = -1;
581 coeffs[1][2][0] = -1;
586 coeffs[2][0][0] = -2;
588 coeffs[2][0][2] = -3;
594 coeffs[2][2][0] = -3;
605 if (difference_style == 1) {
614 coeffs[0][0][1] = -1;
617 coeffs[0][1][0] = -1;
638 coeffs[1][1][1] = -4;
655 coeffs[2][0][2] = -1;
665 coeffs[2][2][0] = -1;
668 coeffs[2][2][3] = -2;
673 coeffs[2][3][2] = -2;
687 Eigen::MatrixXd bMat = Eigen::MatrixXd::Zero(width*height+1, width*height+1);
690 for (
unsigned int i = 0; i < width*height; i++) {
692 unsigned int const x0 = i % width;
693 unsigned int const y0 = i / width;
695 unsigned int x_edge_distance = (x0 > (width - x0 - 1)) ? width - x0 - 1 : x0;
696 unsigned int y_edge_distance = (y0 > (height - y0 - 1)) ? height - y0 - 1 : y0;
697 unsigned int edge_distance = (x_edge_distance < y_edge_distance) ? x_edge_distance :
700 for (
unsigned int dx = 0; dx < x_size; dx++) {
701 for (
unsigned int dy = 0; dy < y_size; dy++) {
709 double this_coeff = 0;
712 if (boundary_style == 0) {
715 if (y > height - 1 || x > width - 1) {
718 this_coeff = coeffs[order][dx][dy];
721 }
else if (boundary_style == 1) {
722 x = (width + x0 + dx - x_cen) % width;
723 y = (height + y0 + dy - y_cen) % height;
724 this_coeff = coeffs[order][dx][dy];
728 }
else if (boundary_style == 2) {
731 if (edge_distance == 0) {
737 else if (edge_distance == 1 && order > 0) {
738 x = (width + x0 + dx - x_cen1) % width;
739 y = (height + y0 + dy - y_cen1) % height;
740 if ((dx < 3) && (dy < 3)) { this_coeff = coeffs[1][dx][dy]; }
743 else if (edge_distance == 2 && order > 1){
744 x = (width + x0 + dx - x_cen2) % width;
745 y = (height + y0 + dy - y_cen2) % height;
746 if ((dx < 5) && (dy < 5)) { this_coeff = coeffs[2][dx][dy]; }
749 else if (edge_distance > order) {
750 x = (width + x0 + dx - x_cen) % width;
751 y = (height + y0 + dy - y_cen) % height;
752 this_coeff = coeffs[order][dx][dy];
757 bMat(i, y*width + x) = this_coeff;
769 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
void setParameter(unsigned int ind, double newValue)
std::string getAsString(std::string const &name) const
int getAsInt(std::string const &name) const
std::vector< T > getArray(std::string const &name) const
double getAsDouble(std::string const &name) const
bool getAsBool(std::string const &name) const
std::vector< std::shared_ptr< Kernel > > KernelList
Extent< int, 2 > Extent2I
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.