Reading raw data with sbxread()

Raw image data in scanbox is contained in *.sbx files.  To read these data you can use the sbxread() function.

Here is the documentation from its help section–

function x = sbxread(fname,k,N,varargin)

% img = sbxread(fname,k,N,varargin)
% Reads from frame k to k+N-1 in file fname
% fname - the file name (e.g., 'xx0_000_001')
% k - the index of the first frame to be read. The first index is 0.
% N - the number of consecutive frames to read starting with k.
% If N>1 it returns a 4D array of size = [#pmt rows cols N]
% If N=1 it returns a 3D array of size = [#pmt rows cols]
% #pmts is the number of pmt channels being sampled (1 or 2)
% rows is the number of lines in the image
% cols is the number of pixels in each line
% Note that these images are the raw data, not corrected for motion and
% non-uniform sampling
% The function also creates a global 'info' variable with additional
% informationi about the file

So, for example, the following lines of code will read images from 0 to 19 (20 total) and display the average of the first (green) PMT channel:

<pre>>> x = sbxread('gd8_000_000',1,20);
>> imagesc(squeeze(mean(x(1,:,:,:),4))), truesize, axis off

And you may get something like this:

spatial raw

Note that these raw data have not yet been corrected for non-uniform sampling.  To correct for non-uniform sampling you can post multiply the image with a sparse interpolant matrix stored in the global variable info.S.  For example, the following lien computes the mean image of the first 20 and corrects for spatial distortion:

imagesc(squeeze(mean(x(1,:,:,:),4))*info.S), truesize, axis off

…and now you get:

spatial compensation


The global info variable contains a number of useful information:

              frame: [144x1 double]
               line: [144x1 double]
           event_id: [144x1 double]
            resfreq: 7938
 postTriggerSamples: 5000
   recordsPerBuffer: 512
     bytesPerBuffer: 10240000
           channels: 1
         ballmotion: []
          abort_bit: 0
             config: [1x1 struct]
           messages: {72x1 cell}
            aligned: [1x1 struct]
                  S: [1250x796 double]
              nchan: 2
                fid: 7
            max_idx: 9028

The variables frame, line and event_id, contain the description of TTL events that arrived during the experiment as described here. The variable S, contains the sparse interpolant matrix you can use to correct for non-uniform sampling. The other variables are used internally by sbxread() to understand how the *.sbx file is organized.