//Egeblad lab's: // _____ __ __ _ _ _ // | __ \ \ \ / / | | | | | | // | | | | ___ _____\ \ /\ / /__ | |__ | |__ | | ___ _ __ // | | | |/ _ \______\ \/ \/ / _ \| '_ \| '_ \| |/ _ \ '__| // | |__| | __/ \ /\ / (_) | |_) | |_) | | __/ | // |_____/ \___| \/ \/ \___/|_.__/|_.__/|_|\___|_| //bUnwarpJ is a pre-requisite for this. If not installed, please install first. function getBar(p1, p2) { n = 20; bar1 = "--------------------"; bar2 = "********************"; index = round(n*(p1/p2)); if (index<1) index = 1; if (index>n-1) index = n-1; return substring(bar2, 0, index) + substring(bar1, index+1, n); } title = "Expt1"; Dialog.create("Egeblad lab's De-wobbler"); Dialog.addString("Name your experiment:", title); Dialog.addChoice("Quality:", newArray("low", "high", "super")); Dialog.addChoice("Reference frame:", newArray("first", "previous")); Dialog.addCheckbox("Save temporary files", false); Dialog.addCheckbox("Apply alignment in time?", true); Dialog.addCheckbox("Reduce dimensions? (speeds up)", false); Dialog.addCheckbox("Reduce noise?", true); Dialog.show(); title = Dialog.getString(); quality = Dialog.getChoice(); if (quality == "low") { quality=0; } else if (quality == "high") { quality=1; } else { quality=2; } prevframe = Dialog.getChoice(); if (prevframe == "previous") { prevframe=1; } else { prevframe=0; } saveindiv = Dialog.getCheckbox(); align = Dialog.getCheckbox(); reducedim = Dialog.getCheckbox(); reducenoise = Dialog.getCheckbox(); 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 (saveindiv==1) { if (File.exists(indivpath)==false) { File.makeDirectory(indivpath); } } else { print(""); } print("Starting wobblyness compensation..."); print(""); if (reducedim==1) { print("You chose to reduce dimensions"); run("Size...", "width=512 height=512 constrain average interpolation=Bilinear"); } else { print("You chose not to reduce dimensions"); } rename("kkfu"); if (reducenoise==1) { print("You chose to reduce noise."); print("Removing bright outliers"); print(""); run("Remove Outliers...", "radius=4 threshold=50 which=Bright stack"); print("-done-"); print(""); print("Applying median filter..."); print(""); run("Median...", "radius=2 stack"); print("-done-"); print(""); print("Applying Background substraction"); print(""); run("Subtract Background...", "rolling=100 stack"); print("-done-"); print(""); } else { print("You chose NOT to reduce noise."); } if (align==1) { print("Aligning stack in time"); print(""); 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=Rigid interpolate"); print("-done-"); print(""); } else { print("You didn't want to align your images in t"); } rename("movie"); run("Duplicate...", "duplicate range=1-1 use"); rename("referenceframe"); if (align==1) { selectWindow("kkfu"); close(); } else { print(""); } selectWindow("movie"); run("AVI... ", "compression=JPEG frame=10 save="+path+File.separator+title+"_orig.avi"); slices=nSlices; print("YOU HAVE "+slices+" SLICES"); print(""); print("------------------------"); print("STARTING ALIGNMENT PHASE"); print("------------------------"); print(""); progress_title = "[Progress]"; run("Text Window...", "name="+ progress_title +" width=25 height=2 monospaced"); slices=nSlices; print("YOU HAVE "+slices+" NUMBER OF SLICES"); for (i = 1; i < (slices+1); i++) { frame=i; percent=(i*100)/slices; //to convert the nSlices in a percent to show in the progressbar print(progress_title, "\\Update:"+frame+"/"+slices+" ("+(frame*100)/slices+"%)\n"+getBar(frame, slices)); print(""); print("---------------------------"); print("---------------------------"); print("Processing slide "+frame+" of "+slices); print("---------------------------"); print("---------------------------"); selectWindow("movie"); run("Duplicate...", "duplicate range="+i+"-"+i); rename("target"); run("Extract SIFT Correspondences", "source_image=referenceframe target_image=target initial_gaussian_blur=5 steps_per_scale_octave=3 minimum_image_size=64 maximum_image_size=1024 feature_descriptor_size=5 feature_descriptor_orientation_bins=20 closest/next_closest_ratio=0.92 filter maximal_alignment_error=25 minimal_inlier_ratio=0.05 minimal_number_of_inliers=7 expected_transformation=Similarity"); if (quality==1) { print("You chose high quality"); run("bUnwarpJ", "source_image=referenceframe target_image=target registration=Accurate image_subsample_factor=0 initial_deformation=[Very Coarse] final_deformation=[Very Fine] divergence_weight=0 curl_weight=0 landmark_weight=0 image_weight=1 consistency_weight=10 stop_threshold=0.01"); } else if (quality==2) { print("You chose super high quality"); run("bUnwarpJ", "source_image=referenceframe target_image=target registration=Accurate image_subsample_factor=0 initial_deformation=[Very Coarse] final_deformation=[Super Fine] divergence_weight=0 curl_weight=0 landmark_weight=0 image_weight=1 consistency_weight=10 stop_threshold=0.01"); } else { print("You chose coarse quality"); run("bUnwarpJ", "source_image=referenceframe target_image=target registration=Fast image_subsample_factor=0 initial_deformation=[Very Coarse] final_deformation=Coarse divergence_weight=0 curl_weight=0 landmark_weight=0 image_weight=1 consistency_weight=10 stop_threshold=0.01"); } wait(1000); selectWindow("Registered Source Image"); close(); selectWindow("target"); close(); selectWindow("Registered Target Image"); rename("reg"+i); if (saveindiv==1) { saveAs("Tiff", indivpath+File.separator+title+"_frame_"+i+".tif"); rename("reg"+i); } else { print("You chose not to save your files as we go"); } if (prevframe==1) { //from here to use previous frame to compute wrapping print("You chose reference to be the previous frame"); selectWindow("reg"+i); run("Duplicate...", "title=newref duplicate range=1-1"); selectWindow("referenceframe"); close(); selectWindow("newref"); rename("referenceframe"); run("RGB Color"); } else { print("You chose reference to be the first frame"); } } selectWindow("referenceframe"); close(); selectWindow("movie"); close(); run("Concatenate...", "all_open open"); run("Duplicate...", "duplicate slices=1"); saveAs("Tiff", path+File.separator+title+"_computed.tif"); run("AVI... ", "compression=JPEG frame=10 save="+path+File.separator+title+"_computed.avi"); print(""); print("Done.");