Skip to content

Commit

Permalink
Merge pull request #1966 from dgault/metamorph_voxelsize
Browse files Browse the repository at this point in the history
Incorrect VoxelSize in MetaMorph Reader
  • Loading branch information
melissalinkert committed Sep 30, 2015
2 parents e5fa891 + d8f1f6e commit 134c310
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions components/formats-gpl/src/loci/formats/in/MetamorphReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormatSymbols;
import java.util.Arrays;
import java.util.ArrayList;
Expand Down Expand Up @@ -778,6 +779,38 @@ else if (differentZs) {
if (zDistances != null) {
stepSize = zDistances[0];
}
else {
Vector<Double> zPositions = new Vector<Double>();
Vector<Double> uniqueZ = new Vector<Double>();

for (IFD ifd : ifds) {
MetamorphHandler zPlaneHandler = new MetamorphHandler();

String zComment = ifd.getComment();
if (zComment != null &&
zComment.startsWith("<MetaData>"))
{
try {
XMLTools.parseXML(XMLTools.sanitizeXML(zComment),
zPlaneHandler);
}
catch (IOException e) { }
}

zPositions = zPlaneHandler.getZPositions();
for (Double z : zPositions) {
if (!uniqueZ.contains(z)) uniqueZ.add(z);
}
}
if (uniqueZ.size() > 1 && uniqueZ.size() == getSizeZ()) {
BigDecimal lastZ = BigDecimal.valueOf(uniqueZ.get(uniqueZ.size() - 1));
BigDecimal firstZ = BigDecimal.valueOf(uniqueZ.get(0));
BigDecimal zRange = (lastZ.subtract(firstZ)).abs();
BigDecimal zSize = BigDecimal.valueOf((double)(getSizeZ() - 1));
stepSize = zRange.divide(zSize).doubleValue();
}
}

Length physicalSizeZ = FormatTools.getPhysicalSizeZ(stepSize);
if (physicalSizeZ != null) {
store.setPixelsPhysicalSizeZ(physicalSizeZ, i);
Expand Down

0 comments on commit 134c310

Please sign in to comment.