Changeset 1938


Ignore:
Timestamp:
12/14/06 15:04:04 (13 years ago)
Author:
melissa
Message:

Fixed FileStitcher to respect multi-series files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/FileStitcher.java

    r1926 r1938  
    5757 
    5858  /** Axis guesser object used to guess which dimensional axes are which. */ 
    59   private AxisGuesser ag; 
     59  private AxisGuesser[] ag; 
    6060 
    6161  /** The matching files. */ 
     
    6666 
    6767  /** Blank buffered image, for use when image counts vary between files. */ 
    68   private BufferedImage blankImage; 
     68  private BufferedImage[] blankImage; 
    6969 
    7070  /** Blank image bytes, for use when image counts vary between files. */ 
    71   private byte[] blankBytes; 
     71  private byte[][] blankBytes; 
    7272 
    7373  /** Image dimensions. */ 
    74   private int width, height; 
     74  private int[] width, height; 
    7575 
    7676  /** Number of images per file. */ 
    77   private int imagesPerFile; 
     77  private int[] imagesPerFile; 
    7878 
    7979  /** Total number of image planes. */ 
    80   private int totalImages; 
     80  private int[] totalImages; 
    8181 
    8282  /** Dimension order. */ 
    83   private String order; 
     83  private String[] order; 
    8484 
    8585  /** Dimensional axis lengths per file. */ 
    86   private int sizeZ, sizeC, sizeT; 
     86  private int[] sizeZ, sizeC, sizeT; 
    8787 
    8888  /** Total dimensional axis lengths. */ 
    89   private int totalSizeZ, totalSizeC, totalSizeT; 
     89  private int[] totalSizeZ, totalSizeC, totalSizeT; 
    9090 
    9191  /** Component lengths for each axis type. */ 
    92   private int[] lenZ, lenC, lenT; 
     92  private int[][] lenZ, lenC, lenT; 
    9393 
    9494  /** Whether or not we're doing channel stat calculation (no by default). */ 
     
    138138  { 
    139139    if (!id.equals(currentId)) initFile(id); 
    140     return ag.getAxisTypes(); 
     140    return ag[getSeries(id)].getAxisTypes(); 
    141141  } 
    142142 
     
    154154  { 
    155155    if (!id.equals(currentId)) initFile(id); 
    156     ag.setAxisTypes(axes); 
     156    ag[getSeries(id)].setAxisTypes(axes); 
    157157    computeAxisLengths(); 
    158158  } 
     
    174174  { 
    175175    if (!id.equals(currentId)) initFile(id); 
    176     return ag; 
     176    return ag[getSeries(id)]; 
    177177  } 
    178178 
     
    212212  public int getImageCount(String id) throws FormatException, IOException { 
    213213    if (!id.equals(currentId)) initFile(id); 
    214     return totalImages; 
     214    return totalImages[getSeries(id)]; 
    215215  } 
    216216 
     
    224224  public int getSizeX(String id) throws FormatException, IOException { 
    225225    if (!id.equals(currentId)) initFile(id); 
    226     return width; 
     226    return width[getSeries(id)]; 
    227227  } 
    228228 
     
    230230  public int getSizeY(String id) throws FormatException, IOException { 
    231231    if (!id.equals(currentId)) initFile(id); 
    232     return height; 
     232    return height[getSeries(id)]; 
    233233  } 
    234234 
     
    236236  public int getSizeZ(String id) throws FormatException, IOException { 
    237237    if (!id.equals(currentId)) initFile(id); 
    238     return totalSizeZ; 
     238    return totalSizeZ[getSeries(id)]; 
    239239  } 
    240240 
     
    242242  public int getSizeC(String id) throws FormatException, IOException { 
    243243    if (!id.equals(currentId)) initFile(id); 
    244     return totalSizeC; 
     244    return totalSizeC[getSeries(id)]; 
    245245  } 
    246246 
     
    248248  public int getSizeT(String id) throws FormatException, IOException { 
    249249    if (!id.equals(currentId)) initFile(id); 
    250     return totalSizeT; 
     250    return totalSizeT[getSeries(id)]; 
    251251  } 
    252252 
     
    260260  public int getEffectiveSizeC(String id) throws FormatException, IOException { 
    261261    if (!id.equals(currentId)) initFile(id); 
    262     return isRGB(id) ? (getSizeC(id) + 2) / 3 : getSizeC(id); 
     262    return isRGB(id) ? 1 : getSizeC(id); 
    263263  } 
    264264  
     
    319319  { 
    320320    if (!id.equals(currentId)) initFile(id); 
    321     return order; 
     321    return order[getSeries(id)]; 
    322322  } 
    323323 
     
    325325  public boolean isOrderCertain(String id) throws FormatException, IOException { 
    326326    if (!id.equals(currentId)) initFile(id); 
    327     return ag.isCertain(); 
     327    return ag[getSeries(id)].isCertain(); 
    328328  } 
    329329 
     
    355355    // return a blank image to cover for the fact that 
    356356    // this file does not contain enough image planes 
    357     if (blankImage == null) { 
    358       blankImage = ImageTools.blankImage(width, height, 
    359         sizeC, getPixelType(currentId)); 
    360     } 
    361     return blankImage; 
     357    int sno = getSeries(id); 
     358    if (blankImage[sno] == null) { 
     359      blankImage[sno] = ImageTools.blankImage(width[sno], height[sno], 
     360        sizeC[sno], getPixelType(currentId)); 
     361    } 
     362    return blankImage[sno]; 
    362363  } 
    363364 
     
    373374    // return a blank image to cover for the fact that 
    374375    // this file does not contain enough image planes 
    375     if (blankBytes == null) { 
     376    int sno = getSeries(id); 
     377    if (blankBytes[sno] == null) { 
    376378      int bytes = FormatReader.getBytesPerPixel(getPixelType(currentId)); 
    377       blankBytes = new byte[width * height * bytes * sizeC]; 
    378     } 
    379     return blankBytes; 
     379      blankBytes[sno] = new byte[width[sno] * height[sno] * bytes *  
     380        (isRGB(id) ? sizeC[sno] : 1)]; 
     381    } 
     382    return blankBytes[sno]; 
    380383  } 
    381384 
     
    469472  { 
    470473    if (!id.equals(currentId)) initFile(id); 
    471     this.order = order; 
     474    this.order[getSeries(id)] = order; 
    472475    String f0 = files[0]; 
    473476    reader.swapDimensions(f0, order); 
    474     sizeZ = reader.getSizeZ(f0); 
    475     sizeC = reader.getSizeC(f0); 
    476     sizeT = reader.getSizeT(f0); 
     477    sizeZ[getSeries(id)] = reader.getSizeZ(f0); 
     478    sizeC[getSeries(id)] = reader.getSizeC(f0); 
     479    sizeT[getSeries(id)] = reader.getSizeT(f0); 
    477480    computeAxisLengths(); 
    478481  } 
     
    650653    String f0 = files[0]; 
    651654 
     655    int seriesCount = getSeriesCount(f0); 
     656    ag = new AxisGuesser[seriesCount]; 
     657    blankImage = new BufferedImage[seriesCount]; 
     658    blankBytes = new byte[seriesCount][]; 
     659    width = new int[seriesCount]; 
     660    height = new int[seriesCount]; 
     661    imagesPerFile = new int[seriesCount]; 
     662    totalImages = new int[seriesCount]; 
     663    order = new String[seriesCount]; 
     664    sizeZ = new int[seriesCount]; 
     665    sizeC = new int[seriesCount]; 
     666    sizeT = new int[seriesCount]; 
     667    totalSizeZ = new int[seriesCount]; 
     668    totalSizeC = new int[seriesCount]; 
     669    totalSizeT = new int[seriesCount]; 
     670    lenZ = new int[seriesCount][]; 
     671    lenC = new int[seriesCount][]; 
     672    lenT = new int[seriesCount][]; 
     673 
    652674    // analyze first file; assume each file has the same parameters 
    653     width = reader.getSizeX(f0); 
    654     height = reader.getSizeY(f0); 
    655     imagesPerFile = reader.getImageCount(f0); 
    656     totalImages = files.length * imagesPerFile; 
    657     order = reader.getDimensionOrder(f0); 
    658     sizeZ = reader.getSizeZ(f0); 
    659     sizeC = reader.getSizeC(f0); 
    660     sizeT = reader.getSizeT(f0); 
     675     
     676    int oldSeries = getSeries(f0); 
     677    for (int i=0; i<seriesCount; i++) { 
     678      setSeries(f0, i); 
     679      reader.setSeries(f0, i); 
     680      width[i] = reader.getSizeX(f0); 
     681      height[i] = reader.getSizeY(f0); 
     682      imagesPerFile[i] = reader.getImageCount(f0); 
     683      totalImages[i] = files.length * imagesPerFile[i]; 
     684      /* debug */ System.out.println("setting image count to " + 
     685        imagesPerFile[i] + " for series " + getSeries(f0)); 
     686      order[i] = reader.getDimensionOrder(f0); 
     687      sizeZ[i] = reader.getSizeZ(f0); 
     688      sizeC[i] = reader.getSizeC(f0); 
     689      sizeT[i] = reader.getSizeT(f0); 
     690    } 
     691    setSeries(f0, oldSeries); 
    661692    boolean certain = reader.isOrderCertain(f0); 
    662693 
    663694    // guess at dimensions corresponding to file numbering 
    664     ag = new AxisGuesser(fp, order, sizeZ, sizeT, sizeC, certain); 
     695    for (int i=0; i<seriesCount; i++) { 
     696      ag[i] = new AxisGuesser(fp, order[i], sizeZ[i], sizeT[i], sizeC[i],  
     697        certain); 
     698    } 
    665699 
    666700    // order may need to be adjusted 
    667     order = ag.getAdjustedOrder(); 
    668     swapDimensions(currentId, order); 
     701    for (int i=0; i<seriesCount; i++) { 
     702      setSeries(f0, i); 
     703      order[i] = ag[i].getAdjustedOrder(); 
     704      swapDimensions(currentId, order[i]); 
     705    } 
     706    setSeries(f0, oldSeries); 
    669707  } 
    670708 
    671709  /** Computes axis length arrays, and total axis lengths. */ 
    672710  protected void computeAxisLengths() throws FormatException, IOException { 
     711    int sno = getSeries(currentId); 
     712     
    673713    int[] count = fp.getCount(); 
    674     int[] axes = ag.getAxisTypes(); 
    675     int numZ = ag.getAxisCountZ(); 
    676     int numC = ag.getAxisCountC(); 
    677     int numT = ag.getAxisCountT(); 
    678     totalSizeZ = sizeZ; 
    679     totalSizeC = sizeC; 
    680     totalSizeT = sizeT; 
    681     lenZ = new int[numZ + 1]; 
    682     lenC = new int[numC + 1]; 
    683     lenT = new int[numT + 1]; 
    684     lenZ[0] = sizeZ; 
    685     lenC[0] = sizeC; 
    686     lenT[0] = sizeT; 
     714    int[] axes = ag[sno].getAxisTypes(); 
     715    int numZ = ag[sno].getAxisCountZ(); 
     716    int numC = ag[sno].getAxisCountC(); 
     717    int numT = ag[sno].getAxisCountT(); 
     718     
     719    totalSizeZ[sno] = sizeZ[sno]; 
     720    totalSizeC[sno] = sizeC[sno]; 
     721    totalSizeT[sno] = sizeT[sno]; 
     722    lenZ[sno] = new int[numZ + 1]; 
     723    lenC[sno] = new int[numC + 1]; 
     724    lenT[sno] = new int[numT + 1]; 
     725    lenZ[sno][0] = sizeZ[sno]; 
     726    lenC[sno][0] = sizeC[sno]; 
     727    lenT[sno][0] = sizeT[sno]; 
    687728    int z = 1, c = 1, t = 1; 
    688729    for (int i=0; i<axes.length; i++) { 
    689730      switch (axes[i]) { 
    690731        case AxisGuesser.Z_AXIS: 
    691           totalSizeZ *= count[i]; 
    692           lenZ[z++] = count[i]; 
     732          totalSizeZ[sno] *= count[i]; 
     733          lenZ[sno][z++] = count[i]; 
    693734          break; 
    694735        case AxisGuesser.C_AXIS: 
    695           totalSizeC *= count[i]; 
    696           lenC[c++] = count[i]; 
     736          totalSizeC[sno] *= count[i]; 
     737          lenC[sno][c++] = count[i]; 
    697738          break; 
    698739        case AxisGuesser.T_AXIS: 
    699           totalSizeT *= count[i]; 
    700           lenT[t++] = count[i]; 
     740          totalSizeT[sno] *= count[i]; 
     741          lenT[sno][t++] = count[i]; 
    701742          break; 
    702743        default: 
     
    711752    boolean little = reader.isLittleEndian(f0); 
    712753    MetadataStore s = reader.getMetadataStore(f0); 
    713     s.setPixels(new Integer(width), new Integer(height), 
    714       new Integer(totalSizeZ), new Integer(totalSizeC), 
    715       new Integer(totalSizeT), new Integer(pixelType), 
    716       new Boolean(!little), order, null); 
     754    s.setPixels(new Integer(width[sno]), new Integer(height[sno]), 
     755      new Integer(totalSizeZ[sno]), new Integer(totalSizeC[sno]), 
     756      new Integer(totalSizeT[sno]), new Integer(pixelType), 
     757      new Boolean(!little), order[sno], new Integer(sno)); 
    717758  } 
    718759 
     
    727768  { 
    728769    if (!id.equals(currentId)) initFile(id); 
    729  
    730     int[] axes = ag.getAxisTypes(); 
     770    int sno = getSeries(id); 
     771 
     772    int[] axes = ag[sno].getAxisTypes(); 
    731773    int[] count = fp.getCount(); 
    732774 
    733775    // get Z, C and T positions 
    734776    int[] zct = getZCTCoords(id, no); 
    735     int[] posZ = rasterToPosition(lenZ, zct[0]); 
    736     int[] posC = rasterToPosition(lenC, zct[1]); 
    737     int[] posT = rasterToPosition(lenT, zct[2]); 
     777    int[] posZ = rasterToPosition(lenZ[sno], zct[0]); 
     778    int[] posC = rasterToPosition(lenC[sno], zct[1]); 
     779    int[] posT = rasterToPosition(lenT[sno], zct[2]); 
    738780 
    739781    // convert Z, C and T position lists into file index and image index 
     
    750792    } 
    751793    int fno = positionToRaster(count, pos); 
    752     int ino = FormatReader.getIndex(order, sizeZ, sizeC, sizeT, 
    753       imagesPerFile, isRGB(id), posZ[0], posC[0], posT[0]); 
     794    int ino = FormatReader.getIndex(order[sno], sizeZ[sno], sizeC[sno],  
     795      sizeT[sno], imagesPerFile[sno], isRGB(id), posZ[0], posC[0], posT[0]); 
    754796 
    755797    // configure the reader, in case we haven't done this one yet 
     
    757799    readers[fno].setSeries(files[fno], reader.getSeries(files[0])); 
    758800    readers[fno].setColorTableIgnored(ignoreColorTable); 
    759     readers[fno].swapDimensions(files[fno], order); 
     801    readers[fno].swapDimensions(files[fno], order[sno]); 
    760802 
    761803    return new int[] {fno, ino}; 
     
    772814    int[] include = new int[readers.length]; 
    773815    Arrays.fill(include, -1); 
    774     for (int t=0; t<sizeT; t++) { 
    775       for (int z=0; z<sizeZ; z++) { 
     816    for (int t=0; t<sizeT[getSeries(id)]; t++) { 
     817      for (int z=0; z<sizeZ[getSeries(id)]; z++) { 
    776818        int no = getIndex(id, z, theC, t); 
    777819        int[] q = computeIndices(id, no); 
Note: See TracChangeset for help on using the changeset viewer.