Class Quantize
- java.lang.Object
-
- nom.tam.fits.compression.algorithm.quant.Quantize
-
public class Quantize extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
Quantize.DoubleArrayPointer
-
Field Summary
Fields Modifier and Type Field Description private static double
DEFAULT_QUANT_LEVEL
private static double
MAX_INT_AS_DOUBLE
private double
maxValue
maximum non-null valueprivate static int
MINIMUM_PIXEL_WIDTH
private double
minValue
minimum non-null valueprivate static long
N_RESERVED_VALUES
number of reserved values, starting withprivate static int
N4
private static int
N6
private long
ngood
number of good, non-null pixels?private static double
NOISE_2_MULTIPLICATOR
private static double
NOISE_3_MULTIPLICATOR
private static double
NOISE_5_MULTIPLICATOR
private double
noise2
returned 2nd order MAD of all non-null pixelsprivate double
noise3
returned 3rd order MAD of all non-null pixelsprivate double
noise5
private QuantizeOption
parameter
private double
xmaxval
private double
xminval
private double
xnoise2
private double
xnoise3
private double
xnoise5
-
Constructor Summary
Constructors Constructor Description Quantize(QuantizeOption quantizeOption)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
calculateNoise(double[] arrayIn, int nx, int ny)
Estimate the median and background noise in the input image using 2nd, 3rd and 5th order Median Absolute Differences.private boolean
calculateNoiseShortRow(Quantize.DoubleArrayPointer array, int nx, int ny)
protected void
computeMedianOfValuesEachRow(int nrows, int nrows2, double[] diffs2, double[] diffs3, double[] diffs5)
protected int
findNextValidPixelWithNullCheck(int nx, Quantize.DoubleArrayPointer rowpix, int ii)
private double
getNextPixelAndCheckMinMax(Quantize.DoubleArrayPointer rowpix, int ii)
protected double
getNoise2()
protected double
getNoise3()
protected double
getNoise5()
private void
initializeNoise()
protected boolean
isNull(double d)
boolean
quantize(double[] fdata, int nxpix, int nypix)
arguments: long row i: tile number = row number in the binary table double fdata[] i: tiledImageOperation of image pixels to be compressed long nxpix i: number of pixels in each row of fdata long nypix i: number of rows in fdata nullcheck i: check for nullvalues in fdata? double in_null_value i: value used to represent undefined pixels in fdata float qlevel i: quantization level int dither_method i; which dithering method to use int idata[] o: values of fdata after applying bzero and bscale double bscale o: scale factor double bzero o: zero offset int iminval o: minimum quantized value that is returned int imaxval o: maximum quantized value that is returned The function value will be one if the input fdata were copied to idata; in this case the parameters bscale and bzero can be used to convert back to nearly the original floating point values: fdata ~= idata * bscale + bzero.private double
quickSelect(double[] arr, int n)
private void
setNoiseResult(long ngoodpix)
private void
swapElements(double[] array, int one, int second)
-
-
-
Field Detail
-
DEFAULT_QUANT_LEVEL
private static final double DEFAULT_QUANT_LEVEL
- See Also:
- Constant Field Values
-
MAX_INT_AS_DOUBLE
private static final double MAX_INT_AS_DOUBLE
- See Also:
- Constant Field Values
-
MINIMUM_PIXEL_WIDTH
private static final int MINIMUM_PIXEL_WIDTH
- See Also:
- Constant Field Values
-
N_RESERVED_VALUES
private static final long N_RESERVED_VALUES
number of reserved values, starting with- See Also:
- Constant Field Values
-
N4
private static final int N4
- See Also:
- Constant Field Values
-
N6
private static final int N6
- See Also:
- Constant Field Values
-
NOISE_2_MULTIPLICATOR
private static final double NOISE_2_MULTIPLICATOR
- See Also:
- Constant Field Values
-
NOISE_3_MULTIPLICATOR
private static final double NOISE_3_MULTIPLICATOR
- See Also:
- Constant Field Values
-
NOISE_5_MULTIPLICATOR
private static final double NOISE_5_MULTIPLICATOR
- See Also:
- Constant Field Values
-
parameter
private final QuantizeOption parameter
-
maxValue
private double maxValue
maximum non-null value
-
minValue
private double minValue
minimum non-null value
-
ngood
private long ngood
number of good, non-null pixels?
-
noise2
private double noise2
returned 2nd order MAD of all non-null pixels
-
noise3
private double noise3
returned 3rd order MAD of all non-null pixels
-
noise5
private double noise5
-
xmaxval
private double xmaxval
-
xminval
private double xminval
-
xnoise2
private double xnoise2
-
xnoise3
private double xnoise3
-
xnoise5
private double xnoise5
-
-
Constructor Detail
-
Quantize
public Quantize(QuantizeOption quantizeOption)
-
-
Method Detail
-
calculateNoise
private void calculateNoise(double[] arrayIn, int nx, int ny)
Estimate the median and background noise in the input image using 2nd, 3rd and 5th order Median Absolute Differences. The noise in the background of the image is calculated using the MAD algorithms developed for deriving the signal to noise ratio in spectra (see issue #42 of the ST-ECF newsletter, http://www.stecf.org/documents/newsletter/) 3rd order: noise = 1.482602 / sqrt(6) * median (abs(2*flux(i) - flux(i-2) - flux(i+2))) The returned estimates are the median of the values that are computed for each row of the image.- Parameters:
arrayIn
- 2 dimensional tiledImageOperation of image pixelsnx
- number of pixels in each row of the imageny
- number of rows in the imagenullcheck
- check for null values, if truenullvalue
- value of null pixels, if nullcheck is true
-
calculateNoiseShortRow
private boolean calculateNoiseShortRow(Quantize.DoubleArrayPointer array, int nx, int ny)
-
computeMedianOfValuesEachRow
protected void computeMedianOfValuesEachRow(int nrows, int nrows2, double[] diffs2, double[] diffs3, double[] diffs5)
-
findNextValidPixelWithNullCheck
protected int findNextValidPixelWithNullCheck(int nx, Quantize.DoubleArrayPointer rowpix, int ii)
-
getNextPixelAndCheckMinMax
private double getNextPixelAndCheckMinMax(Quantize.DoubleArrayPointer rowpix, int ii)
-
getNoise2
protected double getNoise2()
-
getNoise3
protected double getNoise3()
-
getNoise5
protected double getNoise5()
-
initializeNoise
private void initializeNoise()
-
isNull
protected boolean isNull(double d)
-
quantize
public boolean quantize(double[] fdata, int nxpix, int nypix)
arguments: long row i: tile number = row number in the binary table double fdata[] i: tiledImageOperation of image pixels to be compressed long nxpix i: number of pixels in each row of fdata long nypix i: number of rows in fdata nullcheck i: check for nullvalues in fdata? double in_null_value i: value used to represent undefined pixels in fdata float qlevel i: quantization level int dither_method i; which dithering method to use int idata[] o: values of fdata after applying bzero and bscale double bscale o: scale factor double bzero o: zero offset int iminval o: minimum quantized value that is returned int imaxval o: maximum quantized value that is returned The function value will be one if the input fdata were copied to idata; in this case the parameters bscale and bzero can be used to convert back to nearly the original floating point values: fdata ~= idata * bscale + bzero. If the function value is zero, the data were not copied to idata.In earlier implementations of the compression code, we only used the noise3 value as the most reliable estimate of the background noise in an image. If it is not possible to compute a noise3 value, then this serves as a red flag to indicate that quantizing the image could cause a loss of significant information in the image.
At some later date, we decided to take the more conservative approach of using the minimum of all three of the noise values (while still requiring that noise3 has a defined value) as the best estimate of the noise. Note that if an image contains pure Gaussian distributed noise, then noise2, noise3, and noise5 will have exactly the same value (within statistical measurement errors).
- Parameters:
fdata
- the data to quantinizenxpix
- the image widthnypix
- the image hight- Returns:
- true if the quantification was possible
-
quickSelect
private double quickSelect(double[] arr, int n)
-
setNoiseResult
private void setNoiseResult(long ngoodpix)
-
swapElements
private void swapElements(double[] array, int one, int second)
-
-