LSST Applications g0d33ba9806+3d1aa5cd78,g0fba68d861+6c07529581,g1e78f5e6d3+aa4d1c21f1,g1ec0fe41b4+f536777771,g1fd858c14a+c6963eae98,g35bb328faa+fcb1d3bbc8,g4af146b050+58cb980876,g4d2262a081+bfae794ebc,g53246c7159+fcb1d3bbc8,g5a012ec0e7+b20b785ecb,g60b5630c4e+3d1aa5cd78,g67b6fd64d1+4086c0989b,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+a8b896a16a,g8852436030+75f93ca278,g89139ef638+4086c0989b,g9125e01d80+fcb1d3bbc8,g94187f82dc+3d1aa5cd78,g989de1cb63+4086c0989b,g9f33ca652e+94dd9a85be,g9f7030ddb1+3f50642ad9,ga2b97cdc51+3d1aa5cd78,ga44b1db4f6+7d2d5e68ea,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+96cb2ddcf2,gb58c049af0+f03b321e39,gb89ab40317+4086c0989b,gcf25f946ba+75f93ca278,gd6cbbdb0b4+af3c3595f5,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+ed90e8109d,ge278dab8ac+d65b3c2b70,ge410e46f29+4086c0989b,gf67bdafdda+4086c0989b,gfe06eef73a+e2ab3e8e4f,v29.0.0.rc5
LSST Data Management Base Package
|
(Return to Images)
(You might be interested to compare this example with the discussion of Image locators ; apart from an include file and a typedef, the only difference is the use of ImageT::Pixel(y, 0x1, 10)
as the assigned pixel value instead of y
).
Iterators provide access to an image, pixel by pixel. You often want access to neighbouring pixels (e.g. computing a gradient, or smoothing). Let's consider the problem of smoothing with a
kernel (the code's in maskedImage2.cc):
Start by including MaskedImage.h, defining a namespace for clarity:
Declare a MaskedImage
Set the image (but not the mask or variance) to a ramp
That didn't gain us much, did it? The code's a little messier than using x_iterator
. But now we can add code to calculate the smoothed image. First make an output image, and copy the input pixels:
(we didn't need to copy all of them, just the ones around the edge that we won't smooth, but this is an easy way to do it).
Now do the smoothing:
(N.b. you don't really want to do this; not only is this kernel separable into 1
2
1
in first the x
then the y
directions, but lsst::afw::math
can do convolutions for you).
Here's a faster way to do the same thing (the use of an Image::Ptr
is just for variety)
The xy_loc::cached_location_t
variables remember relative positions.
We can rewrite this to move setting nw
, se
etc. out of the loop:
You may have noticed that that kernel isn't normalised. We could change the coefficients, but that'd slow things down for integer images (such as the one here); but we can normalise after the fact by making an Image that shares pixels with the central part of out2
and manipulating it via overloaded operator/=
N.b. you can use the iterator embedded in the locator directly if you really want to, e.g.
Note that this isn't quite the same x_iterator
as before, due to the need to make the x_iterator
move the underlying xy_locator
.
Finally write some output files and close out main()
: