Changeset 6656


Ignore:
Timestamp:
07/07/10 10:52:17 (9 years ago)
Author:
curtis
Message:

If TimeIncrement is missing, average DeltaT values for ImageJ time interval.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/loci-plugins/src/loci/plugins/in/Calibrator.java

    r6654 r6656  
    2929import ij.measure.Calibration; 
    3030 
     31import java.util.Arrays; 
     32 
    3133import loci.formats.FormatTools; 
    3234import loci.formats.meta.IMetadata; 
     35import ome.xml.model.primitives.NonNegativeInteger; 
     36import ome.xml.model.primitives.PositiveInteger; 
    3337 
    3438/** 
     
    4347  // -- Fields -- 
    4448 
    45   private ImportProcess process; 
     49  private final ImportProcess process; 
    4650 
    4751  // -- Constructor -- 
     
    7074    if (td != null) tcal = td.floatValue(); 
    7175 
    72     final boolean xcalPresent = !Double.isNaN(xcal); 
    73     final boolean ycalPresent = !Double.isNaN(ycal); 
    74     final boolean zcalPresent = !Double.isNaN(zcal); 
    75     final boolean tcalPresent = !Double.isNaN(tcal); 
     76    boolean xcalPresent = !Double.isNaN(xcal); 
     77    boolean ycalPresent = !Double.isNaN(ycal); 
     78    boolean zcalPresent = !Double.isNaN(zcal); 
     79    boolean tcalPresent = !Double.isNaN(tcal); 
    7680 
    77     // if the physical width or physical height are missing, 
    78     // assume that the width and height are equal 
     81    // HACK: If the physical width or height are missing, 
     82    // assume that the width and height are equal. 
    7983    if (xcalPresent && !ycalPresent) ycal = xcal; 
    8084    else if (ycalPresent && !xcalPresent) xcal = ycal; 
    8185 
     86    // HACK: If the time increment is missing, 
     87    // average any variable time interval values. 
     88    if (!tcalPresent) tcal = computeVariableTimeInterval(meta, series); 
     89 
     90    xcalPresent = !Double.isNaN(xcal); 
     91    ycalPresent = !Double.isNaN(ycal); 
     92    zcalPresent = !Double.isNaN(zcal); 
     93    tcalPresent = !Double.isNaN(tcal); 
    8294    final boolean hasSpatial = xcalPresent || ycalPresent || zcalPresent; 
    8395    final boolean hasCalibration = hasSpatial || ycalPresent; 
     
    111123  } 
    112124 
     125  private double computeVariableTimeInterval(IMetadata meta, int series) { 
     126    // collect variable time interval values 
     127    final PositiveInteger sizeT = meta.getPixelsSizeT(series); 
     128    final int tSize = sizeT == null ? 1 : sizeT.getValue(); 
     129    final int planeCount = meta.getPlaneCount(series); 
     130    final double[] deltas = new double[tSize]; 
     131    Arrays.fill(deltas, Double.NaN); 
     132    for (int p=0; p<planeCount; p++) { 
     133      final NonNegativeInteger theZ = meta.getPlaneTheZ(series, p); 
     134      final NonNegativeInteger theC = meta.getPlaneTheC(series, p); 
     135      final NonNegativeInteger theT = meta.getPlaneTheT(series, p); 
     136      if (theZ == null || theC == null || theT == null) continue; 
     137      if (theZ.getValue() != 0 || theC.getValue() != 0) continue; 
     138      // store delta T value at appropriate index 
     139      final int t = theT.getValue(); 
     140      if (t >= tSize) continue; 
     141      final Double deltaT = meta.getPlaneDeltaT(series, p); 
     142      if (deltaT == null) continue; 
     143      deltas[t] = deltaT; 
     144    } 
     145    // average delta T differences 
     146    double tiTotal = 0; 
     147    int tiCount = 0; 
     148    for (int t=1; t<tSize; t++) { 
     149      double delta1 = deltas[t - 1]; 
     150      double delta2 = deltas[t]; 
     151      if (Double.isNaN(delta1) || Double.isNaN(delta2)) continue; 
     152      tiTotal += delta2 - delta1; 
     153      tiCount++; 
     154    } 
     155    if (tiCount == 0) return Double.NaN; 
     156    return (float) (tiTotal / tiCount); 
     157  } 
     158 
    113159} 
Note: See TracChangeset for help on using the changeset viewer.