LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
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
 Determine the scaling for a particular image. More...
 

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  };
Scale to preserve dynamic range.
Scale based on the standard deviation, dynamic range negative.
Scale based on the standard deviation, dynamic range positive+negative.
Scale based on the standard deviation. dynamic range positive.

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 130 of file fitsCompression.cc.

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

◆ 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  }
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.
ArrayKeyVector arrays

◆ 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

Determine the scaling for a particular image.

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

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: