|
LSSTApplications
11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
|
(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:
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:
Now do the smoothing:
(N.b. you don't really want to do this; not only is this kernel separable into1 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)
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 samex_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():
1.8.5