8 public static final int STRAIGHT_LINE=0,POLY2=1,POLY3=2,POLY4=3,
9 EXPONENTIAL=4,POWER=5,LOG=6,RODBARD=7,GAMMA_VARIATE=8, LOG2=9;
10 public static final int NONE=20, UNCALIBRATED_OD=21;
39 private double[] coefficients;
42 private String unit =
"pixel";
48 private String valueUnit =
"Gray Value";
51 private int function = NONE;
54 private float[] cTable;
56 private boolean invertedLut;
57 private int bitDepth = 8;
58 private boolean zeroClip;
80 if (unit==null || unit.equals(
""))
95 if (unit.equals(
"pixel"))
97 else if (unit.equals(
"micron"))
99 else if (unit.equals(
"inch"))
123 public void setFunction(
int function,
double[] coefficients, String unit) {
127 public void setFunction(
int function,
double[] coefficients, String unit,
boolean zeroClip) {
129 {disableDensityCalibration();
return;}
130 if (coefficients==null &&
function>=STRAIGHT_LINE &&
function<=LOG2)
132 this.
function =
function;
133 this.coefficients = coefficients;
134 this.zeroClip = zeroClip;
147 disableDensityCalibration();
148 bitDepth = newBitDepth;
151 public void disableDensityCalibration() {
155 valueUnit =
"Gray Value";
176 return function!=NONE;
195 {make16BitCTable();
return;}
198 if (
function==UNCALIBRATED_OD) {
199 cTable =
new float[256];
200 for (
int i=0; i<256; i++)
201 cTable[i] = (
float)od(i);
202 }
else if (
function>=STRAIGHT_LINE &&
function<=LOG2 && coefficients!=null) {
203 cTable =
new float[256];
205 for (
int i=0; i<256; i++) {
206 value = CurveFitter.f(
function, coefficients, i);
207 if (zeroClip && value<0.0)
210 cTable[i] = (float)value;
216 void make16BitCTable() {
217 if (
function>=STRAIGHT_LINE &&
function<=LOG2 && coefficients!=null) {
218 cTable =
new float[65536];
219 for (
int i=0; i<65536; i++)
220 cTable[i] = (
float)CurveFitter.f(
function, coefficients, i);
225 double od(
double v) {
227 if (v==255.0) v = 254.5;
228 return 0.434294481*Math.log(255.0/(255.0-v));
231 return 0.434294481*Math.log(255.0/v);
239 if (
function>=STRAIGHT_LINE &&
function<=LOG2 && coefficients!=null) {
240 double v =
CurveFitter.
f(
function, coefficients, value);
241 if (zeroClip && v<0.0)
247 if (cTable!=null && value>=0 && value<cTable.length)
248 return cTable[value];
258 if (
function>=STRAIGHT_LINE &&
function<=LOG2 && coefficients!=null) {
259 double v =
CurveFitter.
f(
function, coefficients, value);
260 if (zeroClip && v<0.0)
275 float fvalue = (float)value;
276 float smallestDiff = Float.MAX_VALUE;
279 for (
int i=0; i<cTable.length; i++) {
280 diff = fvalue - cTable[i];
281 if (diff<0f) diff = -diff;
282 if (diff<smallestDiff) {
303 copy.valueUnit = valueUnit;
304 copy.function =
function;
305 copy.coefficients = coefficients;
306 copy.cTable = cTable;
307 copy.invertedLut = invertedLut;
308 copy.bitDepth = bitDepth;
309 copy.zeroClip = zeroClip;
317 boolean equal =
true;
320 if (!cal.unit.equals(unit))
322 if (!cal.valueUnit.equals(valueUnit) || cal.function!=
function)
329 return bitDepth==16 && cTable!=null && cTable[0]==-32768;
332 public String toString() {
339 +
", nc=" + (coefficients!=null?
""+coefficients.length:
"null")
340 +
", table=" + (cTable!=null?
""+cTable.length:
"null")
341 +
", vunit=" + valueUnit;