Looking for up-to-date ScanImage documentation? That has moved here: docs.scanimage.org

Icon
This documentation is for a legacy ScanImage version. The current documentation is ScanImage 2019.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

For an overview of the ScanImage Roi concept, please review the article Scanfields, ROIs, ROI Groups.

For an overview of the RoiGroup and Roi API, please review the article RoiGroup & Roi

Rotated Rectangle Imaging Scanfield

For imaging with a rectangular scanpattern, ScanImage uses the Scanfield 'RotatedRectangle'. The following paramters define this Scanfield:

Code Block
titleRotated Rectangle Imaging Scanfield
hSf = scanimage.mroi.scanfield.fields.RotatedRectangle();  % create an Imaging Scanfield of type RotatedRectangle
hSf.pixelResolutionXY = [512,512];   				       % set [x,y] resolution
hSf.centerXY = [0.5,0.5];                                  % set [x,y] center (in reference coordinate space)
hSf.sizeXY = [0.5 0.5];  								   % set [x,y] size (in reference coordinate space)
hSf.rotationDegrees= 0;                                    % set rotation (in reference coordinate space)

Pixel Positions in Reference Space

Info

Review the article ScanImage Coordinate Systems to learn more about the different coordinate spaces used in ScanImage.

Scanfields of type RotatedRectangle have two associated affine matrices that allow coordinate space conversions

  • pixelToRefTransfrom - transform pixel coordinates to reference space
  • affine - transform scanfield coordinates to reference space

 

Code Block
titlePixel To Reference Space Transform
hSf = scanimage.mroi.scanfield.fields.RotatedRectangle();  % create an Imaging Scanfield of type RotatedRectangle
hSf.pixelResolutionXY = [32,32];                           % set [x,y] resolution
hSf.centerXY = [0.5,0.5];                                  % set [x,y] resolution
hSf.sizeXY = [0.5,0.5];                                    % set [x,y] center (in reference coordinate space)
hSf.rotationDegrees = 20;                                  % set [x,y] size (in reference coordinate space)
pixToRefT = hSf.pixelToRefTransform();                     % get affine transform to convert pixel coordinatecoordinates to reference space
sfToRefT  = hSf.affine();                                  % get affine transfrom to convert scanfield coordinates to reference space

%% plot pixel coordinates
pixelResXY = hSf.pixelResolutionXY;                        % get scanfield pixel resolution
[xx,yy] = meshgrid(1:pixelResXY(1),1:pixelResXY(2));       % create mesh of pixel coordinates
[xx_ref,yy_ref] = most.idioms.xformMesh(xx,yy,hSf.pixelToRefTransformpixToRefT);  % transform pixel mesh into reference coordinate space
% plot meshgrid in reference space
hFig = figure();
hAx = axes('Parent',hFig,'XLim',[0,1],'YLim',[0,1],'YDir','reverse','DataAspectRatio',[1,1,1]);
line('Parent',hAx,'XData',xx_ref(:),'YData',yy_ref(:),'Color',[0 0.5 1],'LineStyle','none','Marker','.');

%% plot scanfield outline
outlinePts = [0 0; 0 1; 1 1; 1 0; 0 0];
outlinePts_ref = most.idioms.xformPoints(outlinePts,hSf.affinesfToRefT);
line('Parent',hAx,'XData',outlinePts_ref (:,1),'YData',outlinePts_ref (:,2),'Color','red');

%% plot scanfield center
centerPt = [0.5,0.5];
centerPt_ref = most.idioms.xformPoints(centerPt,hSf.affinesfToRefT);
line('Parent',hAx,'XData',centerPt_ref(1),'YData',centerPt_ref(2),'Color','red','Marker','x','MarkerSize',10);
 
Panel
bgColorwhite
titlePixel Coordinates in a Rotated Rectangle

Pixel coordinates within a RotatedRectangle. The pixel coordinates change when the resolution of the scanfield is changed.

RoiManager

All imaging RoiGroups are managed by the ScanImage component hSI.hRoiManager. This component contains two RoiGroups:

  • hSI.hRoiManager
    • hSI.hRoiManager.roiGroupDefault (default, used for non-mRoi imaging)
    • hSI.hRoiManager.roiGroupMroi (used for mRoi imaging)

hSI.hRoiManager.currentRoiGroup returns one of this roiGroups, depending if hSI.hRoiManager.mroiEnable is set to True or False

Warning

Do not change hSI.hRoiManager.roiGroupDefault directly. The scanfield of this RoiGroup is configured automatically by ScanImage using the following properties in hSI.hRoiManager:

hSI.hRoiManager.pixelsPerLine
hSI.hRoiManager.linesPerFrame
hSI.hRoiManager.scanZoomFactor
hSI.hRoiManager.scanRotation
hSI.hRoiManager.scanAngleMultiplierSlow
hSI.hRoiManager.scanAngleMultiplierFast
hSI.hRoiManager.scanAngleShiftSlow
hSI.hRoiManager.scanAngleShiftFast
hSI.hRoiManager.forceSquarePixelation
hSI.hRoiManager.forceSquarePixels

Use hSI.hRoiManager.roiGroupDefault.rois(1).scanfields(1) to inspect the current scanning paramters