requires("1.53f"); // MAIN CODE // Choice of Image Type // Get Images Directory and number of junction folders Imdir=getDirectory("Image Junction Folder"); jctn = getFileList(Imdir); Nbj=lengthOf(jctn); // Define a saving directory pathsave=getDirectory("Saving Folder"); types = newArray("Nikkon nd2","Leica lif or Zeiss czi","TIFF"); Dialog.create("Image Type"); Dialog.addMessage("Select the Type of Images"); Dialog.addChoice("Images", types); Dialog.show(); TypeIm=Dialog.getChoice(); if (TypeIm=="Leica lif or Zeiss czi") { TypeIm="Leica lif"; } //Use of the functions (at the end of the code) for extracting pixel information from images or dialog boxes ChanPix=selectChannelandPix(TypeIm); presyn=ChanPix[0]; chan_presyn=ChanPix[1]; postsyn=ChanPix[2]; chan_postsyn=ChanPix[3]; xypix=ChanPix[4]; zstep=ChanPix[5]; //Batchmode true to improve processing speed setBatchMode(true); for (i = 0; i < Nbj ; i++) { // Open stack of the junction images according to the Image Type and extracting the presynaptic image stack (presyn) and the postsynaptic image stack (postsyn) if (TypeIm == "Nikkon nd2") { ListImJcn=getFileList(Imdir); open(Imdir+ListImJcn[i]); extractChannel_bioFormat(chan_presyn,chan_postsyn); getVoxelSize(width, height, depth, unit); xypix=width; zstep=depth; } else if (TypeIm == "Leica lif") { ListImJcn=getFileList(Imdir); Junction=Imdir+ListImJcn[i]; run("Bio-Formats Importer", "open="+Junction+" autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT"); extractChannel_bioFormat(chan_presyn,chan_postsyn); getVoxelSize(width, height, depth, unit); xypix=width; zstep=depth; } else { ListImJcn=getFileList(Imdir+jctn[i]); Junction=Imdir+jctn[i]; run("Image Sequence...", "dir="+Junction+" sort"); run("Set Scale...", "distance=1 known="+xypix+" pixel=1 unit=um"); extractChannel_RGB(chan_presyn,chan_postsyn); N=lengthOf(jctn[i]); jctn[i]=substring(jctn[i],0, N-1); } selectWindow("stack_presyn"); rename(presyn); selectWindow("stack_postsyn"); rename(postsyn); //---------------------------------------------------------------------- // Creating a directory for each junction pathjctn=pathsave+jctn[i]; File.makeDirectory(pathjctn); // Calculating the volume of the postsynaptic part of the junction selectWindow(postsyn); run("Duplicate...", "duplicate"); name2=postsyn+"-2"; rename(name2); selectWindow(postsyn); Midslice=nSlices/2+1; setSlice(Midslice); //Otsu Thresholding setAutoThreshold("Otsu"); setOption("BlackBackground", false); run("Convert to Mask", "method=Otsu background=Dark"); run("Invert","stack"); run("Dilate","stack"); // Analyzing surfaces run("Set Measurements...", "area stack display redirect=None decimal=3"); run("Analyze Particles...", "size=20-Infinity pixel show=Masks display exclude stack"); // Summing all the surface area of detected surfaces = Volume of bungatoxin staining //Error message in case the signal is not automatically detected R=isOpen("Results"); if (R==0) { print("PostSynaptic signal is too low to be processed automatically."); } else { //Calculating presynaptic volume by summing all surfaces detected, and multiplying by zstep. n=getValue("results.count"); post=0; for(k=0; k