Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions components/formats-gpl/src/loci/formats/in/CellSensReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -1862,6 +1862,37 @@ else if (tag == RWC_FRAME_ORIGIN) {
pyramid.originY = doubleValues[1];
}
}
else if (tag == VALUE
&& "Calibration Function ".equals(tagPrefix)
&& realType == DOUBLE_2
&& nDoubleValues >= 4
&& (nDoubleValues % 2) == 0)
{
// Tag 20051 (CALIBRATION) sub-volumes carry a piecewise-
// linear lookup table mapping a raw axis (e.g. uint16
// pixel value) to a calibrated axis (e.g. Z position in
// micrometres for DSX EFI height maps, or intensity in
// counts for deconvolved fluorescence images). The LUT
// is stored as (raw, calibrated) DOUBLE_2 pairs and is
// linear, so a single (slope, origin) suffices to
// reconstruct the mapping. Surface those summary values
// as named metadata so downstream tools can convert
// pixel values to calibrated units without reparsing
// the full table from a long string.
int nPairs = nDoubleValues / 2;
double rawFirst = doubleValues[0];
double calFirst = doubleValues[1];
double rawLast = doubleValues[2 * (nPairs - 1)];
double calLast = doubleValues[2 * (nPairs - 1) + 1];
double dRaw = rawLast - rawFirst;
if (dRaw != 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check may yield unexpected results; best practice when comparing double values is not to use == or !=. https://cclc.mtu.edu/java-doubles-and-floating-point-numbers/ has a concise explanation with additional references.

In other readers, we would use something like Math.abs(dRaw - 0) > Constants.EPSILON to check that dRaw is non-zero.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 1676a74. Thanks Melissa!

double slope = (calLast - calFirst) / dRaw;
addGlobalMeta("Calibration Function Slope", slope);
addGlobalMeta("Calibration Function Origin", calFirst);
addGlobalMeta("Calibration Function Final", calLast);
addGlobalMeta("Calibration Function NPoints", nPairs);
}
}
break;
case RGB:
int red = vsi.read();
Expand Down
Loading