// Demo imageJ script to control SharpCap and then filter the resulting image background // It can open an imageJ GUI, then create a Windows .bat file to launch SharpCap with its *.py script // This is only a demo, and not intended to be useful as is. // The full version generates the .bat and .py files, and has a complete interface to control SharpCap // This script was developed from http://rsb.info.nih.gov/ij/macros/tools/VideoCaptureTool.txt // The imageJ Macro language is described on https://imagej.net/ij/developer/macro/macros.html // The imageJ Macro functions are described on https://wsr.imagej.net/developer/macro/functions.html // // (1) Download ImageJ bundled with Java 64-bits for Windows https://imagej.net/ij/download.html // If you already have Java installed, you can just download the imageJ ZIP archive // Use the Command Recorder (Plugins>Macros>Record) to see what the imageJ menu commands do // (2) Create D:ShapCap.bat="C:\\Program Files\\SharpCap 4.1 (64 bit)\\SharpCap.exe" /runscript D:\SharpCap.py (3) Create D:SharpCap.py=SharpCap.SelectedCamera.CaptureSingleFrameTo ("D:\image.fits") // (4) Copy this SharpCapTest.txt file to ImageJ\macros\toolsets // (5) Click the red >> icon in the ImageJ toolbar and select this SharpCapTest.txt tool // (6) Right-click the new camera icon to set the parameters to remove diffuse BG // (7) Left-click the new camera icon to launch SharpCap, capture an image, and remove diffuse BG // (8) Eventually edit the commands below, select this tool again with the red >> icon and relaunch // (9) Clear the camera icon tool by selecting "Startup Macros" with the red >> icon //(10) NOTE: The image is captured with the last camera and its settings eg (Camera V3 Simulator) var radius = 10; //Default value var percentagesub = 0.95; //Default value (try 1.0) //-------------------- S h a r p C a p T o o l A c t i o n --------------------- // This is the action you get on clicking the left button on the camera icon macro 'SharpCap Action Tool - C000F14faF24faP4461b1d40Cfffo5577' { //IMAGE acquire setOption("WaitForCompletion", false); //Don't wait for SharpCap.bat to finish status = exec("cmd /c start \"\" /min d:\\SharpCap.bat"); //Launches SharpCap with no errors // status = exec("cmd /c d:\\SharpCap.bat"); //Launches SharpCap with scripting errors wait(500); //wait 0.1s for new cmd window to draw showMessage("After image captured, Click OK to continue"); //could also do this automatically in imageJ status=exec("taskkill /IM SharpCap* "); //Close SharpCap status=exec("taskkill /F /IM cmd.exe "); //Close cmd window //BG Subtract open("D:\\image.fits"); title = getTitle(); //Original Image Title imgid = getImageID(); //ID of original image run("Duplicate...", "title=med duplicate"); //Image/Duplicate->"med" medid = getImageID(); //ID of median image run("Despeckle"); //remove one pixel noise run("Median...", "radius="+radius+" stack"); //Process/Filters/Median run("Multiply...", "value="+percentagesub + " stack"); //Process/Filters/Multiply imageCalculator("Subtract create stack", title,"med"); //Subtract median image rename(title+"_med"+radius); //Rename the result setSlice(round(nSlices()/2)); //NA since image not a stack run("Despeckle"); //remove one pixel noise run("Enhance Contrast", "saturated=0.35"); //auto contrast and intensity selectImage(medid); //select median image image close(); //close it selectImage(imgid); //select original image close(); //close it File.delete("D:\\image.fits"); //delete original image } //-------------------- S h a r p C a p T o o l O p t i o n s --------------------- // This is the options dialogue you get on clicking the right button on the camera icon // It could be expanded to input all necessary SharpCap options - camera, exposure time, etc. macro 'SharpCap Action Tool Options' { //GUI Dialog.create("Median BG radius 10 >> bigger than spots"); Dialog.addNumber("Please input a median BG radius", radius); Dialog.addNumber("Input a percentage of intensity to subtract", percentagesub); Dialog.show(); radius = Dialog.getNumber(); percentagesub = Dialog.getNumber(); }