Skip to content

Instantly share code, notes, and snippets.

@jcasado
Created June 19, 2019 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcasado/22d89926c51ab7b23d02ba158f3bedfd to your computer and use it in GitHub Desktop.
Save jcasado/22d89926c51ab7b23d02ba158f3bedfd to your computer and use it in GitHub Desktop.
Fiji script to convert multipage TIFF files
// Prepare file formats for segmentation workflow: Ilastik + Cell Profiler + HistoCAT
// Input must be a folder with multipage TIFF files, one for each sample or core
// 19.6.2019 Julia and Nuppu
basePath = "/path/to/project/folder/";
coreStacks = "tiff/files/folder/";
for_histocat = "for_histocat/"; //Where to save Image sequences
for_ilastik = "for_ilastik/"; //Where to save .h5 files
function processCore(dir, filename, for_histocat, for_ilastik) {
// Open multipage TIFF file
run("Bio-Formats Windowless Importer", "open="+dir + filename);
// Get name
dotIndex = indexOf(filename, ".");
coreName = substring(filename, 0, dotIndex);
// Save for Histocat
newDir = for_histocat + coreName;
File.makeDirectory(newDir);
run("Image Sequence... ", "format=TIFF name="+coreName+"_ digits=2 save="+newDir+"/"+coreName+"_00.tif");
// Save for Ilastik
run("Properties...", "channels=32 slices=1 frames=1 unit=pixel pixel_width=1.0000 pixel_height=1.0000 voxel_depth=1.0000 global");
run("Export HDF5", "select="+for_ilastik+coreName+".h5 exportpath="+for_ilastik+coreName+".h5 datasetname=data compressionlevel=0 input="+filename);
close();
}
dir = basePath + coreStacks;
setBatchMode(true);
coreList = getFileList(dir);
// Iterate over all cores
for (i = 0; i < corelist.length; i++)
processCore(dir, coreList[i], basePath + for_histocat, basePath + for_ilastik);
setBatchMode(false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment