Processing Volumetric Data

After collecting volumetric data with the Optotune you can now process your data as follows.

First, use sbxsplit() to generate separate data files for each “slice” of the optotune.

For example, if I have a data file gn7_008_001.sbx collected some data with an optotune waveform having a period of 5 the command

>> sbxsplit('gn7_008_001')

will generate a set of 5 files named gn7_008_001_ot_NNN, where NNN.sbx will range from 000 to 004, corresponding to each separate optical plane.

Second, the resulting files can then be aligned and segmented by treating each plane individually.  This will generate the corresponding *.signals and *.segment files.

Finally, you can call:

>> sbxmerge('gn7_008_001')

This will generate gn7_008_001_merged.signals and gn7_008_001_merged.segment.

The signals matrix will have as many rows as frames were present during acquisition while interpolating the missing samples for each plane (that is, when the optotune was sampling from other planes).

The interpolated signals are then deconvolved as usual to generate an estimate of spiking in the spks matrix.  From here on you can process the data as if it came from a typical experiment where only one plane was sampled.

The mask variable in the segmented file will have a size of [ny nx plane], where [ny, nx] is the size of each frame and plane is the period of the optotune waveform.  Each cell has a unique ID value corresponding to its column in the signals matrix.


Note that each setting of the optotune waveform is treated independently, even though thay may potentially represent the same plane (as it may happen using sinusoidal or triangular z-scanning).

A montage display for real-time display of volumetric data


By default, Scanbox displays the incoming image stream on its main window. Thus, during volumetric scanning, one sees the incoming images as depth is changing over time.  If one is imaging only a handful of optical planes, it is difficult to see what is really going on.

A different way to visualize the data in such recordings is to have a montage showing the different optical sections separately, each being updated as new data becomes available. Here, we offer a plug-in for Scanbox that implements this mode of visualization.

As discussed in previous examples, Scanbox shares date with other processing by means of memory-mapped files. A header at the beginning of the file provides a mechanism for exclusive access to the data via a semaphore and exposes basic information about the data, such as the size of the images, the frame # being shared at any one time, and the period (in frames) of the volumetric scanning waveform, among other information.

Such data, along with a readily available montage function from Matlab, allows one to easily display the data as separate optical planes during acquisition.

Here is the code:

% Plug-in Demo: Display optical sections separately

close all; % Close all open figs

% Open memory mapped file -- define just the header first

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

% Process all incoming frames until Scanbox stops

    while(mmfile.Data.header(1)<0) % wait for a new frame...
        if(mmfile.Data.header(1) == -2) % exit if Scanbox stopped
    if(flag) % first time? Format chA according to lines/columns in data
        mmfile.Format = {'int16' [1 16] 'header' ; ...
            'uint16' double([mmfile.Data.header(2) mmfile.Data.header(3)]) 'chA'};
        mchA = double(intmax('uint16')-mmfile.Data.chA);
        flag = 0;
        nplanes = mmfile.Data.header(6);
        I = zeros([size(mchA) 1 nplanes]);
        I(:,:,1,1) = mchA;
        axis off;           % remove axis
        colormap gray;      % use gray colormap
        I(:,:,1,mod(mmfile.Data.header(1),nplanes)+1) = double(intmax('uint16')-mmfile.Data.chA);
    mmfile.Data.header(1) = -1; % signal Scanbox that frame has been consumed!
    drawnow limitrate;

clear(mmfile); % close the memory mapped file
close all;     % close all figures

And here are, side-by-side, the result of viewing the incoming stream in the main Scanbox window and in the volumetric plug-in.