LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
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.
 
 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.
 
 ImageScalingOptions (int bitpix_, double bscale_=1.0, double bzero_=0.0)
 Manual scaling Ctor.
 
template<typename T >
ImageScale determine (image::ImageBase< T > const &image, image::Mask< image::MaskPixel > const *mask=nullptr) const
 Determine the scaling for a particular image.
 
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.
 
int bitpix
 Bits per pixel (0, 8,16,32,64,-32,-64)
 
bool fuzz
 Fuzz the values when quantising floating-point values?
 
int seed
 Seed for random number generator when fuzzing.
 
std::vector< std::stringmaskPlanes
 Mask planes to ignore when doing statistics.
 
float quantizeLevel
 Divisor of the standard deviation for STDEV_* scaling.
 
float quantizePad
 Number of stdev to allow on the low/high side (for STDEV_POSITIVE/NEGATIVE)
 
double bscale
 Manually specified BSCALE (for MANUAL scaling)
 
double bzero
 Manually specified BZERO (for MANUAL scaling)
 

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)

◆ 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,
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, image::Mask< image::MaskPixel > const *mask=nullptr) const
Determine the scaling for a particular image.

◆ 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: