Month: July 2016

A plug-in for real-time histograms in Scanbox

A Scanbox user requested to add the ability to display a histogram of image values in real-time.

Here, I use a the general mechanism of memory mapped files in Scanbox to show how easy is to add such “plug-ins” to provide additional functionality to the system.

The Matlab code necessary to add real-time histograms in Scanbox is very concise and commented below:

% Display real-time histogram in Scanbox

% Prepare the figure for display

close all;
h.MenuBar = 'None';
h.NumberTitle = 'off';
h.Name = 'Scanbox ChA real time histogram';

% Open memory-mapped file to have access to image stream

mmfile = memmapfile('scanbox.mmap','Writable',true, ...
'Format', { 'int16' [1 16] 'header' } , 'Repeat', 1);

% Some parameters for display

nframes = 5; % how often we want to display histogram
nbins = 128; % how many bins in the histogram
margin = 20; % size of the margins to crop around the central ROI

% Start processing until Scanbox stops...

k = 0;

flag = 1; % Necessary to set image format the first time


   while(mmfile.Data.header(1)<0) % wait for a new frame to arrive
      if(mmfile.Data.header(1) == -2) % exit if Scanbox finished acquiring data

   if(flag) % First time? Format chA according to lines/columns in header
      mmfile.Format = {'int16' [1 16] 'header' ; ...
      'uint16' double([mmfile.Data.header(2) mmfile.Data.header(3)]) 'chA'};
      flag = 0;

   if(mod(k,nframes==0)) % update histogram every k frames
      imhist(intmax('uint16')-mmfile.Data.chA(margin:end-margin,margin:end-margin),nbins); % display histogram

   mmfile.Data.header(1) = -1; % signal Scanbox that frame has been consumed!
   k = k+1;

clear(mmfile) % close memory-mapped file

That’s all…

Check the mmap configuration variable is 1 and start Scanbox.

Open a new Matlab process and run the script above.

Start scanning and you should see a real-time histogram being displayed, each of the frames will look like this:


You can add other features to this script, such as displaying the number of pixels saturated, and so on.

Importantly, notice that the memory-mapped mechanism can easily be accessed by plug-ins written in other languages, like Python, so you are not bound to use Matlab.

If you develop useful real-time plug-ins for Scanbox let us know and we will include them as part of the future releases.


Scanbox does 2p-SLM stimulation! (And the mystery of the disappearing cell)

Scanbox is almost ready for in-vivo, two photon stimulation using spatial light modulators!  In our first set of experiments we are are testing the system in SOM cells co-expressing C1V1 and GCaMP6.  Prior to each experiment, we perform a calibration to ensure alignment of the SLM and imaging paths (takes ~3 min).  Cells for stimulation are selected in the same fashion as we define ROIs for real-time processing.  Scanbox allows the selection of an ROI, disk size, pulse duration, and laser power to use for stimulation.  This basic SLM interface is as simple as “point and shoot” and allows one to visualize the traces of all ROIs in response to stimulation.  The stimulus pulse is also shown superimposed on the traces.

Below are two examples where we stimulated two separate cells within the same field of view.  In the movies, the green circle shows the cell that will be stimulated.  The stimulation pulses are shown as a red dot flashed to the right to the frame number (they are very brief).

Here is another cell being stimulated within the same field of view:

Interestingly, stimulation of a single cell also drives a few others in its neighborhood (together with their processes) consistent with the reported existence of gap-junctions between sets of inhibitory neurons of the same type.

We also observed a curious phenomenon, referred in the lab as the mystery of the disappearing cell, which we cannot explain…  but we are sure someone reading this will know the answer to.

After stimulating a cell a few times in succession, GCaMP fluorescence is actually diminished within the cell body and in its near neighborhood, making the cell “disappear” and creating a “hole” within the image.  The “hole” encompasses the cell body and part of the immediate surroundings.

Surprisingly, after waiting 15-20 sec the the cell reappears, suggesting this is not merely a case of photo-ablation.  In the example below we show this phenomenon in two separate cells within the same field of view:

So, what the heck is going on?!  Can you help us explain the mystery of the disappearing cell?

Here are some of the suggestions offered within the Lab:


  • Instant bleaching
  • Higher rate of non-linear bleaching/triplet state
  • Conversion or release of opaque molecules
  • Physical movement of tissue due to heating/other dynamics
  • Photo-switching to off state of GCaMP (all GFPs photos-witch under UV)
  • GFP related changes (environment, pH, FRET)
  • Camp related changes (Ca buffering)


  • “Yuste said 2p stimulation pokes holes in cells [….] (paper here)”


  • Two-photon stimulation distorts the space-time continuum transporting the cell to another dimension.

If you know the answer, please, please… let us know in the comments below!  (Whatever is going on, at least the phenomenon provided us with a simple handle to verify we can precisely calibrate the SLM and imaging paths and stimulate single neurons.)

In terms of further development, we will add an SLM-server that reads the calibration data, the ROIs, and listens to commands over the network, allowing the user to stimulate any subset of the N cells, with different disk sizes, pulse times, and intensity levels.  It should not take more than a week.

It is time to start thinking about all the cool experiments that are coming up next (and start shopping for a new laser)! 🤓