A rolling average plug-in for scanbox

Scanbox offers a memory-mapped interface mechanism to expose incoming data to other processes. This facilitates a wide rage of customization by users that may want to display their data in different ways or do some on-line processing not currently supported by Scanbox.

We previously provided one example of how a real-time histogram of the data can be generated. Today we offer a simple modification of this code to show a rolling average display, where frames are weighted with an exponential window, can be implemented.

These additional processes can run concurrently with the Scanbox live display if your computer is fast enough. To lighten the load on the computer you can now choose to disable the Scanbox display in the “Image Display” panel.

Remember that plug-ins run on a separate Matlab process and from the yeti/mmap directory.

The code is self-explanatory:

% Simply rolling average plug-in for Scanbox

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

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

% Define the forgetting factor  0 < delta <= 1

delta = 0.9;  % this will generate an exponential decaying memory window: lambda^n

% 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
    display(sprintf('Frame %06d',mmfile.Data.header(1))); % print frame# being processed
    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;
        ih = imagesc(mchA); % setup display
        axis off;           % remove axis
        colormap gray;      % use gray colormap
        truesize            % true image size
        mchA = delta*mchA + (1-delta)*double(intmax('uint16')-mmfile.Data.chA);
        ih.CData = mchA;
    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

If you have any questions just post them below. Homework: Create a plug-in that shows areas of the image that are saturated in red (due date: Aug 8, 2016)