LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Public Attributes | List of all members
lsst::afw::fits::ImageScalingOptions Class Reference

Options for scaling image pixels. More...

#include <fitsCompression.h>

Public Types

enum  ScalingAlgorithm {
  NONE , RANGE , STDEV_POSITIVE , STDEV_NEGATIVE ,
  STDEV_BOTH , MANUAL
}
 

Public Member Functions

 ImageScalingOptions ()
 Default Ctor. More...
 
 ImageScalingOptions (ScalingAlgorithm algorithm_, int bitpix_, std::vector< std::string > const &maskPlanes_={}, int seed_=1, float quantizeLevel_=4.0, float quantizePad_=5.0, bool fuzz_=true, double bscale_=1.0, double bzero_=0.0)
 General purpose Ctor. More...
 
 ImageScalingOptions (int bitpix_, double bscale_=1.0, double bzero_=0.0)
 Manual scaling Ctor. More...
 
template<typename T >
ImageScale determine (image::ImageBase< T > const &image, std::shared_ptr< image::Mask< image::MaskPixel > const > mask=nullptr) const
 Determine the scaling for a particular image. More...
 
template<typename T , int N>
ImageScale determine (ndarray::Array< T const, N, N > const &image, ndarray::Array< bool, N, N > const &mask) const
 

Public Attributes

ScalingAlgorithm algorithm
 Scaling algorithm to use. More...
 
int bitpix
 Bits per pixel (0, 8,16,32,64,-32,-64) More...
 
bool fuzz
 Fuzz the values when quantising floating-point values? More...
 
int seed
 Seed for random number generator when fuzzing. More...
 
std::vector< std::stringmaskPlanes
 Mask planes to ignore when doing statistics. More...
 
float quantizeLevel
 Divisor of the standard deviation for STDEV_* scaling. More...
 
float quantizePad
 Number of stdev to allow on the low/high side (for STDEV_POSITIVE/NEGATIVE) More...
 
double bscale
 Manually specified BSCALE (for MANUAL scaling) More...
 
double bzero
 Manually specified BZERO (for MANUAL scaling) More...
 

Detailed Description

Options for scaling image pixels.

Scaling (quantisation) of floating-point images is important in order to achieve respectable compression factors. Unfortunately, scaling a floating-point image means losing some information, in two ways: values are quantised so values in between the quanta will be rounded up or down; and values outside the range of supported values in the integer image will be clipped. This implementation is based on the successful implementation used by Pan-STARRS.

