//Egeblad lab's: // ______ _ _ // |___ / | (_) // / /_____ __ _| |_ __ _ _ __ ___ _ __ // / /______/ _` | | |/ _` | '_ \ / _ \ '__| // / /__ | (_| | | | (_| | | | | __/ | // /_____| \__,_|_|_|\__, |_| |_|\___|_| // __/ | // |___/ //Please, install requirementes prior to usage: //TemplateMatching: add this to the update site list: http://sites.imagej.net/Template_Matching/ Dialog.create("Egeblad lab's Z-aligner"); Dialog.addChoice("What kind of alignment?", newArray("SIFT", "TemplateMatching")); Dialog.addChoice("What algorithm (for SIFT)?", newArray("Translation", "Rigid", "Similarity", "Affine")); Dialog.show(); choice = Dialog.getChoice(); alg = Dialog.getChoice(); waitForUser("Attention", "In the next dialog, choose the folder where you want to save your results."); path = getDirectory("Choose where to save the results"); indivpath = path+File.separator+"indiv_files"; if (File.exists(indivpath)==false) { File.makeDirectory(indivpath); } print("You chose algorithm: "+alg); if (choice == "TemplateMatching") { choice=0; } else { choice=1; } rename("origin"); Stack.getDimensions(width, height, channels, slices, frames); rectx1 = width*5/100; rectx2 = width-((width*5/100)*2); recty1 = height*5/100; recty2 = height-((height*5/100)*2); for (i = 1; i < (frames+1); i++) { print("-------------------------------"); print("Processing frame "+i+" of "+frames); print("-------------------------------"); selectWindow("origin"); run("Duplicate...", "duplicate frames="+i+"-"+i); if (choice == 0) { print("I'm going to do TemplateMatching"); makeRectangle(rectx1, recty1, rectx2, recty2); run("Align slices in stack...", "method=5 windowsizex="+parseInt(rectx2)+" windowsizey="+parseInt(recty2)+" x0="+parseInt(rectx1)+" y0="+parseInt(recty1)+" swindow=0 subpixel=false itpmethod=0 ref.slice=1 show=true"); } else { print("I'm going to do SIFT"); run("Linear Stack Alignment with SIFT", "initial_gaussian_blur=1.60 steps_per_scale_octave=3 minimum_image_size=64 maximum_image_size=1024 feature_descriptor_size=4 feature_descriptor_orientation_bins=8 closest/next_closest_ratio=0.92 maximal_alignment_error=25 inlier_ratio=0.05 expected_transformation="+alg+" interpolate"); run("Stack to Hyperstack...", "order=xyczt(default) channels=1 slices="+slices+" frames=1 display=Grayscale"); selectWindow("origin-1"); close(); } saveAs("Tiff", indivpath+File.separator+"frame_"+i+".tif"); } selectWindow("origin"); saveAs("Tiff", path+File.separator+"original.tif"); close(); run("Concatenate...", "all_open open"); saveAs("Tiff", path+File.separator+"processed.tif"); print("Done.");