27 #include "lsst/pex/exceptions.h" 31 namespace pexExcept = lsst::pex::exceptions;
43 for (
int y = 0; y != image.
getHeight(); ++y) {
44 for (XIter imPtr = image.
row_begin(y), imEnd = image.
row_end(y); imPtr != imEnd; ++imPtr) {
53 _sum = kernel.
computeImage(_image,
false, pos[0], pos[1]);
57 std::shared_ptr<Kernel> retPtr(
new FixedKernel(_image));
58 retPtr->setCtr(this->
getCtr());
63 if ((width <= 0) || (height <= 0)) {
64 std::ostringstream os;
65 os <<
"Cannot create FixedKernel with dimensions (" << width <<
", " << height <<
"). ";
66 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
69 std::ostringstream os;
70 os <<
"Cannot resize FixedKernel from (" <<
getWidth() <<
", " <<
getHeight() <<
") to (" 71 << width <<
", " << height <<
"), because at least one dimension would change by an odd value.";
72 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
77 std::shared_ptr<image::Image<Pixel>> imNew = std::make_shared<image::Image<Pixel>>(bboxNew);
82 bboxIntersect.clip(bboxNew);
91 bboxIntersect.getMinY() + offsetY),
92 bboxIntersect.getDimensions());
95 imNew->
assign(imIntersect, bboxIntersect);
96 std::shared_ptr<Kernel> retPtr = std::make_shared<FixedKernel>(*imNew);
101 double multFactor = 1.0;
102 double imSum = this->_sum;
105 throw LSST_EXCEPT(pexExcept::OverflowError,
"Cannot normalize; kernel sum is 0");
107 multFactor = 1.0 /
static_cast<double>(this->_sum);
113 for (
int y = 0; y != this->
getHeight(); ++y) {
115 imPtr != imEnd; ++imPtr, ++kPtr) {
116 imPtr[0] = multFactor * kPtr[0];
124 std::ostringstream os;
125 os << prefix <<
"FixedKernel:" << std::endl;
126 os << prefix <<
"..sum: " << _sum << std::endl;
136 table::Key<table::Array<Kernel::Pixel> >
image;
139 :
Kernel::PersistenceHelper(0),
140 image(
schema.addField<table::Array<
Kernel::
Pixel> >(
"image",
"pixel values (row-major)",
141 dimensions.getX() * dimensions.getY())) {}
143 explicit FixedKernelPersistenceHelper(table::Schema
const& schema_)
144 : Kernel::PersistenceHelper(schema_),
image(
schema[
"image"]) {}
155 FixedKernelPersistenceHelper
const keys(catalogs.front().getSchema());
158 ndarray::flatten<1>(ndarray::static_dimension_cast<2>(image.
getArray())) = record[keys.image];
159 std::shared_ptr<FixedKernel>
result = std::make_shared<FixedKernel>(
image);
160 result->setCtr(record.get(keys.center));
164 explicit Factory(std::string
const&
name) : afw::table::io::PersistableFactory(name) {}
169 std::string getFixedKernelPersistenceName() {
return "FixedKernel"; }
179 std::shared_ptr<afw::table::BaseRecord> record = keys.write(handle, *
this);
180 (*record)[keys.image] = ndarray::flatten<1>(ndarray::copy(_image.getArray()));
int getHeight() const
Return the Kernel's height.
afw::table::PointKey< int > dimensions
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
An object passed to Persistable::write to allow it to persist itself.
lsst::afw::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
int getHeight() const
Return the number of rows in the image.
A base class for factory classes used to reconstruct objects from records.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
lsst::afw::geom::Point2I getCtr() const
Return index of kernel's center.
void assign(ImageBase const &rhs, geom::Box2I const &bbox=geom::Box2I(), ImageOrigin origin=PARENT)
Copy pixels from another image to a specified subregion of this image.
Extent< int, 2 > Extent2I
int getX0() const
Return the image's column-origin.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
An integer coordinate rectangle.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
virtual std::shared_ptr< Kernel > resized(int width, int height) const
Return a pointer to a clone with specified kernel dimensions.
A base class for image defects.
FixedKernel()
Construct an empty FixedKernel of size 0x0.
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
table::Key< std::string > name
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
int getWidth() const
Return the Kernel's width.
virtual std::shared_ptr< afw::table::io::Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const
Construct a new object from the given InputArchive and vector of catalogs.
A vector of catalogs used by Persistable.
Base class for all records.
int getY0() const
Return the image's row-origin.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
Kernel()
Construct a null Kernel of size 0,0.
table::Key< table::Array< Kernel::Pixel > > image
x_iterator row_end(int y) const
Return an x_iterator to the end of the y'th row.
Kernels are used for convolution with MaskedImages and (eventually) Images.
geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
afw::table::Schema schema
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Factory(std::string const &name)