/* * BlindAnalysis.ijm * This macro will take a directory of TIFFs * strip the label from them * save each with a randomised filename * log the association between original file and blind analysis file * Adapted from: * Shuffler macro by Christophe Leterrier v1.0 26/06/08 * Modified by Chris Gell 07/09/2018 Adapted from https://github.com/quantixed/imagej-macros/blob/master/Blind_Analysis.ijm * Only works with .tif files and only parses subfolders of the selected folder. All subfolders must have a tif in them. */ macro "Blind Analysis" { DIR_PATH=getDirectory("Select a directory"); rootDIR_PATH=DIR_PATH print("\\Clear"); print("root DIR_PATH :"+DIR_PATH); containsRandoms=newArray(1000); // Create the output folder OUTPUT_DIR=rootDIR_PATH+"BLIND"+File.separator; File.makeDirectory(OUTPUT_DIR); f=File.open(OUTPUT_DIR+"log.txt"); rootALL_NAMES=getFileList(DIR_PATH); totalNumImages=rootALL_NAMES.length; //////////////////// parse through the subfolder for (j=0; j0) { IM_NUMBER=IM_NUMBER+1; } } IM_NAMES=newArray(IM_NUMBER); IM_EXT=newArray(IM_NUMBER); // Test all files for extension j=0; for (i=0; i0) { IM_NAMES[j]=ALL_NAMES[i]; j=j+1; } } // Generate a permutation array of length IM_NUMBER IM_PERM=newArray(IM_NUMBER); for(j=0; j 1 || ff > 1) { stripFrameByFrame(cc,ss,ff); } else { setMetadata("Label", ""); // strips the label data from the image for blinding purposes } save(OUTPUT_PATH_PERM); print(f,IM_NAMES[j]+"\t"+IM_PERM_NAMES[j]); close(); } setBatchMode("exit and display"); showStatus("finished"); } function stripFrameByFrame(cc,ss,ff) { if(Stack.isHyperstack) { for(i = 0; i < ss; i++){ Stack.setSlice(i+1); for(j = 0; j < ff; j++) { Stack.setFrame(j+1); for(k = 0; k < cc; k++) { Stack.setChannel(k+1); setMetadata("Label", ""); } } } } else if(cc > 1 && ss == 1 && ff == 1) { setMetadata("Label", ""); } else if(cc == 1 && ss > 1) { for(i = 0; i < ss; i++){ setSlice(i+1); setMetadata("Label", ""); } } else if(cc == 1 && ff > 1) { for(i = 0; i < ff; i++){ setSlice(i+1); setMetadata("Label", ""); } } } }