Applying SLM Calibration in Beanshell

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Applying SLM Calibration in Beanshell

Ross, Tyler D.

Hello,


I am using a projector to display patterns on my sample with micromanager. I have calibrated the projector using the projector plugin. However, when I upload images to the projector using the beanshell script, the calibration is not being applied. Is there a beanshell function that I can use to apply the calibration transformations on my images before they are sent to the projector?



For reference I am using Pariksheet's script:


// Upload image from stack to SLM before each frame in MDA.
//
// We have to use the core API to upload each frame individually,
// since there is no public sequencing API for SLM devices.
//
// Pariksheet Nanda <[hidden email]> July 2014
//
// License: Public Domain

import ij.io.Opener; // To load TIFF stack file from disk.
import ij.ImagePlus; // To hold the opened image.
import ij.ImageStack; // To access stack pixels.

// Load file from disk.
Opener opener = new Opener();
ImagePlus imp =
opener.openImage("/path/to/stack.tif");

// Get stack info.
ImageStack stack = imp.getImageStack();
slices = stack.getSize();

// Set MDA to acquire the number of slices.
seqSettings = gui.getAcquisitionSettings();
seqSettings.numFrames = slices;
gui.setAcquisitionSettings(seqSettings);

// Get the installed name of the SLM.
mosaic = mmc.getSLMDevice();

// Boilerplate when using runnables.
gui.clearRunnables();

// Runnable to upload each image to the SLM.
runnable = new Runnable() {
      int slice = 1;
     
      public void run() {
         // Get the pixels of the stack slice.
         pixels = stack.getPixels(slice);
         // Upload the image to the SLM.
         mmc.setSLMImage(mosaic, pixels);
         // Activate the uploaded image on the SLM.
         mmc.displaySLMImage(mosaic);
         print("Activated slice " + slice);
         slice++;
      }
   };

// Dimension order is frame, position, channel, slice.
gui.attachRunnable(-1, -1, -1, -1, runnable);


Tyler



_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Applying SLM Calibration in Beanshell

Stuurman, Nico
Hi Tyler,


I am using a projector to display patterns on my sample with micromanager. I have calibrated the projector using the projector plugin. However, when I upload images to the projector using the beanshell script, the calibration is not being applied. Is there a beanshell function that I can use to apply the calibration transformations on my images before they are sent to the projector?


The calibration is stored in the Projector plugin itself.  You will need to go through its code to see how you can get in there.  I rewrote substantial parts of that plugin in 2.0-gamma in part to make approaches like yours easier.  It looks like you are using 1.4, and I really do not remember how that version was wired up.  If you are not bound to 1.4, it maybe easier to switch to 2.0-gamma (but note that the scripting interface has changed, especially with respect to the gui object, which is now called and mm and has a completely different interface).

Best,


Nico



For reference I am using Pariksheet's script:


// Upload image from stack to SLM before each frame in MDA.
//
// We have to use the core API to upload each frame individually,
// since there is no public sequencing API for SLM devices.
//
// Pariksheet Nanda <[hidden email]> July 2014
//
// License: Public Domain

import ij.io.Opener; // To load TIFF stack file from disk.
import ij.ImagePlus; // To hold the opened image.
import ij.ImageStack; // To access stack pixels.

// Load file from disk.
Opener opener = new Opener();
ImagePlus imp =
opener.openImage("/path/to/stack.tif");

// Get stack info.
ImageStack stack = imp.getImageStack();
slices = stack.getSize();

// Set MDA to acquire the number of slices.
seqSettings = gui.getAcquisitionSettings();
seqSettings.numFrames = slices;
gui.setAcquisitionSettings(seqSettings);

// Get the installed name of the SLM.
mosaic = mmc.getSLMDevice();

// Boilerplate when using runnables.
gui.clearRunnables();

// Runnable to upload each image to the SLM.
runnable = new Runnable() {
      int slice = 1;
     
      public void run() {
         // Get the pixels of the stack slice.
         pixels = stack.getPixels(slice);
         // Upload the image to the SLM.
         mmc.setSLMImage(mosaic, pixels);
         // Activate the uploaded image on the SLM.
         mmc.displaySLMImage(mosaic);
         print("Activated slice " + slice);
         slice++;
      }
   };

// Dimension order is frame, position, channel, slice.
gui.attachRunnable(-1, -1, -1, -1, runnable);


Tyler



_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general



_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Applying SLM Calibration in Beanshell

StevenF
Hi,

So I am reviving this thread because i am also interested in accessing the
Calibration/Affine Transforms generated by the Calibration of the Projector
plugin!

How would you go about doing this using version 2.0 gamma?

Thanks in advance,

Best,

Steven



--
Sent from: http://micro-manager.3463995.n2.nabble.com/


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Applying SLM Calibration in Beanshell

Stuurman, Nico
Hi Steven,
> So I am reviving this thread because i am also interested in accessing the
> Calibration/Affine Transforms generated by the Calibration of the Projector
> plugin!
>
> How would you go about doing this using version 2.0 gamma?

For 2.0-gamma, look at my mnfinder repository on Github:
https://github.com/nicost/mnfinder/tree/mm2-gamma

The relevant code is in the
https://github.com/nicost/mnfinder/blob/mm2-gamma/MicroNuclei/src/org/micromanager/micronuclei/MicroNucleiForm.java 
class (hmm, not so nice to have this in the UI class, but oh well),
specifically, the "zap" function that takes ImageJ rois and projects
them on the SLM (line 1115 onwards).

Best,

Nico


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Applying SLM Calibration in Beanshell

mglotzer
Hi Nico,
A quick question related to this thread.

 I wrote a small script to adjust the activation intensity of a set of ROIs
in ROI manager to activate using the projector plugin (using M-M 2.0).
However, the ROIs in ROI manager are not transformed by the calibration
settings. Running "use ROIs" function in the projector plug in applies to
calibration, but it overwrites the changes I had made to the intensities in
each ROI.  

Thus this thread seems to pertain exactly to what I am trying to accomplish.
My question is whether the functions ProjectorAction.transformROIs and
runPolygons referenced in the mnfinder script above alters only the shape of
the ROIs or do they also the intensity of the ROIs? If the intensity is
changed, is there a way to only apply the calibration?


Thanks
best,
Michael




--
Sent from: http://micro-manager.3463995.n2.nabble.com/


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Applying SLM Calibration in Beanshell

Stuurman, Nico
Hi Michael,

>   I wrote a small script to adjust the activation intensity of a set of ROIs
> in ROI manager to activate using the projector plugin (using M-M 2.0).
> However, the ROIs in ROI manager are not transformed by the calibration
> settings. Running "use ROIs" function in the projector plug in applies to
> calibration, but it overwrites the changes I had made to the intensities in
> each ROI.
>
> Thus this thread seems to pertain exactly to what I am trying to accomplish.
> My question is whether the functions ProjectorAction.transformROIs and
> runPolygons referenced in the mnfinder script above alters only the shape of
> the ROIs or do they also the intensity of the ROIs? If the intensity is
> changed, is there a way to only apply the calibration?

Haven't tested this, but hope this will guide you in the right
direction.  Assuming 2.0-gamma:

import org.micromanager.projector.ProjectorActions;
import org.micromanager.projector.internal.devices.SLM;

pd = ProjectorActions.getProjectionDevice(mm);
// will fail if your device is not an SLM.  May need to open Projector
plugin first
slm = (SLM) pd;
// defines intensity of each ROI, for instance
List intensities = new ArrayList();
for (int i = 0; i < 10; i++) {
     intensities.add(100 + i);
}

if (slm != null) { // if you do not have an slm it will be null
     maps = ProjectorActions.loadMapping(mm, pd);
     transformROIs = ProjectorActions.transformROIs(rois, maps);
     slmImg = slm.roisToPixels(width, height, transformROIs, intensities);
     slm.displaySLMImage(slmImg);
     slm.waitForDevice();
}


Best,


Nico

_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Applying SLM Calibration in Beanshell

mglotzer
Thanks Nico!

For future reference, could you please point me to the ProjectorActions
package? I could not find it on GitHub or the programming docs linked to
from micro-manager.org.

Do the documentation of the API's on the programming guide at m-m.org
pertain to the 1.4 version primarily? Are the 2.0 APIs only listed on
GitHub? (I understand that the projector interface has undergone significant
revision from 1.4 to 2.0).

Thanks again!
best,
Michael







--
Sent from: http://micro-manager.3463995.n2.nabble.com/


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Applying SLM Calibration in Beanshell

Stuurman, Nico
Hi Michael,

> For future reference, could you please point me to the ProjectorActions
> package? I could not find it on GitHub or the programming docs linked to
> from micro-manager.org.

The projector plugin is a plugin (may actually be good to promote this
to the main application...).

Source code:
https://github.com/nicost/micro-manager/tree/ViewerPlusCV/libraries/Projector/src/main/java/org/micromanager/projector

Note: Chris and Mark decided that plugin can no longer call other
plugins and changed the code to load each plugin using its own
class-loader.  This has the net effect that the plugin can "see" the
code of the main applications, but not see the code of other plugins. 
That is very bad for something that is useful to other plugins (I can
see that it helps "separate" code and avoid potential clashes, but in
general I feel that it is more of a burden than helpful).  I have looked
into reverting this, but can not easily figure out that plugin loading
code.  So, for now, shared plugin code is sitting in its own "libraries"
folder, and gets compiled into a jar that is copied into the plugins
(rather than mmplugins) directory.

> Do the documentation of the API's on the programming guide at m-m.org
> pertain to the 1.4 version primarily? Are the 2.0 APIs only listed on
> GitHub? (I understand that the projector interface has undergone significant
> revision from 1.4 to 2.0).

Good point!  I made links specific to 1.4 and 2.0-gamma on the
programming page side bar
(https://micro-manager.org/wiki/Micro-Manager_Programming_Guide).
However, these do not link to the source code of the plugins.


Best,


Nico


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
Reply | Threaded
Open this post in threaded view
|

Re: Applying SLM Calibration in Beanshell

tron

Stuurman, Nico @ 24/05/2019 22:09 -0300 dixit:

> Note: Chris and Mark decided that plugin can no longer call other
> plugins and changed the code to load each plugin using its own
> class-loader.  This has the net effect that the plugin can "see" the
> code of the main applications, but not see the code of other plugins. 
> That is very bad for something that is useful to other plugins (I can
> see that it helps "separate" code and avoid potential clashes, but in
> general I feel that it is more of a burden than helpful).  I have looked
> into reverting this, but can not easily figure out that plugin loading
> code.  So, for now, shared plugin code is sitting in its own "libraries"
> folder, and gets compiled into a jar that is copied into the plugins
> (rather than mmplugins) directory.

You may consider using an additional parameter to the load pluggin
function (e.g a String, optional), to identify a class loader.
If given, that could create a named "space" so if two pluggins needed to
share, it would be enough to pass the same class loader id.
Otherwise, you would retain current functionality.

--
Carlos G Mendioroz  <[hidden email]>


_______________________________________________
micro-manager-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/micro-manager-general
--
Carlos G Mendioroz