#include <imageanalysis/ImageAnalysis/StatImageCreator.h>
#include <casacore/images/Images/ImageStatistics.h>
#include <imageanalysis/Annotations/AnnCenterBox.h>
#include <imageanalysis/Annotations/AnnCircle.h>
#include <casacore/lattices/LEL/LatticeExpr.h>
const Double StatImageCreator::PHI = 1.482602218505602;
StatImageCreator::StatImageCreator(
const SPCIIF image, const Record *const region,
const String& mask, const String& outname, Bool overwrite
) : ImageStatsConfigurator(image, region, mask, outname, overwrite) {
auto da = _getImage()->coordinates().directionAxesNumbers();
void StatImageCreator::setRadius(const Quantity& radius) {
! (radius.getUnit().startsWith("pix") || radius.isConform("rad")),
"radius units " + radius.getUnit() + " must be pixel or angular"
void StatImageCreator::setRectangle(
const Quantity& xLength, const Quantity& yLength
! (xLength.getUnit().startsWith("pix") || xLength.isConform("rad")),
"xLength units " + xLength.getUnit() + " must be pixel or angular"
! (yLength.getUnit().startsWith("pix") || yLength.isConform("rad")),
"xLength units " + yLength.getUnit() + " must be pixel or angular"
void StatImageCreator::setAnchorPosition(Int x, Int y) {
Vector<Double> anchorPixel(_getImage()->ndim(), 0);
anchorPixel[_dirAxes[0]] = x;
anchorPixel[_dirAxes[1]] = y;
_anchor = _getImage()->coordinates().toWorld(anchorPixel);
void StatImageCreator::useReferencePixelAsAnchor() {
const auto refPix = _getImage()->coordinates().referencePixel();
Int x = round(refPix[_dirAxes[0]]);
Int y = round(refPix[_dirAxes[1]]);
*_getLog() << LogIO::NORMAL << LogOrigin("StatImageCreator", __func__)
<< "Anchor being set at pixel [" << x << "," << y
<< "], at/near image reference pixel." << LogIO::POST;
void StatImageCreator::setGridSpacing(uInt x, uInt y) {
SPIIF StatImageCreator::compute() {
static const AxesSpecifier dummyAxesSpec;
*_getLog() << LogOrigin(getClass(), __func__);
auto mylog = _getLog().get();
auto subImageRO = SubImageFactory<Float>::createSubImageRO(
*_getImage(), *_getRegion(), _getMask(),
mylog, dummyAxesSpec, _getStretch()
auto subImageRW = SubImageFactory<Float>::createImage(
*_getImage(), "", *_getRegion(), _getMask(),
dummyAxesSpec, False, False, _getStretch()
_doMask = ! ImageMask::isAllMaskTrue(*subImageRO);
const auto imshape = subImageRO->shape();
const auto xshape = imshape[_dirAxes[0]];
const auto yshape = imshape[_dirAxes[1]];
const auto& csys = subImageRO->coordinates();
auto anchorPixel = csys.toPixel(_anchor);
Int xanchor = rint(anchorPixel[_dirAxes[0]]);
Int yanchor = rint(anchorPixel[_dirAxes[1]]);