// bfOpenAsHyperstack.txt
// Written by Wayne Rasband
// Last updated on 2008 May 9

// Uses the Bio-Formats macro extensions to open a file as a hyperstack.

requires("1.41c");

path = File.openDialog("Select a File");
name = File.getName(path);

run("Bio-Formats Macro Extensions");
Ext.setId(path);
Ext.getCurrentFile(file);
Ext.getSizeX(sizeX);
Ext.getSizeY(sizeY);
Ext.getSizeC(sizeC);
Ext.getSizeZ(sizeZ);
Ext.getSizeT(sizeT);
Ext.getImageCount(n);
//print(file+":", sizeX, sizeY, sizeC, sizeZ, sizeT);
setBatchMode(true);
for (i=0; i<n; i++) {
  showProgress(i, n);
  Ext.openImage("plane "+i, i);
  if (i==0)
    stack = getImageID;
  else {
    run("Copy");
    close;
    selectImage(stack);
    run("Add Slice");
    run("Paste");
  }
}
rename(name);
if (nSlices>1) {
  Stack.setDimensions(sizeC, sizeZ, sizeT);
  if (sizeC>1) {
    if (sizeC==3&&sizeC==nSlices)
      mode = "Composite";
    else
      mode = "Color";
    run("Make Composite", "display="+mode);

  }
  setOption("OpenAsHyperStack", true);
}
setBatchMode(false);
Ext.close();
