BSscript for checking camera response with varying exposure : Calling second camera

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

BSscript for checking camera response with varying exposure : Calling second camera

Amit Cherian
This post has NOT been accepted by the mailing list yet.
We have a dual camera setup (Two Photometrics Evolve Delta EMCCDs)
We managed to put up a BSscript for checking camera response with varying exposure.

The BS script is able to access images only from the first camera. Kindly hint me on how to accomplish this for two camera simultaneous. Multi-Cam has been configured and works when we click Snap.

This is the code for single cam

--------------------------------------------
gui.refreshGUI();
gui.refreshGUIFromCache();
gui.closeAllAcquisitions();
gui.clearMessageWindow();

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;
import ij.io.FileSaver;
import org.micromanager.utils.ImageUtils;
import ij.process.ImageProcessor;
import ij.ImagePlus;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import ij.io.DirectoryChooser;

DirectoryChooser dr = new DirectoryChooser("Choose the Pre Bleach directory");
dr.setDefaultDirectory("D:\temp");
acqRoot = dr.getDirectory();
SampleRoot1 = acqRoot ;
print("image:"+SampleRoot1);
numPics=9;
picNum=0;
delayBetweenPicsMs=20;

int[] ExpList = { 2000, 1500, 1000, 800, 600, 400, 200, 100, 50 };

for( i = 0; i < numPics; i++ ){
        timeStartCurrentLoop = System.currentTimeMillis();
     mmc.setExposure(ExpList[i]); //load exposure list
     gui.refreshGUI();
        //take a picture
        mmc.snapImage();
        gui.sleep(50);

        //saving
        Object img = mmc.getImage();
        proc0 = ImageUtils.makeProcessor(mmc, img);
        ImagePlus imgp0 = new ImagePlus("",proc0);
        FileSaver fs =  new FileSaver(imgp0);
        strDirectory = SampleRoot1;
        fs.saveAsTiff(strDirectory + "/" + String.valueOf(ExpList[i]) + ".tif");

        gui.message("Image: " + String.valueOf(ExpList[i]) );

        while ( (System.currentTimeMillis() - timeStartCurrentLoop) < delayBetweenPicsMs ) {
                gui.sleep(50);
        }
       
}
-------------------------------------------------------


Thanks in advance
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BSscript for checking camera response with varying exposure : Calling second camera

JonD
Administrator
This post has NOT been accepted by the mailing list yet.
Amit Cherian wrote
We have a dual camera setup (Two Photometrics Evolve Delta EMCCDs)
We managed to put up a BSscript for checking camera response with varying exposure.

The BS script is able to access images only from the first camera. Kindly hint me on how to accomplish this for two camera simultaneous. Multi-Cam has been configured and works when we click Snap.
mmc.snapImage() works with whatever camera is currently selected.  If the MultiCam device is selected then it should return a "multi-channel" image, one image from each camera.  If it doesn't then this is a bug in MultiCam from my understanding.

To select which camera is active use mmc.SetCameraDevice(java.lang.String cameraLabel).  See https://valelab4.ucsf.edu/~MM/doc/mmcorej/mmcorej/CMMCore.html#setCameraDevice(java.lang.String).  Or you can set the Core's property called "Camera".  Set it to the name of the MultiCam device.

Once you get back a multi-channel image then you may need to split it before processing.

Note that MultiCam requires using the same ROI settings on both cameras.  I'm not sure to what extent it can tolerate differences in other settings, e.g. exposure time.

Jon

-------------------------------------------
Jon Daniels
Applied Scientific Instrumentation
29391 West Enid Rd, Eugene, OR 97402
Phone: (541) 461-8181 x118
-------------------------------------------

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BSscript for checking camera response with varying exposure : Calling second camera

Amit Cherian
This post has NOT been accepted by the mailing list yet.
Thank you Jon for pointing me towards the code.

I managed to work out the code for varying EMGain and Exposure Test for two camera.

For some reason it works only with the demo camera configuration I used to test the code. When it comes to actually controlling two PVCams, it doesn't seem to work.

Instead this error pops up :
Line 40: run-time error : Cannot set property "Gain" to "6" [ Error in device "Evolve-1": The device can not set this property at this moment (32) ]

I've attached the code and the configurations which has multi PVCam and Dummy cam.


PVcam Config: multi_PVCam.cfg

Demo_Cam Config: multi_demo.cfg


Script:

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;
import ij.io.FileSaver;
import org.micromanager.utils.ImageUtils;
import ij.process.ImageProcessor;
import ij.ImagePlus;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import ij.io.DirectoryChooser;
gui.refreshGUI();
gui.refreshGUIFromCache();
gui.closeAllAcquisitions();
gui.clearMessageWindow();


DirectoryChooser dr = new DirectoryChooser("Choose the directory");
dr.setDefaultDirectory("D:\temp");
acqRoot = dr.getDirectory();

print("image:"+ acqRoot);
numPics=9;

int[] GainList = { 6, 3, 2, 4, 1, 5};
int[] ExpList = { 2000, 1500, 1000, 800, 600, 400, 200, 100, 50 };

z = pos = 0;
nF = 9; //  # of frames
nCh = 2; // # of cahnnels
nZ = nPos = 0; // # of Z and xy positions

for( g = 0; g < 6; g++ )
{ deviceName = "Evolve-1";
                propertyName = "Gain";
                newValue = String.valueOf(GainList[g]);
                mmc.setProperty(deviceName, propertyName, newValue);//set gain for Evolve 1

                deviceName = "Evolve-2"; // camera name
                propertyName = "Gain"; // property to be changed
                newValue = String.valueOf(GainList[g]); // load list of gain
                mmc.setProperty(deviceName, propertyName, newValue);
               
                acqName = gui.getUniqueAcquisitionName("Gain"+ GainList[g]); //set folder name

                acqDir = acqRoot;

                gui.openAcquisition(acqName, acqDir, nF, nCh, nZ, true, true);
                       
                        for( f = 0; f < nF; f++ )
                        {
                       
        mmc.setExposure(ExpList[f]); //load exposure list
      gui.refreshGUI();
                                mmc.snapImage();
                                for (int ch = 0; ch < nCh; ch++)
                                {
    im = mmc.getTaggedImage(ch);
    gui.addImageToAcquisition(acqName, f, ch, z, pos, im);
                                }
                        }
}

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BSscript for checking camera response with varying exposure : Calling second camera

JonD
Administrator
This post has NOT been accepted by the mailing list yet.
Amit Cherian wrote
Thank you Jon for pointing me towards the code.

I managed to work out the code for varying EMGain and Exposure Test for two camera.

For some reason it works only with the demo camera configuration I used to test the code. When it comes to actually controlling two PVCams, it doesn't seem to work.

Instead this error pops up :
Line 40: run-time error : Cannot set property "Gain" to "6" [ Error in device "Evolve-1": The device can not set this property at this moment (32) ]

I've attached the code and the configurations which has multi PVCam and Dummy cam.
I assume it works to change the property using the Device Property Browser.  Next I'd try sending the script commands one line at a time at the interactive prompt of the script editor to see if it's some funny issue with sending commands too quickly or trying to change a setting when the 2nd camera isn't set to be active.

Regardless this seems to be an issue with the device adapter not behaving the way you expect.  Photometrics has added functionality to the PVCAM device adapter within the past year and would be the ones to help.  I'm not sure if they "listen" on this list or if you'll need to contact them separately.

Jon

-------------------------------------------
Jon Daniels
Applied Scientific Instrumentation
29391 West Enid Rd, Eugene, OR 97402
Phone: (541) 461-8181 x118
-------------------------------------------


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: BSscript for checking camera response with varying exposure : Calling second camera

Amit Cherian
I'm not sure why Nico's response has not come in the thread.
So posting the thread here
---------------------------------------------------------------------------------------------------------------------
On 8/14/2017 6:44 AM, Amit Cherian wrote:

I managed to work out the code for varying EMGain and Exposure Test for two
 camera.

 For some reason it works only with the demo camera configuration I used to
 test the code. When it comes to actually controlling two PVCams, it doesn't
 seem to work.

 Instead this error pops up :
 Line 40: run-time error : Cannot set property "Gain" to "6" [ Error in
 device "Evolve-1": The device can not set this property at this moment (32)
 ]


This is not a problem with the code, but the problem is that certain properties can only be set after others have been set.  Reading the documentation to your cameras will be helpful, as well as playing with the Device Property browser and see what works, and what does not work.  Most likely, in the case of (EM) gain, the camera readout mode should first be set to the EM readout register (however, I do not remember the PVCAM properties well, as  there is an analog gain and EM gain).  Also, the readout speed may be important.

 Best,

 Nico
---------------------------------------------------------------------------------------------------------------------


A thousand Thanks you Jon and Nico once again in helping me solve this issue.

I was creating a mistake by attempting to change the Gain of PVCam which has just two values "1" and "2", so trying to set this to something else was giving me the error.
The property name was to be set to "MultiplierGain". Now it's working sweet.

What I'm not sure is this

"the camera readout mode should first be set to the EM readout register ",

I'd tried sending the script commands one line at a time at the interactive prompt of the script editor, its is surely setting the gain for both cameras and the metadata also confirms the same.

This code has really got me enthusiastic with writing more codes for automating imaging protocols.

Thank you Jon and Nico for the support.

Micromanager Rokz


Updated code

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;
import ij.io.FileSaver;
import org.micromanager.utils.ImageUtils;
import ij.process.ImageProcessor;
import ij.ImagePlus;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import ij.io.DirectoryChooser;
gui.refreshGUI();
gui.refreshGUIFromCache();
gui.closeAllAcquisitions();
gui.clearMessageWindow();


DirectoryChooser dr = new DirectoryChooser("Choose the directory");
dr.setDefaultDirectory("D:\temp");
acqDir = dr.getDirectory();

print("image:"+ acqDir); //print acquisition directory

int[] GainList = { 6, 3, 2, 4, 1, 5}; // Gain List
int[] ExpList = { 2000, 1500, 1000, 800, 600, 400, 200, 100, 50 };

nF = 9; //  # of frames
nCh = 2; // # of cahnnels
nZ = nPos = 0; // # of Z and xy positions
z = pos = 0;

for( g = 0; g < 6; g++ ) // loop for varying Gain
{ deviceName = "Evolve-1"; // camera name
                propertyName = "MultiplierGain"; // property to be changed
                newValue = String.valueOf(GainList[g]); // load list of gain
                mmc.setProperty(deviceName, propertyName, newValue);// Set the above mentioned properties

                deviceName = "Evolve-2"; // camera name
                propertyName = "MultiplierGain"; // property to be changed
                newValue = String.valueOf(GainList[g]); // load list of gain
                mmc.setProperty(deviceName, propertyName, newValue);// Set the above mentioned properties
               
                acqName = gui.getUniqueAcquisitionName("EMGain "+ GainList[g]); //set folder name

                gui.openAcquisition(acqName, acqDir, nF, nCh, nZ, true, true);
                       
                        for( f = 0; f < nF; f++ ) // loop for varying exposures
                        {
                       
                                mmc.setExposure(ExpList[f]); //set exposure from exposure list
      gui.refreshGUI();
                                mmc.snapImage();
                                for (int ch = 0; ch < nCh; ch++) // loop for multicam image
                                {
    im = mmc.getTaggedImage(ch);
    gui.addImageToAcquisition(acqName, f, ch, z, pos, im);
                                }
                        }
}

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Nabble should be archiving all messages now

JonD
Administrator
Amit Cherian wrote
I'm not sure why Nico's response has not come in the thread.
So posting the thread here
Apparently Nabble stopped receiving messages from the main listserv sometime end-July or early-Aug.  This was noticed and resolved yesterday.

Messages sent via the Nabble interface made it to the listserv, just not the other way.  Hence the Nabble archive is missing most messages posted during those ~2 weeks (except any posted via Nabble).

Jon

-------------------------------------------
Jon Daniels
Applied Scientific Instrumentation
29391 West Enid Rd, Eugene, OR 97402
Phone: (541) 461-8181 x118
-------------------------------------------
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nabble should be archiving all messages now

Amit Cherian
I've updated the code making it capable of automatically calculate the number of gains and exposures that one has entered.

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import ij.plugin.frame.*;
import ij.io.FileSaver;
import org.micromanager.utils.ImageUtils;
import ij.process.ImageProcessor;
import ij.ImagePlus;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import ij.io.DirectoryChooser;
gui.refreshGUI();
gui.refreshGUIFromCache();
gui.closeAllAcquisitions();
gui.clearMessageWindow();


DirectoryChooser dr = new DirectoryChooser("Choose the directory");
dr.setDefaultDirectory("D:\temp");
acqDir = dr.getDirectory();

print("image:"+ acqDir); //print acquisition directory

int[] GainList = { 6, 3, 2, 4, 1, 5}; // Gain List
nG = GainList.length;
int[] ExpList = { 2000, 1500, 1000, 800, 600, 400, 200, 100, 50 };
nE = ExpList.length;
nCh = 2; // # of cameras
nZ = nPos = 0; // # of Z and xy positions
z = pos = 0;

for( g = 0; g < nG; g++ ) // loop for varying Gain
{ deviceName = "Evolve-1"; // camera name
                propertyName = "MultiplierGain"; // property to be changed
                newValue = String.valueOf(GainList[g]); // load list of gain
                mmc.setProperty(deviceName, propertyName, newValue);// Set the above mentioned properties

                deviceName = "Evolve-2"; // camera name
                propertyName = "MultiplierGain"; // property to be changed
                newValue = String.valueOf(GainList[g]); // load list of gain
                mmc.setProperty(deviceName, propertyName, newValue);// Set the above mentioned properties
               
                acqName = gui.getUniqueAcquisitionName("EMGain "+ GainList[g]); //set folder name

                gui.openAcquisition(acqName, acqDir, nE, nCh, nZ, true, true);
                       
                        for( e = 0; e < nE; e++ ) // loop for varying exposures
                        {  mmc.sleep(50);
                       
                                mmc.setExposure(ExpList[e]); //set exposure from exposure list
      gui.refreshGUI();
                                mmc.snapImage();
                                for (int ch = 0; ch < nCh; ch++) // loop for multicam image
                                {
    im = mmc.getTaggedImage(ch);
    gui.addImageToAcquisition(acqName, e, ch, z, pos, im);
                                }
                        }
}
Loading...