5 #include "boost/format.hpp" 15 template <
typename ImageT>
18 explicit SetPixels() : _value(0) {}
20 void setValue(
float value) { _value = value; }
29 template <
typename ImageT>
34 float saturatedPixelValue
36 int const width = rim.getWidth(), height = rim.getHeight();
37 int const x0 = rim.getX0(), y0 = rim.getY0();
39 if (width != gim.getWidth() || height != gim.getHeight() || x0 != gim.getX0() || y0 != gim.getY0()) {
43 "(%dx%d+%d+%d v. %dx%d+%d+%d") %
44 width % height % x0 % y0 % gim.getWidth() % gim.getHeight() % gim.getX0() % gim.getY0()));
46 if (width != bim.getWidth() || height != bim.getHeight() || x0 != bim.getX0() || y0 != bim.getY0()) {
50 "(%dx%d+%d+%d v. %dx%d+%d+%d") %
51 width % height % x0 % y0 % bim.getWidth() % bim.getHeight() % bim.getX0() % bim.getY0()));
56 SetPixels<typename ImageT::Image> setR, setG, setB;
59 int const npixMin = 1;
69 for (FootprintList::const_iterator
ptr = feet->begin(),
end = feet->end();
ptr !=
end; ++
ptr) {
71 auto const bigFoot = std::make_shared<detection::Footprint>(foot->getSpans()->dilated(borderWidth),
74 double sumR = 0, sumG = 0, sumB = 0;
75 double maxR = 0, maxG = 0, maxB = 0;
77 for (
auto span = bigFoot->getSpans()->begin(), send = bigFoot->getSpans()->end();
span != send;
79 int const y =
span->getY() - y0;
80 if (y < 0 || y >= height) {
83 int sx0 =
span->getX0() - x0;
87 int sx1 =
span->getX1() - x0;
92 for (
typename ImageT::iterator rptr = rim.at(sx0, y), rend = rim.at(sx1 + 1, y),
93 gptr = gim.at(sx0, y), bptr = bim.at(sx0, y);
94 rptr != rend; ++rptr, ++gptr, ++bptr) {
95 if (!((rptr.mask() | gptr.mask() | bptr.mask()) & SAT)) {
96 float val = rptr.image();
118 float R = 0, G = 0, B = 0;
119 if (sumR + sumB + sumG > 0) {
122 R = useMaxPixel ? maxR : saturatedPixelValue;
124 G = (R * sumG) / sumR;
125 B = (R * sumB) / sumR;
127 B = useMaxPixel ? maxB : saturatedPixelValue;
128 R = (B * sumR) / sumB;
129 G = (B * sumG) / sumB;
133 G = useMaxPixel ? maxG : saturatedPixelValue;
134 R = (G * sumR) / sumG;
135 B = (G * sumB) / sumG;
137 B = useMaxPixel ? maxB : saturatedPixelValue;
138 R = (B * sumR) / sumB;
139 G = (B * sumG) / sumB;
145 foot->getSpans()->applyFunctor(setR, *rim.getImage());
147 foot->getSpans()->applyFunctor(setG, *gim.getImage());
149 foot->getSpans()->applyFunctor(setB, *bim.getImage());
155 float saturatedPixelValue);
float Pixel
Typedefs to be used for pixel values.
Use (pixels & (given mask))
A Threshold is used to pass a threshold value to detection algorithms.
void replaceSaturatedPixels(ImageT &rim, ImageT &gim, ImageT &bim, int borderWidth=2, float saturatedPixelValue=65535)
A base class for image defects.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A class to manipulate images, masks, and variance as a single object.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Reports invalid arguments.