Skip to content

Commit

Permalink
Read and write spacing and zunit ImageJ TIFF metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Sep 20, 2024
1 parent 686371d commit 41858b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion components/formats-bsd/src/loci/formats/in/TiffReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class TiffReader extends BaseTiffReader {
private String companionFile;
private String description;
private String calibrationUnit;
private String zUnit;
private Double physicalSizeZ;
private Time timeIncrement;
private Integer xOrigin, yOrigin;
Expand Down Expand Up @@ -113,6 +114,7 @@ public void close(boolean fileOnly) throws IOException {
companionFile = null;
description = null;
calibrationUnit = null;
zUnit = null;
physicalSizeZ = null;
timeIncrement = null;
xOrigin = null;
Expand All @@ -137,6 +139,7 @@ protected void initStandardMetadata() throws FormatException, IOException {

description = null;
calibrationUnit = null;
zUnit = null;
physicalSizeZ = null;
timeIncrement = null;
xOrigin = null;
Expand Down Expand Up @@ -293,6 +296,10 @@ else if (token.startsWith("unit=")) {
calibrationUnit = value;
put("Unit", calibrationUnit);
}
else if (token.startsWith("zunit=")) {
zUnit = value;
put("Z Unit", zUnit);
}
else if (token.startsWith("finterval=")) {
Double valueDouble = parseDouble(value);
if (valueDouble != null) {
Expand Down Expand Up @@ -404,7 +411,7 @@ private void populateMetadataStoreImageJ(MetadataStore store) {
if (physicalSizeZ != null) {
double zDepth = physicalSizeZ.doubleValue();
if (zDepth < 0) zDepth = -zDepth;
Length z = FormatTools.getPhysicalSizeZ(zDepth);
Length z = FormatTools.getPhysicalSizeZ(zDepth, zUnit);
if (z != null) {
store.setPixelsPhysicalSizeZ(z, 0);
}
Expand Down
14 changes: 11 additions & 3 deletions components/formats-bsd/src/loci/formats/out/TiffWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,17 @@ else if (retrieve.getPixelsBinDataCount(series) == 0) {
int channels = retrieve.getPixelsSizeC(series).getValue().intValue();
int z = retrieve.getPixelsSizeZ(series).getValue().intValue();
int t = retrieve.getPixelsSizeT(series).getValue().intValue();
ifd.putIFDValue(IFD.IMAGE_DESCRIPTION,
"ImageJ=\nhyperstack=true\nimages=" + (channels * z * t) + "\nchannels=" +
channels + "\nslices=" + z + "\nframes=" + t);

String imagejMetadata = "ImageJ=\nhyperstack=true\nimages=" +
(channels * z * t) + "\nchannels=" +
channels + "\nslices=" + z + "\nframes=" + t;
Length physicalSizeZ = retrieve.getPixelsPhysicalSizeZ(series);
if (physicalSizeZ != null) {
Double zSpacing = physicalSizeZ.value().doubleValue();
String zUnit = physicalSizeZ.unit().getSymbol();
imagejMetadata += "\nzunit=" + zUnit + "\nspacing=" + zSpacing;
}
ifd.putIFDValue(IFD.IMAGE_DESCRIPTION, imagejMetadata);

int index = (no * getResolutionCount()) + getResolution();
int currentSeries = getSeries();
Expand Down

0 comments on commit 41858b0

Please sign in to comment.