LabKit MATLAB Workbench

reference

FrameworkApp SDK API

labkit.app.interaction.scaleBarGeometry

Compute serializable image scale-bar overlay geometry.

Syntax

geometry = labkit.app.interaction.scaleBarGeometry(imageSize, ... calibration, barLength, position, colorName)

Inputs

imageSize
Numeric vector whose first two elements are positive finite image height and width in pixels.
calibration
Struct with a positive finite pixelsPerUnit field and a unit field, normally returned by scaleBarCalibration.
barLength
Positive finite physical length expressed in calibration.unit.
position
Text containing "top" or "bottom" and optionally "left", "center", or "right". Unrecognized vertical text uses bottom; unrecognized horizontal text uses center.
colorName
"White" selects [1 1 1]. Every other value selects black.

Outputs

geometry
Scalar data struct with the fields described below.

Geometry Fields

line
Two-by-two [x y] endpoints in image-pixel coordinates.
label
Display text containing barLength and calibration.unit.
color
RGB triplet selected by colorName.
labelPosition
One-by-two centered label position in image pixels.
verticalAlignment
"top" for a top bar or "bottom" for a bottom bar.
pixelsPerUnit
Calibration value copied into the geometry.
unit
Unit label copied into the geometry as a string scalar.
barLength
Requested physical length.
position
Supplied position text as a string scalar.
colorName
Supplied color text as a string scalar.

Description

The helper places the line with an eight-percent image-edge margin and a five-pixel minimum inset. It errors when the requested bar cannot fit in the available horizontal span. Apps and renderers own drawing; this function creates no graphics and is suitable for saved project state.

Errors

labkit:app:interaction:InvalidImageSize
imageSize lacks positive finite height and width.
labkit:app:interaction:InvalidScaleBar
calibration or barLength is not a positive finite scalar.
labkit:app:interaction:ScaleBarTooLong
The requested bar does not fit inside the horizontal margins.

Example

cal = labkit.app.interaction.scaleCalibration(80, 20, "mm");
geometry = labkit.app.interaction.scaleBarGeometry( ...
[600 800], cal, 10, "Bottom right", "White");
assert(abs(diff(geometry.line(:,1))) == 40)

Source

This page is generated from the MATLAB help text in +labkit/+app/+interaction/scaleBarGeometry.m.