Skip to content

Commit

Permalink
TIFFFormat: correct calibration data
Browse files Browse the repository at this point in the history
Was mistakenly populating private fields in the Metadata instead of
putting calibration values on the actual CalibratedAxes.

Removed the superfluous fields and accessors. The TIFFFormat$Metadata
axes should now have their x/y/z calibration values populated correctly.
  • Loading branch information
hinerm committed Dec 26, 2013
1 parent 8681733 commit 232261b
Showing 1 changed file with 14 additions and 57 deletions.
71 changes: 14 additions & 57 deletions scifio/src/main/java/io/scif/formats/TIFFFormat.java
Expand Up @@ -117,13 +117,10 @@ public static class Metadata extends MinimalTIFFFormat.Metadata {
private String experimenterLastName;
private String experimenterEmail;
private String imageDescription;
private double physicalSizeX;
private double physicalSizeY;

private String companionFile;
private String description;
private String calibrationUnit;
private Double physicalSizeZ;
private Double timeIncrement;
private Integer xOrigin, yOrigin;

Expand Down Expand Up @@ -153,14 +150,6 @@ public void setCalibrationUnit(final String calibrationUnit) {
this.calibrationUnit = calibrationUnit;
}

public Double getPhysicalSizeZ() {
return physicalSizeZ == null ? 1.0 : physicalSizeZ;
}

public void setPhysicalSizeZ(final Double physicalSizeZ) {
this.physicalSizeZ = physicalSizeZ;
}

public Double getTimeIncrement() {
return timeIncrement == null ? 1.0 : timeIncrement;
}
Expand Down Expand Up @@ -225,22 +214,6 @@ public void setImageDescription(final String imageDescription) {
this.imageDescription = imageDescription;
}

public double getPhysicalSizeX() {
return physicalSizeX;
}

public void setPhysicalSizeX(final double physicalSizeX) {
this.physicalSizeX = physicalSizeX;
}

public double getPhysicalSizeY() {
return physicalSizeY;
}

public void setPhysicalSizeY(final double physicalSizeY) {
this.physicalSizeY = physicalSizeY;
}

// -- Metadata API Methods --

@Override
Expand All @@ -265,7 +238,6 @@ public void close(final boolean fileOnly) throws IOException {
companionFile = null;
description = null;
calibrationUnit = null;
physicalSizeZ = null;
timeIncrement = null;
xOrigin = null;
yOrigin = null;
Expand Down Expand Up @@ -407,7 +379,6 @@ protected void initMetadataStore(final Metadata meta)
// if (meta.getDescription() != null) {
// store.setImageDescription(description, 0);
// }
populateMetadataStoreImageJ(meta);
}

// -- Helper methods --
Expand Down Expand Up @@ -469,8 +440,16 @@ else if (token.startsWith("finterval=")) {
put("Frame Interval", meta.getTimeIncrement());
}
else if (token.startsWith("spacing=")) {
meta.setPhysicalSizeZ(parseDouble(value));
put("Spacing", meta.getPhysicalSizeZ());
final double physicalSizeZ = parseDouble(value);
if (physicalSizeZ >= 0) {
if (meta.get(0).getAxis(Axes.Z) == null) {
meta.get(0).addAxis(Axes.Z, 1);
}

FormatTools
.calibrate(meta.get(0).getAxis(Axes.Z), physicalSizeZ, 0);
}
put("Spacing", physicalSizeZ);
}
else if (token.startsWith("xorigin=")) {
meta.setxOrigin(parseInt(value));
Expand Down Expand Up @@ -583,28 +562,6 @@ else if (z * t == ifds.size()) {
m.setAxes(validAxes.toArray(new CalibratedAxis[validAxes.size()]));
}

/**
* Checks the original metadata table for ImageJ-specific information to
* propagate into the metadata store.
*/
private void populateMetadataStoreImageJ(final Metadata meta) {
// TODO: Perhaps we should only populate the physical Z size if the unit
// is
// a known, physical quantity such as "micron" rather than "pixel".
// e.g.: if (calibrationUnit.equals("micron"))
if (meta.getPhysicalSizeZ() != null) {
double zDepth = meta.getPhysicalSizeZ();
if (zDepth < 0) zDepth = -zDepth;
if (zDepth > 0) {
meta.setPhysicalSizeZ(zDepth);
}
else {
log()
.warn("Expected positive value for PhysicalSizeZ; got " + zDepth);
}
}
}

private void
parseCommentMetamorph(final Metadata meta, final String comment)
{
Expand Down Expand Up @@ -1050,13 +1007,13 @@ protected void initMetadataStore(final Metadata meta)
final double pixY = firstIFD.getYResolution();

if (pixX > 0 && pixX < Double.POSITIVE_INFINITY) {
meta.setPhysicalSizeX(pixX);
FormatTools.calibrate(meta.get(0).getAxis(Axes.X), pixX, 0);
}
else {
log().warn("Expected positive value for PhysicalSizeX; got " + pixX);
}
if (pixY > 0 && pixX < Double.POSITIVE_INFINITY) {
meta.setPhysicalSizeY(pixY);
FormatTools.calibrate(meta.get(0).getAxis(Axes.Y), pixY, 0);
}
else {
log().warn("Expected positive value for PhysicalSizeY; got " + pixY);
Expand Down Expand Up @@ -1437,13 +1394,13 @@ private long prepareToWriteImage(final int imageIndex, final long planeIndex,
ifd.put(new Integer(IFD.IMAGE_WIDTH), new Long(width));
ifd.put(new Integer(IFD.IMAGE_LENGTH), new Long(height));

Double physicalSizeX = meta.getPhysicalSizeX();
Double physicalSizeX = meta.get(0).getAxis(Axes.X).averageScale(0, 1);
if (physicalSizeX == null || physicalSizeX.doubleValue() == 0) {
physicalSizeX = 0d;
}
else physicalSizeX = 1d / physicalSizeX;

Double physicalSizeY = meta.getPhysicalSizeY();
Double physicalSizeY = meta.get(0).getAxis(Axes.Y).averageScale(0, 1);
if (physicalSizeY == null || physicalSizeY.doubleValue() == 0) {
physicalSizeY = 0d;
}
Expand Down

0 comments on commit 232261b

Please sign in to comment.