ROI Integration Output Channels

ScanImage® can use the Integration Outputs to drive software, analog or digital outputs. A user defined function is called to generate an output value from a list of selected Integration ROIs.

Channel Configuration

To configure output channels, open the Resource Configuration Editor and locate the Integration ROI Output Channel under section Online Analysis. Name the device such that it indicates the type of output it will generate. In this example, they are named “Integration AO”, “Integration DO”, and “Integration Software” for each of the output types.


Each output channel can be of one of the following types:

Daq Name

Channel ID





Does not generate an output, just calls the user defined output function


<DAQ Name>


Outputs an analog signal on the specified analog output


<DAQ Name>

Dx.x (vDAQ)

PFIx (NI hardware)

Outputs a digital signal on the specified PFI channel


Configuration Editor

Configuration of three output channels: Software, Analog Output, and Digital Output; The Channel Name can be chosen arbitrarily.


A ‘Software’ output channel does not require any data acquisitIon hardware. It can be used with the ScanImage API to control the Acquisition, similar to a User Function.


After configuring the output channels in the machine configuration editor, ScanImage® needs to be restarted to apply the changes.


Channel Output Configuration

The output channel ‘Analog Output 1’ is configured to output the average of Cell2 and Cell 3.

Output Configuration

Each output channel can be configured to process the value of multiple integration ROIs. In the Integration Controls, select the ROIs to be passed to the output function.

The output function needs to accept the following inputs:

Input Name



1xN array of integration values of the selected ROIs


advanced parameters

The output function needs to generate the follwing outputs:

Function output


Software Channel

Empty array []

Any output by the function is ignored

Analog Channel

Numeric scalar within range -10..10

Voltage level to drive the analog output

Digital Channel

Logical scalar

Logic level to drive the digital output

The physical channels are only updated when the output value changes (i.e. if the function generates the same output multiple times, the physical channel is only update once).


Updating the physical channel is a blocking call in Matlab. This means that the Matlab execution needs to wait until the update is completed. To improve performance and reduce latency, PCI(e)/PXI(e) are preferable over USB DAQ devices.


Since the ROI Integration and output calculation is done in Matlab, there is a time delay between the frame acquisition and the channel output on the physical DAQ board.

User defined output function

Instead of the default anonymous function, ScanImage® can call a function defined in a .m file on the path. To call a function, replace the anonymous function call as follows:

Output function call


The user defined output function can be used to perform a variety of tasks. The following example averages all passed integration values.

Example output function

 1function outputVal = myOutputFunction(vals,varargin)
 2  persistent hLine
 3  persistent history
 4  persistent historyPointer
 5  historyLength = 100;
 7  if isempty(hLine) || ~isvalid(hLine)
 8    hFig = figure();
 9    hAx = axes('Parent',hFig,'XLim',[1,historyLength]);
10    hLine = line('Parent',hAx,'XData',NaN,'YData',NaN,'Color','b');
11  end
13  if isempty(history) || length(history) ~= historyLength
14    history = nan(1,historyLength);
15  end
17  if isempty(historyPointer) || historyPointer > historyLength
18    historyPointer = 1;
19  end
21  outputVal = mean(vals); % calculate the output value by averaging all input values
22  history(historyPointer) = outputVal;
23  historyPointer = historyPointer + 1;
24  if historyPointer > historyLength
25    historyPointer = 1;
26  end
28  history(historyPointer) = NaN;
30  hLine.XData = 1:historyLength;
31  hLine.YData = history;

Plot generated by myOutputFunction