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.

../_images/IntegrationROIChannelConfig1.png

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

Daq Name

Channel ID

Description

Software

None

None

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

AnalogOutput

<DAQ Name>

AOx

Outputs an analog signal on the specified analog output

DigitalOutput

<DAQ Name>

Dx.x (vDAQ)

PFIx (NI hardware)

Outputs a digital signal on the specified PFI channel

../_images/IntegrationROIChannelConfig2.png

Configuration Editor

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

Note

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.

Attention

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

../_images/Integraion+Controls.PNG

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

Description

vals

1xN array of integration values of the selected ROIs

varargin

advanced parameters

The output function needs to generate the follwing outputs:

Function output

Description

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).

Tip

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.

Note

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

@(varargin)myOutputFunction(varargin{:})

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function outputVal = myOutputFunction(vals,varargin)
  persistent hLine
  persistent history
  persistent historyPointer
  historyLength = 100;

  if isempty(hLine) || ~isvalid(hLine)
    hFig = figure();
    hAx = axes('Parent',hFig,'XLim',[1,historyLength]);
    hLine = line('Parent',hAx,'XData',NaN,'YData',NaN,'Color','b');
  end

  if isempty(history) || length(history) ~= historyLength
    history = nan(1,historyLength);
  end

  if isempty(historyPointer) || historyPointer > historyLength
    historyPointer = 1;
  end

  outputVal = mean(vals); % calculate the output value by averaging all input values
  history(historyPointer) = outputVal;
  historyPointer = historyPointer + 1;
  if historyPointer > historyLength
    historyPointer = 1;
  end

  history(historyPointer) = NaN;

  hLine.XData = 1:historyLength;
  hLine.YData = history;
end
../_images/Output+Function+Plot.PNG

Plot generated by myOutputFunction