Avoid image display during acquisition

Hi all,

I am working on a Micro-Manager (1.4.22) beanshell script to perform live fluorescence imaging (I only need the mean gray value of the current image) during a running acquisition. My original script allows a framerate of around 40 frames/s. Based on the gray value, the script gives a live feedback to another device.
I wonder, if I can speed it up by hiding the images during acquisition? I accomplished to avoid displaying it by setting the “show” boolean in “gui.openAcquisition(dFF0, rootDirName, nrFrames, nrChannels, nrSlices, nrPositions, /* show / false, / save */ false)” to false, but then I don’t know how to access the image and its mean gray value anymore (I used “getStatistics().mean”).

Thank you in advance for any ideas!

Best regards,
Amelie

Here parts of an example code (adapted from the micro-manager page) that works only, when images are displayed:

gui.openAcquisition(title, acqDir,
nrFrames, nrChannels, nrSlices, nrPositions,
/* show / false,
/
save */ true);

width = (int) mmc.getImageWidth();
height = (int) mmc.getImageHeight();
bytesPerPixel = (int) mmc.getBytesPerPixel();
bitDepth = (int) mmc.getImageBitDepth();

gui.initializeAcquisition(title, width, height, bytesPerPixel, bitDepth);

mmc.startSequenceAcquisition(nrFrames, 0, true);
frame = 0;
exposureMs = mmc.getExposure();
while (mmc.getRemainingImageCount() > 0 || mmc.isSequenceRunning(mmc.getCameraDevice())) {
if (mmc.getRemainingImageCount() > 0) {
img = mmc.popNextTaggedImage();
imp = IJ.getImage();
double F = imp.getStatistics().mean;
gui.addImageToAcquisition(title, frame, 0, 0, 0, img);
frame++;
}
else {
mmc.sleep(Math.min(0.5 * exposureMs, 20));
}
}

mmc.stopSequenceAcquisition();

1 Like

Tagging @nico.stuurman

1 Like

Are you sure that the camera isn’t already acquiring at it’s maximum speed?

1 Like

The sequence acquisition as such works also for much higher frame rates (I am using an Evolve 512 Delta), but the live analysis is too slow and reaches its limit at around 40 frames/s. Therefore I am looking for a way to run a sequence acquisition without displaying it. I just thought this could speed up the whole program. But I am a complete beginner at programming :slight_smile:

1 Like

I have not used 1.4 in several years, but in Micro-Manager 2.0-gamma min, max, avg, and stddev. are calculated for each image and displayed in the Inspector, and that code can keep up with an Evolve 512 running at its fastest speed. In general, you are much better off using 2.0-gamma rather than 1.4 (which will soon be completely retired), and I will be able to help you much better in 2.0-gamma than 1.4…

Nevertheless, 1.4 has a command to convert a TaggedImage into an ImageProcessor. It is well hidden, and you’ll need:

import org.micromanager.utils.ImageUtils;

ImageProcessor proc = ImageUtils.makeProcessor(img);

You can then wrap the ImageProcessor into an ImagePlus and do the Statistics without the need to display the image (I did not check this code, so there may be errors).

Good luck!

.

1 Like

Hi Nico,

Thank you for your fast response! It works perfectly :blush: I am now at 90 fps and the program reports on every single frame (sometimes my original script measured the mean gray value of the same frame multiple times).
As a next step I will try to convert my script to Micro-Manager 2.0-gamma, as you suggested.

Best regards,
Amelie

1 Like

Hi Amelie,

Great to hear! The new API is a bit different and may take some time to wrap your head around, but it is quite nice once you get used to it.

Best,

Nico

2 Likes