//(c)Jan Wisniewski, Experimental Immunology Branch, NCI, NIH, Bethesda, MD //This Macro identifies spots across whole image(including stacks) or in selected cells/regions //It will process all images in the initial folder and all slices in the stack //Measures dot intensity and corrects it for local background, estimates SNR of each spot //Outputs spreadsheet with results and images showing outlined measured spots print("Photometry of Diffraction-Limited Spots for ImageJ\nJan Wisniewski, Experimental Immunology Branch\nNational Cancer Institute, NIH, Bethesda, Maryland"); getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec); print(""); print("run: ", month, "/", dayOfMonth, "/", year, " at ", hour, ":", minute); print(""); mac=getBoolean("Are you using Mac?"); //specify folders //if(mac==1) {waitForUser("Choose a Temporary Directory for Image Series"); } //output=getDirectory("Choose a Temporary Directory for Image Series"); if(mac==1) {waitForUser("_Choose a Results Folder"); } rsts=getDirectory("_Choose a Results Folder"); if(mac==1) {waitForUser("Select a Source Directory"); } input=getDirectory("Select a Source Directory"); print("source: ", input); print("results: ", rsts); print(""); NAMES=getFileList(input); run("Set Measurements...", "area mean standard center median display redirect=None decimal=2"); //open test image run("Bio-Formats (Windowless)"); ttt=File.name; rename("x"); getDimensions(width, height, channels, slices, frames); chns=channels; stks=slices*frames; if(chns==1) {run("Enhance Contrast", "saturated=0.10"); Dialog.create("Name the target"); Dialog.addString("Name of the Feature: ", " "); itemx=newArray("Grays", "Blue", "Cyan", "Green", "Yellow", "Red", "Magenta"); Dialog.addChoice("Display color: ", itemx, "Grays"); Dialog.show(); CN1=Dialog.getString(); CC1=Dialog.getChoice(); C1="single"; rename(CN1); run(CC1); } if(chns>1) {run("Split Channels"); run("Tile"); selectWindow("C1-x"); run("Enhance Contrast", "saturated=0.10"); selectWindow("C2-x"); run("Enhance Contrast", "saturated=0.10"); if(chns>2) {selectWindow("C3-x"); run("Enhance Contrast", "saturated=0.10"); } if(chns>3) {selectWindow("C4-x"); run("Enhance Contrast", "saturated=0.10"); } if(chns==2) {Dialog.create("Name the target(s)"); Dialog.addString("Name of the 1st Feature: ", " "); items=newArray("C1-x", "C2-x"); Dialog.addRadioButtonGroup("Choose a Channel: ", items, 1, 2, "C1-x"); itemx=newArray("Grays", "Blue", "Cyan", "Green", "Yellow", "Red", "Magenta"); Dialog.addChoice("Display color: ", itemx, "Grays"); Dialog.addMessage(" * * * * *"); Dialog.addString("Name of the 2nd Feature: ", " "); items2=newArray("C1-x", "C2-x", "none"); Dialog.addRadioButtonGroup("Choose a Channel: ", items2, 1, 3, "none"); Dialog.addChoice("Display color: ", itemx, "n/a"); Dialog.show(); CN1=Dialog.getString(); C1=Dialog.getRadioButton(); CC1=Dialog.getChoice(); CN2=Dialog.getString(); C2=Dialog.getRadioButton(); CC2=Dialog.getChoice(); selectWindow(C1); run("Duplicate...", "duplicate"); rename(CN1); run(CC1); if(C2=="none") { } else {selectWindow(C2); run("Duplicate...", "duplicate"); rename(CN2); run(CC2); } close("C1-x"); close("C2-x"); run("Tile"); } if(chns==3) {Dialog.create("Name the target(s)"); Dialog.addString("Name of the 1st Feature: ", " "); items3=newArray("C1-x", "C2-x", "C3-x"); Dialog.addRadioButtonGroup("Choose a Channel: ", items3, 1, 3, "C1-x"); itemx=newArray("Grays", "Blue", "Cyan", "Green", "Yellow", "Red", "Magenta"); Dialog.addChoice("Display color: ", itemx, "Grays"); Dialog.addMessage(" * * * * *"); Dialog.addString("Name of the 2nd Feature: ", " "); items4=newArray("C1-x", "C2-x", "C3-x", "none"); Dialog.addRadioButtonGroup("Choose a Channel: ", items4, 1, 4, "none"); Dialog.addChoice("Display color: ", itemx, "n/a"); Dialog.addMessage(" * * * * *"); Dialog.addString("Name of the 3rd Feature: ", " "); Dialog.addRadioButtonGroup("Choose a Channel: ", items4, 1, 4, "none"); Dialog.addChoice("Display color: ", itemx, "n/a"); Dialog.show(); CN1=Dialog.getString(); C1=Dialog.getRadioButton(); CC1=Dialog.getChoice(); CN2=Dialog.getString(); C2=Dialog.getRadioButton(); CC2=Dialog.getChoice(); CN3=Dialog.getString(); C3=Dialog.getRadioButton(); CC3=Dialog.getChoice(); selectWindow(C1); run("Duplicate...", "duplicate"); rename(CN1); run(CC1); if(C2=="none") { } else {selectWindow(C2); run("Duplicate...", "duplicate"); rename(CN2); run(CC2); } if(C3=="none") { } else {selectWindow(C3); run("Duplicate...", "duplicate"); rename(CN3); run(CC3); } close("C1-x"); close("C2-x"); close("C3-x"); run("Tile"); } if(chns==4) {Dialog.create("Name the target(s)"); Dialog.addString("Name of the 1st Feature: ", " "); items5=newArray("C1-x", "C2-x", "C3-x", "C4-x"); Dialog.addRadioButtonGroup("Choose a Channel: ", items5, 1, 4, "C1-x"); itemx=newArray("Grays", "Blue", "Cyan", "Green", "Yellow", "Red", "Magenta"); Dialog.addChoice("Display color: ", itemx, "Grays"); Dialog.addMessage(" * * * * *"); Dialog.addString("Name of the 2nd Feature: ", " "); items6=newArray("C1-x", "C2-x", "C3-x", "C4-x", "none"); Dialog.addRadioButtonGroup("Choose a Channel: ", items6, 1, 5, "none"); Dialog.addChoice("Display color: ", itemx, "n/a"); Dialog.addMessage(" * * * * *"); Dialog.addString("Name of the 3rd Feature: ", " "); Dialog.addRadioButtonGroup("Choose a Channel: ", items6, 1, 5, "none"); Dialog.addChoice("Display color: ", itemx, "n/a"); Dialog.addMessage(" * * * * *"); Dialog.addString("Name of the 4th Feature: ", " "); Dialog.addRadioButtonGroup("Choose a Channel: ", items6, 1, 5, "none"); Dialog.addChoice("Display color: ", itemx, "n/a"); Dialog.show(); CN1=Dialog.getString(); C1=Dialog.getRadioButton(); CC1=Dialog.getChoice(); CN2=Dialog.getString(); C2=Dialog.getRadioButton(); CC2=Dialog.getChoice(); CN3=Dialog.getString(); C3=Dialog.getRadioButton(); CC3=Dialog.getChoice(); CN4=Dialog.getString(); C4=Dialog.getRadioButton(); CC4=Dialog.getChoice(); selectWindow(C1); run("Duplicate...", "duplicate"); rename(CN1); run(CC1); if(C2=="none") { } else {selectWindow(C2); run("Duplicate...", "duplicate"); rename(CN2); run(CC2); } if(C3=="none") { } else {selectWindow(C3); run("Duplicate...", "duplicate"); rename(CN3); run(CC3); } if(C4=="none") { } else {selectWindow(C4); run("Duplicate...", "duplicate"); rename(CN4); run(CC4); } close("C1-x"); close("C2-x"); close("C3-x"); close("C4-x"); run("Tile"); } } clls=getBoolean("Are you going to analyze whole image?", "Yes", "No - Individual cells will be selected"); if(clls==1) {cllch="whole image"; Dialog.create("Margin to crop?"); Dialog.addNumber("How wide is margin to be cropped (pixels)?", 0); Dialog.show(); marg=Dialog.getNumber(); } else {cllch="selected cells"; } print("analysis method:", cllch); print(""); selectWindow(CN1); fou1=getBoolean("Is the dot superimposed on a diffuse (e.g. nuclear) background?"); if(fou1==1) {run("Bandpass Filter...", "filter_large=4 filter_small=1 suppress=None tolerance=5"); print(" FFT-filtered to suppress strong diffuse local background"); } run("Point Tool...", "type=Circle color=Red size=[Extra Large] label counter=0"); run("Find Maxima...", "prominence=500 output=[Point Selection]"); dtn1=getBoolean("Are dots selected properly?"); if(dtn1==1) {prom=500; } if(dtn1==0) {Dialog.create("Set detection level"); Dialog.addNumber("Enter coefficient to adjust detection sensitivity / If too many dots detected: enter 1.5 or more / If too few: 0.66 or less ", 1); Dialog.show(); coef=Dialog.getNumber(); prot1=coef*500; run("Select None"); run("Find Maxima...", "prominence=prot1 output=[Point Selection]"); dtn2=getBoolean("Are dots selected properly?"); if(dtn2==1) {prom=prot1; } if(dtn2==0) {Dialog.create("Set detection level - last try"); Dialog.addNumber("Enter coefficient to adjust detection sensitivity (with regard to the previous try!) If too many dots detected: enter 1.5 or more / If too few: 0.66 or less ", 1); Dialog.show(); coeg=Dialog.getNumber(); prot2=coeg*prot1; run("Select None"); run("Find Maxima...", "prominence=prot2 output=[Point Selection]"); dtn3=getBoolean("Are dots selected properly?"); if(dtn3==1) {prom=prot2; } if(dtn3==0) {waitForUser("Aborting run"); close(); end } } } run("Select None"); print("test image: ", ttt); print(" channel:", C1, " target name:", CN1, " display:", CC1); setTool("zoom"); waitForUser("Zoom-in on a representative dot until pixels are clearly visible"); setTool("rectangle"); waitForUser("Draw a generous rectangle around a single representative dot"); run("Find Maxima...", "prominence=prom output=List"); run("Select None"); xxs=getResult("X"); yys=getResult("Y"); close("Results"); makeOval(xxs-3, yys-3, 7, 7); phbk=5; run("Make Band...", "band=0.5"); apert1=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes (use defaults)", "No - modify in the next Dialog box"); if(apert1==1) {phap=7; ap=3; } if(apert1==0) {Dialog.create("Photometry parameters"); Dialog.addMessage("Change default values below if needed"); Dialog.addNumber("Diameter of central aperture in pixels (min=3, max=10)", 7); Dialog.show(); phap2=Dialog.getNumber(); ap2=phap2/2-1; makeOval(xxs-ap2, yys-ap2, phap2, phap2); run("Make Band...", "band=0.5"); apert2=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes - Proceed to photometric measurements", "No - modify on more time"); if(apert2==1) {phap=phap2; ap=ap2; } if(apert2==0) {Dialog.create("Photometry parameters - Last Try"); Dialog.addMessage("Adjust one more time"); Dialog.addNumber("Diameter of central aperture in pixels (min=3, max=10)", phap2); Dialog.show(); phap3=Dialog.getNumber(); ap3=phap3/2-1; makeOval(xxs-ap3, yys-ap3, phap3, phap3); run("Make Band...", "band=0.5"); apert3=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes - Proceed to photometric measurements", "No - Macro will abort!"); if(apert3==1) {phap=phap3; ap=ap3; } if(apert3==0) {close(); end; } } } if(phap<7) {if(phap<3) {waitForUser("Aperture too small !!!"); end } if(phap==3) {apar=9; } else {apar=phap*phap-4; } } if(phap>6) {if(phap>10) {waitForUser("Aperture too large !!!"); end } if(phap==10) {apar=80; } else {apar=phap*phap-12; } } print(" detection limit:", prom, " aperture size:", phap, " aperture area: ", apar, " width of local background band:", phbk); close(CN1); if(chns>1) {if(C2=="none") { } else {selectWindow(CN2); fou2=getBoolean("Is the dot superimposed on a diffuse (e.g. nuclear) background?"); if(fou2==1) {run("Bandpass Filter...", "filter_large=4 filter_small=1 suppress=None tolerance=5"); print(" FFT-filtered to suppress strong diffuse local background"); } run("Point Tool...", "type=Circle color=Red size=[Extra Large] label counter=0"); run("Find Maxima...", "prominence=500 output=[Point Selection]"); dto1=getBoolean("Are dots selected properly?"); if(dto1==1) {promo=500; } if(dto1==0) {Dialog.create("Set detection level"); Dialog.addNumber("Enter coefficient to adjust detection sensitivity / If too many dots detected: enter 1.5 or more / If too few: 0.66 or less ", 1); Dialog.show(); coefo=Dialog.getNumber(); proto1=coefo*500; run("Select None"); run("Find Maxima...", "prominence=proto1 output=[Point Selection]"); dto2=getBoolean("Are dots selected properly?"); if(dto2==1) {promo=proto1; } if(dto2==0) {Dialog.create("Set detection level - last try"); Dialog.addNumber("Enter coefficient to adjust detection sensitivity (with regard to the previous try!) If too many dots detected: enter 1.5 or more / If too few: 0.66 or less ", 1); Dialog.show(); coego=Dialog.getNumber(); proto2=coego*proto1; run("Select None"); run("Find Maxima...", "prominence=proto2 output=[Point Selection]"); dto3=getBoolean("Are dots selected properly?"); if(dto3==1) {promo=proto2; } if(dto3==0) {waitForUser("Aborting run"); close(); end } } } run("Select None"); print(" channel:", C2, " target name:", CN2, " display:", CC2); setTool("zoom"); waitForUser("Zoom-in on a representative dot until pixels are clearly visible"); setTool("rectangle"); waitForUser("Draw a generous rectangle around a single representative dot"); run("Find Maxima...", "prominence=promo output=List"); run("Select None"); xxo=getResult("X"); yyo=getResult("Y"); close("Results"); makeOval(xxo-3, yyo-3, 7, 7); phbk=5; run("Make Band...", "band=0.5"); aperto1=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes (use defaults)", "No - modify in the next Dialog box"); if(aperto1==1) {phapo=7; apo=3; } if(aperto1==0) {Dialog.create("Photometry parameters"); Dialog.addMessage("Change default values below if needed"); Dialog.addNumber("Diameter of central aperture in pixels (min=3, max=10)", 7); Dialog.show(); phapo2=Dialog.getNumber(); apo2=phapo2/2-1; makeOval(xxo-apo2, yyo-apo2, phapo2, phapo2); run("Make Band...", "band=0.5"); aperto2=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes - Proceed to photometric measurements", "No - modify on more time"); if(aperto2==1) {phapo=phapo2; apo=apo2; } if(aperto2==0) {Dialog.create("Photometry parameters - Last Try"); Dialog.addMessage("Adjust one more time"); Dialog.addNumber("Diameter of central aperture in pixels (min=3, max=10)", phapo2); Dialog.show(); phapo3=Dialog.getNumber(); apo3=phapo3/2-1; makeOval(xxo-apo3, yyo-apo3, phapo3, phapo3); run("Make Band...", "band=0.5"); aperto3=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes - Proceed to photometric measurements", "No - Macro will abort!"); if(aperto3==1) {phapo=phapo3; apo=apo3; } if(aperto3==0) {close(); end; } } } if(phapo<7) {if(phapo<3) {waitForUser("Aperture too small !!!"); end } if(phapo==3) {aparo=9; } else {aparo=phapo*phapo-4; } } if(phapo>6) {if(phapo>10) {waitForUser("Aperture too large !!!"); end } if(phapo==10) {aparo=80; } else {aparo=phapo*phapo-12; } } print(" detection limit:", promo, " aperture size:", phapo, " aperture area: ", aparo, " width of local background band:", phbk); close(CN2); } } if(chns>2) {if(C3=="none") { } else {selectWindow(CN3); fou3=getBoolean("Is the dot superimposed on a diffuse (e.g. nuclear) background?"); if(fou3==1) {run("Bandpass Filter...", "filter_large=4 filter_small=1 suppress=None tolerance=5"); print(" FFT-filtered to suppress strong diffuse local background"); } run("Point Tool...", "type=Circle color=Red size=[Extra Large] label counter=0"); run("Find Maxima...", "prominence=500 output=[Point Selection]"); dtq1=getBoolean("Are dots selected properly?"); if(dtq1==1) {promq=500; } if(dtq1==0) {Dialog.create("Set detection level"); Dialog.addNumber("Enter coefficient to adjust detection sensitivity / If too many dots detected: enter 1.5 or more / If too few: 0.66 or less ", 1); Dialog.show(); coefq=Dialog.getNumber(); protq1=coefq*500; run("Select None"); run("Find Maxima...", "prominence=protq1 output=[Point Selection]"); dtq2=getBoolean("Are dots selected properly?"); if(dtq2==1) {promq=protq1; } if(dtq2==0) {Dialog.create("Set detection level - last try"); Dialog.addNumber("Enter coefficient to adjust detection sensitivity (with regard to the previous try!) If too many dots detected: enter 1.5 or more / If too few: 0.66 or less ", 1); Dialog.show(); coegq=Dialog.getNumber(); protq2=coegq*protq1; run("Select None"); run("Find Maxima...", "prominence=protq2 output=[Point Selection]"); dtq3=getBoolean("Are dots selected properly?"); if(dtq3==1) {promq=protq2; } if(dtq3==0) {waitForUser("Aborting run"); close(); end } } } run("Select None"); print(" channel:", C3, " target name:", CN3, " display:", CC3); setTool("zoom"); waitForUser("Zoom-in on a representative dot until pixels are clearly visible"); setTool("rectangle"); waitForUser("Draw a generous rectangle around a single representative dot"); run("Find Maxima...", "prominence=promo output=List"); run("Select None"); xxq=getResult("X"); yyq=getResult("Y"); close("Results"); makeOval(xxq-3, yyq-3, 7, 7); phbk=5; run("Make Band...", "band=0.5"); apertq1=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes (use defaults)", "No - modify in the next Dialog box"); if(apertq1==1) {phapq=7; apq=3; } if(apertq1==0) {Dialog.create("Photometry parameters"); Dialog.addMessage("Change default values below if needed"); Dialog.addNumber("Diameter of central aperture in pixels (min=3, max=10)", 7); Dialog.show(); phapq2=Dialog.getNumber(); apq2=phapq2/2-1; makeOval(xxq-apq2, yyq-apq2, phapq2, phapq2); run("Make Band...", "band=0.5"); apertq2=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes - Proceed to photometric measurements", "No - modify on more time"); if(apertq2==1) {phapq=phapq2; apq=apq2; } if(apertq2==0) {Dialog.create("Photometry parameters - Last Try"); Dialog.addMessage("Adjust one more time"); Dialog.addNumber("Diameter of central aperture in pixels (min=3, max=10)", phapq2); Dialog.show(); phapq3=Dialog.getNumber(); apq3=phapq3/2-1; makeOval(xxq-apo3, yyq-apo3, phapq3, phapq3); run("Make Band...", "band=0.5"); apertq3=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes - Proceed to photometric measurements", "No - Macro will abort!"); if(apertq3==1) {phapq=phapq3; apq=apq3; } if(apertq3==0) {close(); end; } } } if(phapq<7) {if(phapq<3) {waitForUser("Aperture too small !!!"); end } if(phapq==3) {aparq=9; } else {aparq=phapq*phapq-4; } } if(phapq>6) {if(phapq>10) {waitForUser("Aperture too large !!!"); end } if(phapq==10) {aparq=80; } else {aparq=phapo*phapq-12; } } print(" detection limit:", promq, " aperture size:", phapq, " aperture area: ", aparq, " width of local background band:", phbk); close(CN3); } } if(chns>3) {if(C4=="none") { } else {selectWindow(CN4); fou4=getBoolean("Is the dot superimposed on a diffuse (e.g. nuclear) background?"); if(fou4==1) {run("Bandpass Filter...", "filter_large=4 filter_small=1 suppress=None tolerance=5"); print(" FFT-filtered to suppress strong diffuse local background"); } run("Point Tool...", "type=Circle color=Red size=[Extra Large] label counter=0"); run("Find Maxima...", "prominence=500 output=[Point Selection]"); dtr1=getBoolean("Are dots selected properly?"); if(dtr1==1) {promr=500; } if(dtr1==0) {Dialog.create("Set detection level"); Dialog.addNumber("Enter coefficient to adjust detection sensitivity / If too many dots detected: enter 1.5 or more / If too few: 0.66 or less ", 1); Dialog.show(); coefr=Dialog.getNumber(); protr1=coefr*500; run("Select None"); run("Find Maxima...", "prominence=protr1 output=[Point Selection]"); dtr2=getBoolean("Are dots selected properly?"); if(dtr2==1) {promr=protr1; } if(dtr2==0) {Dialog.create("Set detection level - last try"); Dialog.addNumber("Enter coefficient to adjust detection sensitivity (with regard to the previous try!) If too many dots detected: enter 1.5 or more / If too few: 0.66 or less ", 1); Dialog.show(); coegr=Dialog.getNumber(); protr2=coegr*protr1; run("Select None"); run("Find Maxima...", "prominence=protr2 output=[Point Selection]"); dtr3=getBoolean("Are dots selected properly?"); if(dtr3==1) {promr=protr2; } if(dtr3==0) {waitForUser("Aborting run"); close(); end } } } run("Select None"); print(" channel:", C4, " target name:", CN4, " display:", CC4); setTool("zoom"); waitForUser("Zoom-in on a representative dot until pixels are clearly visible"); setTool("rectangle"); waitForUser("Draw a generous rectangle around a single representative dot"); run("Find Maxima...", "prominence=promo output=List"); run("Select None"); xxr=getResult("X"); yyr=getResult("Y"); close("Results"); makeOval(xxr-3, yyr-3, 7, 7); phbk=5; run("Make Band...", "band=0.5"); apertr1=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes (use defaults)", "No - modify in the next Dialog box"); if(apertr1==1) {phapr=7; apr=3; } if(apertr1==0) {Dialog.create("Photometry parameters"); Dialog.addMessage("Change default values below if needed"); Dialog.addNumber("Diameter of central aperture in pixels (min=3, max=10)", 7); Dialog.show(); phapr2=Dialog.getNumber(); apr2=phapr2/2-1; makeOval(xxr-apr2, yyr-apr2, phapr2, phapr2); run("Make Band...", "band=0.5"); apertr2=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes - Proceed to photometric measurements", "No - modify on more time"); if(apertr2==1) {phapr=phapr2; apr=apr2; } if(apertr2==0) {Dialog.create("Photometry parameters - Last Try"); Dialog.addMessage("Adjust one more time"); Dialog.addNumber("Diameter of central aperture in pixels (min=3, max=10)", phapr2); Dialog.show(); phapr3=Dialog.getNumber(); apr3=phapr3/2-1; makeOval(xxr-apo3, yyr-apo3, phapr3, phapr3); run("Make Band...", "band=0.5"); apertr3=getBoolean("Are apertures OK? (Dot is completely inside red square)", "Yes - Proceed to photometric measurements", "No - Macro will abort!"); if(apertr3==1) {phapr=phapr3; apr=apr3; } if(apertr3==0) {close(); end; } } } if(phapr<7) {if(phapr<3) {waitForUser("Aperture too small !!!"); end } if(phapr==3) {aparr=9; } else {aparq=phapq*phapq-4; } } if(phapq>6) {if(phapr>10) {waitForUser("Aperture too large !!!"); end } if(phapr==10) {aparr=80; } else {aparr=phapr*phapr-12; } } print(" detection limit:", promr, " aperture size:", phapr, " aperture area: ", aparr, " width of local background band:", phbk); close(CN4); } } //prepare image for (i=0; i1) {if(clls==1) {setTool("rectangle"); makeRectangle(marg, marg, width-marg*2, height-marg*2); run("Crop"); run("Split Channels"); selectWindow(C1); run("Duplicate...", "duplicate"); rename(CN1); run(CC1); run("Reverse"); //create temporary directory myDir1 = rsts+"temporary_"+CN1+"_images"+File.separator; File.makeDirectory(myDir1); zts=nSlices(); run("Stack to Images"); for (j = 0; j < zts; j++) {run("Select All"); run("Copy"); newImage("Untitled", "16-bit black", width-marg*2+20, height-marg*2+20, 1); wait(200); run("Paste"); run("Select None"); run("Enhance Contrast", "saturated=0.10"); saveAs("Tiff", myDir1+ttl+"_"+CN1+"_"+j+1); close(); close(); } if(C2=="none") { } else {selectWindow(C2); run("Duplicate...", "duplicate"); rename(CN2); run(CC2); run("Reverse"); //create temporary directory myDir2 = rsts+"temporary_"+CN2+"_images"+File.separator; File.makeDirectory(myDir2); run("Stack to Images"); for (j = 0; j < zts; j++) {run("Select All"); run("Copy"); newImage("Untitled", "16-bit black", width-marg*2+20, height-marg*2+20, 1); wait(200); run("Paste"); run("Select None"); run("Enhance Contrast", "saturated=0.10"); saveAs("Tiff", myDir2+ttl+"_"+CN2+"_"+j+1); close(); close(); } } if(chns>2) {if(C3=="none") { } else {selectWindow(C3); run("Duplicate...", "duplicate"); rename(CN3); run(CC3); run("Reverse"); //create temporary directory myDir3 = rsts+"temporary_"+CN3+"_images"+File.separator; File.makeDirectory(myDir3); run("Stack to Images"); for (j = 0; j < zts; j++) {run("Select All"); run("Copy"); newImage("Untitled", "16-bit black", width-marg*2+20, height-marg*2+20, 1); wait(200); run("Paste"); run("Select None"); run("Enhance Contrast", "saturated=0.10"); saveAs("Tiff", myDir3+ttl+"_"+CN3+"_"+j+1); close(); close(); } } } if(chns>3) {if(C4=="none") { } else {selectWindow(C4); run("Duplicate...", "duplicate"); rename(CN4); run(CC4); run("Reverse"); //create temporary directory myDir4 = rsts+"temporary_"+CN4+"_images"+File.separator; File.makeDirectory(myDir4); run("Stack to Images"); for (j = 0; j < zts; j++) {run("Select All"); run("Copy"); newImage("Untitled", "16-bit black", width-marg*2+20, height-marg*2+20, 1); wait(200); run("Paste"); run("Select None"); run("Enhance Contrast", "saturated=0.10"); saveAs("Tiff", myDir4+ttl+"_"+CN4+"_"+j+1); close(); close(); } } } close("C1-x"); close("C2-x"); if(chns>2) {close("C3-x"); } if(chns>3) {close("C4-x"); } } if(clls==0) {myDir1 = rsts+"temporary_"+CN1+"_images"+File.separator; File.makeDirectory(myDir1); myDir2 = rsts+"temporary_"+CN2+"_images"+File.separator; File.makeDirectory(myDir2); if(chns>2) {myDir3 = rsts+"temporary_"+CN3+"_images"+File.separator; File.makeDirectory(myDir13); } if(chns>3) {myDir4 = rsts+"temporary_"+CN4+"_images"+File.separator; File.makeDirectory(myDir4); } Dialog.create(" "); Dialog.addNumber("How many cells/regions will you analyze?", 0); Dialog.show(); clln=Dialog.getNumber(); print("number of selected cells:", clln); print(""); if(clln==0) {close("x"); } else {for (l = 0; l < clln; l++) {setTool("freehand"); rename("y"); waitForUser("Select cell/region - ensure it is within selected region throughout the stack\nand none of dots gets near selection boundary!"); run("Duplicate...", "duplicate"); rename("x"); run("Clear Outside", "stack"); run("Select None"); run("Split Channels"); selectWindow(C1); getDimensions(width, height, channels, slices, frames); rename(CN1); run(CC1); zts=nSlices(); run("Reverse"); run("Stack to Images"); for (j = 0; j < zts; j++) {run("Select All"); run("Copy"); newImage("Untitled", "16-bit black", width+20, height+20, 1); wait(200); run("Paste"); run("Select None"); run("Enhance Contrast", "saturated=0.10"); saveAs("Tiff", myDir1+ttl+"_cell_"+l+1+"_"+CN1+"_"+j+1); close(); close(); } if(C2=="none") { } else {selectWindow(C2); rename(CN2); run(CC2); run("Reverse"); run("Stack to Images"); for (j = 0; j < zts; j++) {run("Select All"); run("Copy"); newImage("Untitled", "16-bit black", width+20, height+20, 1); wait(200); run("Paste"); run("Select None"); run("Enhance Contrast", "saturated=0.10"); saveAs("Tiff", myDir2+ttl+"_cell_"+l+1+"_"+CN2+"_"+j+1); close(); close(); } } if(chns>2) {if(C3=="none") { } else {selectWindow(C3); rename(CN3); run(CC3); run("Reverse"); run("Stack to Images"); for (j = 0; j < zts; j++) {run("Select All"); run("Copy"); newImage("Untitled", "16-bit black", width+20, height+20, 1); wait(200); run("Paste"); run("Select None"); run("Enhance Contrast", "saturated=0.10"); saveAs("Tiff", myDir3+ttl+"_cell_"+l+1+"_"+CN3+"_"+j+1); close(); close(); } } if(chns>3) {if(C4=="none") { } else {selectWindow(C4); run("Duplicate...", "duplicate"); rename(CN4); run(CC4); run("Reverse"); run("Stack to Images"); for (j = 0; j < zts; j++) {run("Select All"); run("Copy"); newImage("Untitled", "16-bit black", width+20, height+20, 1); wait(200); run("Paste"); run("Select None"); run("Enhance Contrast", "saturated=0.10"); saveAs("Tiff", myDir4+ttl+"_cell_"+l+1+"_"+CN4+"_"+j+1); close(); close(); } } } } } } close("y"); } } LIST1=getFileList(myDir1); for (h=0; h1) {if(C2=="none") { } else {LIST2=getFileList(myDir2); for (h=0; h2) {if(C3=="none") { } else {LIST3=getFileList(myDir3); for (h=0; h3) {if(C4=="none") { } else {LIST4=getFileList(myDir4); for (h=0; h0) {selectWindow(title1); saveAs("Text", rsts+title1+".csv"); close(title1); } if(clln==0) {close(title1); } } } selectWindow("Log"); saveAs("Text", rsts+"Log"+"_"+month+"_"+dayOfMonth+"_"+year+"_"+hour+"_"+minute+".txt"); close("Log");