Wednesday 19 February 2014

A manual acquisition script for Micro-Manager

Edits


  • 2014-12-24: Code clean-up. Tested with upcoming MM 1.4.20. Contrast limits (autostretch / fixed / full scale) are now properly saved and displayed in ImageJ / Fiji. Channel group now read from the Multi-D Acquisition panel, no need to mess with the source code any more.
  • 2014-12-05: I have edited the Beanshell script to make it work in Micro-Manager 1.4.19

Introduction

This bean shell script for Micro-Manager implements multi-channel acquisition for manual microscopes. It is based on manualAcq.bsh by Nenad Amodaj, Feb 2008 and Nico Stuurman, April 2008.

Script dialog showing channel, exposure time, image directory and image prefix

The script dialog lets the user know which filter to switch to next (including brightfield if needed) and the resulting images are saved as multi-tiff stacks. Most of the settings (channel names and colours, acquisition times, root directory) can now be changed through the Multi-D acquisition panel instead of being hard-coded as in the original script.

Setup

Step 1: Download from github

For now, the beanshell script is available from this link.

Step 2: Hardware configuration

The script relies on the DemoHub / DemoWheel for the Filter names. So in addition to your camera (here I have a Ximea greyscale camera), you will need to add the DemoCamera DHub and select DWheel.


Then on step 5 of the hardware configuration wizard, change the channel names to the filters available on your microscope. Add a brightfield channel if available. Here for instance, I have renamed states 0,1,2,3 to Brightfield, DAPI, FITC, TRITC.


Save your configuration and you're done with the wizard.

Step 3: Channel group

Create a group called "Channel" which uses "DWheel-Label". The name of the group however isn't important:


This is in addition to the groups necessary to control your camera (e.g. bit depth, gain, etc...). Save the config when you're done.

At this stage, you can edit the config file manually, and comment out any unused DWheel states:

# Preset: State-9
#ConfigGroup,Channel,State-9,DWheel,Label,State-9

# Preset: State-8
#ConfigGroup,Channel,State-8,DWheel,Label,State-8

If you do, don't forget to restart Micro-Manager when you are done.

Step 4: Multi-D acquisition setup

Micro-Manager's Multi-D acquisition setup dialog now provides an easy way to interact with the manual acquisition script. You will need to select "Channel" as the Channel group (or whatever name you gave it) and add the Channels in the order you want to acquire them.

Here for example, the order in which the channels are acquired is Brightfield, DAPI, FITC, TRITC. With this config, I will be doing my hunting and focussing using Brightfield, then select the filters as instructed by the script.

As a side note, the script recognises which channels are in use, as well as the exposure times (although these can also be changed from the script if needed). The "Use?" column, as well as the buttons "Up" and "Down" provide an easy way to quickly modify an existing configuration. These configurations can also be saved.

A working channel group with defined channels

An important note: you need to "Close" the Multi-D acquisition dialog to make the new settings available within the rest of Micro-Manager.

Procedure

For now, launch the script through the script panel. Images will be saved in the "directory root" + "prefix" directory. The directory root is the one defined in the Multi-D acquisition panel. The name prefix however, cannot yet be read from the Multi-D acquisition panel. By default, the prefix is "image".

Note 1: If the combined directory name already exists, the prefix will be incremented until an empty slot is found. This stem is then used to prefix each of the created files within that directory.

Note 2: The prefix can be changed at any time and a valid prefix will be created. Each time the prefix is changed, the image counter is reset.

Note 3: The exposure time can be changed and the current channel will be held until the right exposure is found. Press OK again (without having changed the exposure time) to cycle to the next channel.



Cycling through the channels.

Error handling

The following errors are handled appropriately:
  • No channel available or no channel in use in Multi-D acquisition: The user is prompted to add channels.
  • A directory of that name / prefix already exists: In this case, a new prefix is calculated.
  • The output directory cannot be created or a file of that name exists but is not a directory: The user is prompted to change either the image directory or image prefix. Only the last channel needs re-acquiring (when you press OK).

Converting the stacks to RGB images

If you need to convert these stacks to RGB images, you can do it in ImageJ. For each of the channels, adjust the brightness / contrast (Image -> Adjust -> Brightness/Contrast -> Auto). Then Image -> Colors -> Make Composite. Then save the image to an appropriate format.

Sample image

Three channels (b,g,r).
The raw image is available from here: image45_0002_MMStack.ome.tif

Bugs / future improvements

  • For versions of Micro-Manager prior to 1.4.17, uncomment the line gui.initializeAcquisition(acqName, ...
  • The initial prefix is hardcoded to read "image". I do not know how to read the prefix from the Multi-D Acquisition Panel.
  • The album which shows the composite image should really be cleared when a new image is being acquired.
  • Easy way to launch the script, i.e. not from the script panel but from its own toolbar or from the ImageJ toolbar. Working on that.
  • min/max for each channel need a bit of work. At the moment, CHANNEL_MINS are 0 and CHANNEL_MAXES to max depth.

Additional Notes

Closing a window without prompting for save

This is something that took me a bit of time to work out. If you have the title of the window (here we use acqName), do this:

mmAcq = gui.getAcquisition(acqName);
mmAcq.promptToSave(false);
gui.closeAcquisitionWindow(acqName);

You can also check that the window actually exists before trying to close it:

if (gui.acquisitionExists(acqName)) { ... }

Blanking a (tagged) image

I'm half way there with this one. From a tagged image, you can create an ImageJ ImageProcessor. Then use the set() method to blank the image with set(0).

ImageProcessor ip = ImageUtils.makeProcessor(img);
ip.set(0);

... however, I haven't found yet how to get tagged images from an acquisition window. Hence in my program, I store the tagged images in an ArrayList as I snap them.

No comments:

Post a Comment