cfitsio provides a facility for scaling image pixels on write (see ImageCompressionOptions.quantizeLevel), but that facility is limited (it provides a single scaling option, and doesn't use our masks when collecting statistics). This scaling facility provides multiple scaling options, and could be extended to support more in the future (e.g., logarithmic or asinh scaling).

Scaling is specified by:

Scaling algorithms are:

Perhaps this one class could/should have been polymorphic, with different subclasses for different algorithms? But I went with a C-like approach keying off the enum, probably because I was influenced by Pan-STARRS' C code.

Definition at line 355 of file fitsCompression.h.

Member Enumeration Documentation

◆ ScalingAlgorithm

Enumerator
NONE 

No scaling.

RANGE 

Scale to preserve dynamic range.

STDEV_POSITIVE 

Scale based on the standard deviation. dynamic range positive.

STDEV_NEGATIVE 

Scale based on the standard deviation, dynamic range negative.

STDEV_BOTH 

Scale based on the standard deviation, dynamic range positive+negative.

MANUAL 

Scale set manually.

Definition at line 357 of file fitsCompression.h.

357  {
358  NONE,
359  RANGE,
362  STDEV_BOTH,
363  MANUAL,
364  };
@ STDEV_NEGATIVE
Scale based on the standard deviation, dynamic range negative.
@ STDEV_POSITIVE
Scale based on the standard deviation. dynamic range positive.
@ STDEV_BOTH
Scale based on the standard deviation, dynamic range positive+negative.
@ RANGE
Scale to preserve dynamic range.

Constructor & Destructor Documentation

◆ ImageScalingOptions() [1/3]

lsst::afw::fits::ImageScalingOptions::ImageScalingOptions ( )
inlineexplicit

Default Ctor.

Scaling is disabled by default.

Definition at line 378 of file fitsCompression.h.

◆ ImageScalingOptions() [2/3]

lsst::afw::fits::ImageScalingOptions::ImageScalingOptions ( ScalingAlgorithm  algorithm_,
int  bitpix_,
std::vector< std::string > const &  maskPlanes_ = {},
int  seed_ = 1,
float  quantizeLevel_ = 4.0,
float  quantizePad_ = 5.0,
bool  fuzz_ = true,
double  bscale_ = 1.0,
double  bzero_ = 0.0 
)

General purpose Ctor.

Parameters
[in]algorithm_Scaling algorithm to use
[in]bitpix_Bits per pixel (8,16,32,64,-32,-64), or 0 to match pixel type exactly.
[in]maskPlanes_Mask planes to ignore when doing statistics
[in]seed_Seed for random number generator when fuzzing
[in]quantizeLevel_Divisor of the standard deviation for STDEV_* scaling
[in]quantizePad_Number of stdev to allow on the low side (for STDEV_POSITIVE/NEGATIVE)
[in]fuzz_Fuzz the values when quantising floating-point values?
[in]bscale_Manually specified BSCALE (for MANUAL scaling)
[in]bzero_Manually specified BZERO (for MANUAL scaling)

Definition at line 129 of file fitsCompression.cc.

133  : algorithm(algorithm_),
134  bitpix(bitpix_),
135  fuzz(fuzz_),
136  seed(std::abs(seed_ - 1) % (N_RANDOM - 1) +
137  1), // zero is bad (cfitsio uses non-deterministic method)
138  maskPlanes(maskPlanes_),
139  quantizeLevel(quantizeLevel_),
140  quantizePad(quantizePad_),
141  bscale(bscale_),
142  bzero(bzero_) {}
ScalingAlgorithm algorithm
Scaling algorithm to use.
float quantizeLevel
Divisor of the standard deviation for STDEV_* scaling.
bool fuzz
Fuzz the values when quantising floating-point values?
float quantizePad
Number of stdev to allow on the low/high side (for STDEV_POSITIVE/NEGATIVE)
int bitpix
Bits per pixel (0, 8,16,32,64,-32,-64)
double bscale
Manually specified BSCALE (for MANUAL scaling)
std::vector< std::string > maskPlanes
Mask planes to ignore when doing statistics.
int seed
Seed for random number generator when fuzzing.
double bzero
Manually specified BZERO (for MANUAL scaling)
Angle abs(Angle const &a)
Definition: Angle.h:106

◆ ImageScalingOptions() [3/3]

lsst::afw::fits::ImageScalingOptions::ImageScalingOptions ( int  bitpix_,
double  bscale_ = 1.0,
double  bzero_ = 0.0 
)
inline

Manual scaling Ctor.

Parameters
[in]bitpix_Bits per pixel (8,16,32,64,-32,-64), or 0 to match pixel type exactly.
[in]bscale_Manually specified BSCALE
[in]bzero_Manually specified BZERO

Definition at line 403 of file fitsCompression.h.

404  : ImageScalingOptions(MANUAL, bitpix_, {}, 1, 4.0, 5.0, false, bscale_, bzero_) {}

Member Function Documentation

◆ determine() [1/2]

template<typename T >
ImageScale lsst::afw::fits::ImageScalingOptions::determine ( image::ImageBase< T > const &  image,
std::shared_ptr< image::Mask< image::MaskPixel > const >  mask = nullptr 
) const
inline

Determine the scaling for a particular image.

Parameters
[in]imageImage for which to determine scaling
[in]maskMask for image (used to measuring statistics)

Definition at line 412 of file fitsCompression.h.

413  {
414  auto const arrays = _toArray(image, mask);
415  return determine(arrays.first, arrays.second);
416  }
afw::table::Key< afw::table::Array< MaskPixelT > > mask
ArrayKeyVector arrays
ImageScale determine(image::ImageBase< T > const &image, std::shared_ptr< image::Mask< image::MaskPixel > const > mask=nullptr) const
Determine the scaling for a particular image.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.

◆ determine() [2/2]

template<typename T , int N>
ImageScale lsst::afw::fits::ImageScalingOptions::determine ( ndarray::Array< T const, N, N > const &  image,
ndarray::Array< bool, N, N > const &  mask 
) const

Member Data Documentation

◆ algorithm

ScalingAlgorithm lsst::afw::fits::ImageScalingOptions::algorithm

Scaling algorithm to use.

Definition at line 365 of file fitsCompression.h.

◆ bitpix

int lsst::afw::fits::ImageScalingOptions::bitpix

Bits per pixel (0, 8,16,32,64,-32,-64)

Definition at line 366 of file fitsCompression.h.

◆ bscale

double lsst::afw::fits::ImageScalingOptions::bscale

Manually specified BSCALE (for MANUAL scaling)

Definition at line 372 of file fitsCompression.h.

◆ bzero

double lsst::afw::fits::ImageScalingOptions::bzero

Manually specified BZERO (for MANUAL scaling)

Definition at line 373 of file fitsCompression.h.

◆ fuzz

bool lsst::afw::fits::ImageScalingOptions::fuzz

Fuzz the values when quantising floating-point values?

Definition at line 367 of file fitsCompression.h.

◆ maskPlanes

std::vector<std::string> lsst::afw::fits::ImageScalingOptions::maskPlanes

Mask planes to ignore when doing statistics.

Definition at line 369 of file fitsCompression.h.

◆ quantizeLevel

float lsst::afw::fits::ImageScalingOptions::quantizeLevel

Divisor of the standard deviation for STDEV_* scaling.

Definition at line 370 of file fitsCompression.h.

◆ quantizePad

float lsst::afw::fits::ImageScalingOptions::quantizePad

Number of stdev to allow on the low/high side (for STDEV_POSITIVE/NEGATIVE)

Definition at line 371 of file fitsCompression.h.

◆ seed

int lsst::afw::fits::ImageScalingOptions::seed

Seed for random number generator when fuzzing.

Definition at line 368 of file fitsCompression.h.


The documentation for this class was generated from the following files: