//Beanshell for ratiometric measurements //---------------------------------------------------------------------- //Julien Husson //julien.husson@curie.fr //permanent: julien.husson@free.fr // //Macromolécules et Microsystèmes en Biologie et en Médecine //Laboratoire Physico Chimie Curie - UMR 168 //Institut Curie //11 rue P. et M. Curie, 75231 PARIS Cedex 05, FRANCE //Tel : (33) (0) 1 56 24 67 75 //Fax : (33) (0) 1 40 51 06 36 //http://www.curie.fr/equipe/69/lang/_gb //---------------------------------------------------------------------- //This auciliary beanshell just takes a single ratio image (for quick //sample scanny). //It is essentially a simplified version of main beanshell, with automatic //thresholding. import ij.*; import ij.gui.*; import org.micromanager.api.AcquisitionOptions; import java.lang.System; import ij.process.*; import ij.ImagePlus; import ij.plugin.*; import java.lang.Math; import java.awt.image.*; import ij.measure.*; import ij.text.*; import ij.plugin.filter.*; /////////////////////////////////////////////////// /////////////////////////////////////////////////// // intitialization and parameters /////////////////////////////////////////////////// /////////////////////////////////////////////////// gui.closeAllAcquisitions(); gui.clearMessageWindow(); ij.WindowManager.closeAllWindows(); String[] channels = {"FITC","340","380","closed"}; Color[] colors = {Color.GREEN, Color.BLUE, Color.CYAN, Color.WHITE}; String[] fluolevel = {"1","2","3","4"}; String[] binningtable = {"1","2","4"}; numSlices = 1; channelGroup = "Filter wheel";//change to corresponding channel name boolean show = true;//shows/hides gui acquisition window String LUT = "Fire";//change at will String label = "final ratio stack"; ///////////// Menu#0 defining #frames, channel for background location double multiplicationFactor = 10;//it is entered by used in a dialog box at beginning acqName = "test"; rootDirName = "090000"; int indexfirstsnap = 2; timeFileName = rootDirName+"/"+acqName+"_0/"+acqName+"_times.txt"; numFrames = 1; intervalMs = 100; ///time for one loop (in ms) double expTime340380 = 200; double expTimeFITC = 200; double expTimeTrans = 20; String fluolevel1 = fluolevel[0]; String binning1 = binningtable[1]; double multiplicationFactor = 10000; times340 = new long[numFrames]; times380 = new long[numFrames]; timesFITC = new long[numFrames]; timesTrans = new long[numFrames]; mmc.setExposure(expTime340380); mmc.setConfig(channelGroup, channels[indexfirstsnap]); mmc.waitForConfig(channelGroup, channels[indexfirstsnap]); mmc.setShutterDevice("SC10"); mmc.setShutterOpen(false); mmc.setShutterDevice("LudlShutter"); gui.openAcquisition(acqName, rootDirName, numFrames, channels.length, numSlices, show); for (int i=0; i200)||(hROIbg[0]>200)) new WaitForUserDialog("Do it again strangely large background ROI").show(); mmc.setROI(xROIbg[0],yROIbg[0],wROIbg[0],hROIbg[0]); gui.snapSingleImage(); firstimg=new ImagePlus(); firstimg=IJ.getImage(); if (byteDepth1==1) ip0 = new ByteProcessor((int)wROI[0], (int)hROI[0]); if (byteDepth1==2) ip0 = new ShortProcessor((int)wROI[0], (int)wROI[0]); ip0 = firstimg.getProcessor(); ip0.setRoi(xROIbg[0],yROIbg[0],wROIbg[0],hROIbg[0]); ImageStatistics roi0stats = firstimg.getStatistics(); int background0=Math.round(roi0stats.mean); mmc.setROI(xROI[0],yROI[0],wROI[0],hROI[0]); gui.snapSingleImage(); sndimg=new ImagePlus(); sndimg=IJ.getImage(); if (byteDepth1==1) ip01 = new ByteProcessor((int)wROI[0], (int)hROI[0]); if (byteDepth1==2) ip01 = new ShortProcessor((int)wROI[0], (int)wROI[0]); ip01 = sndimg.getProcessor(); ip01.setRoi(xROI[0],yROI[0],wROI[0],hROI[0]); ip01.add(-background0); ip01converted = new ByteProcessor((int)wROI[0], (int)hROI[0]); ip01converted =ip01.convertToByte(false); firstimg.setProcessor("converted to 8bits",ip01converted); ip01.setRoi(xROI[0],yROI[0],wROI[0],hROI[0]); ij.IJ.run("Select None"); ij.IJ.run("Threshold..."); ////////////// THRESHOLDING MENU//////////////// double clippingvalue=ip01converted.getMinThreshold();//clippingvalue = lower threshold value double clippingvalue2=ip01converted.getMaxThreshold();//clippingvalue2 = higher threshold value, the important one ///////////////creating mask mask = new ByteProcessor((int)wROI[0], (int)hROI[0]); maskaux = new FloatProcessor((int)wROI[0], (int)hROI[0]); double factor = 0.00392156827; //factor=1/255 IJ.getImage().getWindow().setVisible(false); img1=new ImagePlus(); img2=new ImagePlus(); ipsubstracted1 = new FloatProcessor((int)wROI[0], (int)hROI[0]); ipsubstracted2 = new FloatProcessor((int)wROI[0], (int)hROI[0]); //********* change here eventually to Byte/Short if 8/16 bits needed*********** ipratio = new ShortProcessor((int)wROI[0], (int)hROI[0]); ipratioaux = new FloatProcessor((int)wROI[0], (int)hROI[0]); ipratiolive = new FloatProcessor((int)wROI[0], (int)hROI[0]); ipratiolive.setColor(Color.blue); ipratiolive.fill(); ImagePlus imgratio=new ImagePlus("",ipratiolive);//first dummy live ratio image imgratio.show(); ij.IJ.run(LUT);//apply LUT ColorModel cmLUT = ipratiolive.getCurrentColorModel(); ij.IJ.run("Grays");//apply LUT ColorModel cmdefault = ipratiolive.getDefaultColorModel(); winratio=imgratio.getWindow(); winratio.pack(); ipLUT = new FloatProcessor(120, 250); ipLUT.setColor(Color.black); ipLUT.fill(); ipLUT.setMinAndMax(500,3500); imgLUT=new ImagePlus(); imgLUT.setProcessor("LUT",ipLUT); imgLUT.show(); ij.IJ.run(LUT); ij.IJ.run("Calibration Bar...", "location=[Upper Right] fill=None label=White number=5 decimal=0 font=20 zoom=1.0"); ij.IJ.save(IJ.getImage(), rootDirName+"/"+acqName+"_0/"+"LUTbar.tif"); imgLUT.close(); mmc.setShutterDevice("SC10"); initTime=System.currentTimeMillis(); ij.IJ.append("Julien Husson, Institut Curie Paris, France", timeFileName); ij.IJ.append("fluo level: "+fluolevel1, timeFileName); ij.IJ.append("binning: "+binning1, timeFileName); ij.IJ.append("exposure time for FITC (ms):"+expTimeFITC, timeFileName); ij.IJ.append("exposure time for 340&380 (ms):"+expTime340380, timeFileName); ij.IJ.append("exposure time for transmitted light (ms):"+expTimeTrans, timeFileName); ij.IJ.append("frame# FITC 340 380 trans", timeFileName); for (int i=0; i=itTook) gui.sleep(intervalMs - itTook); } ij.IJ.run("Tile"); imgratio.updateAndDraw(); mmc.setROI(xROI[0],yROI[0],wROI[0],hROI[0]); mmc.setShutterDevice("SC10"); mmc.setAutoShutter(true); mmc.setShutterDevice("LudlShutter"); mmc.setAutoShutter(true);