Round-off bug with zero point in calibration

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Round-off bug with zero point in calibration

Stein Rørvik
There is some kind of rounding bug affecting the zero point in calibrations.
Depending on the max value, the zero point is in some cases off by a small negative fraction, when both the raw and calibrated min value is meant to be zero.

Try the demo macro below to reproduce the issue.
The two different calibrations applied should be identical, but in the first case the zero point is off.
The arrays show that all values are calculated and shown correctly, except for raw zero / calibrate(0).

This causes problems for me because I need to test if the calibrated value for raw zero is zero or not.
Currently, the statement
                if (calibrate(0) == 0.0) then ....
will fail in these cases, in a manner that is impossible to predict.

I cannot use rounding as a workaround for the zero point test, because in some of my 16-bit data the calibrated max value is already a small fraction and the calibrated zero point may correspond to a small positive raw value. In these cases the calibrated zero value is intentionally off by a small negative value, and I cannot find any robust way to separate this intentional small negative zero point from the round-off-error small negative zero point.

Demo macro:
------------------------------
print("\\Clear<file://Clear>");
run("M51 Galaxy (16-bits)");
print("min: " + calibrate(0));                       //ok, image is uncalibrated
print("max: " + calibrate(65535));             //ok, image is uncalibrated
print("");
values = newArray(65536);

CalibParameters = "function=[Straight Line] unit=[photons/sec] text1=[0 65535] text2=[0.0 6.5535]";
run("Calibrate...", CalibParameters);
print("Calibrate: ", CalibParameters);
print("min: " + calibrate(0));                       //fails, prints -4.4409E-16 instead of zero
print("max: " + calibrate(65535));             //ok
print("");
for(i=0; i <= 65535; i+=1)
                values[i] = calibrate(i);
Array.show("cal1(indexes)", values);

CalibParameters = "function=[Straight Line] unit=[photons/sec] text1=[0 60000] text2=[0.0 6.0]";
run("Calibrate...", CalibParameters);
print("Calibrate: ", CalibParameters);
print("min: " + calibrate(0));                       //ok, prints 0
print("max: " + calibrate(65535));             //ok
print("");
for(i=0; i <= 65535; i+=1)
                values[i] = calibrate(i);
Array.show("cal2(indexes)", values);
------------------------------


I am using daily build ImageJ 1.53g with Java 1.8.0_172 on Windows 10/64-bit.


Stein


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html