//PE AVIs to Hyperstack macro //Warn abour numerical padding of filenames, //without which there will be anamlous results... showMessageWithCancel("Padding of filenames", "NOTE: This script assumes that numerical parts of filenames are padded.\nPerkin-Elmer software generated non-padded names.\nFilenames should have names like XX001XX...XX010XX, not XX1XX....XX010XX. \nOne solution is at:\nhttps://dev.mri.cnrs.fr/projects/imagej-macros/wiki/Pad_Image_Names\nClick 'OK' to continue or 'Cancel' to stop."); //Create dialog to obtain input from user path = File.openDialog("Select a file in the directory"); inputDir = File.getDirectory(path); // Get file list in input directory //print("Path: " + path); //print("inputDir: " + inputDir); images = getFileList(inputDir); //Check for movie files in the selected directory //First get the list of AVI names and put into an array f = 0; //Need to look at file names to see how many wavelengths; populate some arrays //Old UltraView supported 5 laser lines and DIC totalWavelengths = 0; wavelengthA = newArray(""); wavelengthB = newArray(""); wavelengthC = newArray(""); wavelengthD = newArray(""); wavelengthE = newArray(""); wavelengthF = newArray(""); //There are two ways the data can be output: //(1) single AVIs are single time points through space (Z stacks); or //(2) single AVIs are single focal planes through time //The latter have "Slice" in the name, which we'll try to detect, //but to be safe We'll ask... foundSliceinName = true; for (i = 0; i < images.length; i++) { if ((indexOf(images[i], ".AVI") > 0) || (indexOf(images[i], ".avi") > 0)) { //print("Processing " + inputDir + images[i]); if (f == 0 ) { firstMovieName = images[i]; if (indexOf(firstMovieName, "Slice") > 0) { //print("Found slice descriptor in filename. Will suggest each AVI is a single slice over time."); foundSliceinName = true; } else { //print("Did not find slice descriptor in filename. Will suggest each AVI is a single time point Z stack."); foundSliceinName = false; } } f = f + 1; movieName = images[i]; if ((indexOf(images[i], "WavelengthA")) > 0){ //print("File name: " + movieName + " Wavelength A"); wavelengthA = Array.concat(wavelengthA, movieName); if (totalWavelengths < 1) {totalWavelengths = totalWavelengths + 1;} } else if ((indexOf(images[i], "WavelengthB")) > 0){ //print("Wavelength B detected"); //print("File name: " + movieName + " Wavelength B"); wavelengthB = Array.concat(wavelengthB, movieName); if (totalWavelengths < 2) {totalWavelengths = totalWavelengths + 1;} } else if ((indexOf(images[i], "WavelengthC")) > 0){ //print("File name: " + movieName + " Wavelength C"); wavelengthC = Array.concat(wavelengthC, movieName); } else if ((indexOf(images[i], "WavelengthD")) > 0){ //print("File name: " + movieName + " Wavelength D"); wavelengthD = Array.concat(wavelengthD, movieName); } else if ((indexOf(images[i], "WavelengthE")) > 0){ //print("File name: " + movieName + " Wavelength E"); wavelengthE = Array.concat(wavelengthE, movieName); } else if ((indexOf(images[i], "WavelengthF")) > 0){ //print("File name: " + movieName + " Wavelength F"); wavelengthF = Array.concat(wavelengthF, movieName); } if (f == 1) { aviNames = newArray(firstMovieName); } else { aviNames = Array.concat(aviNames, movieName); } } } if (f == 0) { showMessage("No movie files found."); exit; } //showMessage("Total AVIs found: " + f); //Dialog so user can select data structure; prepopulated with choice based on file naming. Dialog.create("Confirm AVI Data Format"); items = newArray("Each AVI is a single time point (Z stack)", "Each AVI is a single slice over time"); if (foundSliceinName) { Dialog.addRadioButtonGroup("Confirm AVI data structure:", items, 2, 1, "Each AVI is a single slice over time"); } else { Dialog.addRadioButtonGroup("Confirm AVI data structure:", items, 2, 1, "Each AVI is a single time point (Z stack)"); } Dialog.show(); AVIDataOption = Dialog.getRadioButton(); //print("AVI Data option: " + AVIDataOption); if (AVIDataOption == "Each AVI is a single time point (Z stack)") { stacksAreZSlices = true; //print("AVIDataString is true"); } else { stacksAreZSlices = false; //print("AVIDataString is false"); } setBatchMode(true); //Open the first AVI and get the number of slices run("AVI...", "avi=[" + inputDir + firstMovieName + "] use"); focalPlanes = nSlices; //showMessage("Z planes: " + nSlices); close; setBatchMode(false); //print ("First movie name: " + firstMovieName); //print ("Last movie name: " + movieName); print("Channels: " + totalWavelengths); print("Focal planes: " + focalPlanes); timePoints = f/totalWavelengths; print("Time points: " + timePoints);" setBatchMode(true); print("Concatenating AVIs..."); for (i = 0; i < f; i++) { //print(inputDir + aviNames[i]); run("AVI...", "avi=[" + inputDir + aviNames[i] + "] use"); } run("Concatenate...", "all_open"); if (stacksAreZSlices == true) { print("Creating hyperstack. Single AVIs are Z stacks..."); run("Stack to Hyperstack...", "order=xyztc (default) channels=" + totalWavelengths + " slices=" + focalPlanes + " frames=" + timePoints); } else { print("Creating hyperstack. Single AVIs are single slices through time..."); run("Stack to Hyperstack...", "order=xytzc channels=" + totalWavelengths + " slices=" + focalPlanes + " frames=" + timePoints); } rename("AVIs"); setBatchMode(false); print("Complete.");