reference
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)Related APIs
labkit.app.interaction.scaleCalibration— Convert a known image distance into pixels per unit.labkit.app.interaction.anchorPath— Declare an editable open or closed path on one plot axis.labkit.app.interaction.interpolateAnchorPath— Build a visible path through image anchor points.labkit.app.interaction.interval— Declare an editable one-dimensional plot interval.labkit.app.interaction.pairedAnchors— Declare matching editable points across plot axes.labkit.app.interaction.pointSlots— Declare a fixed set of editable labeled point positions.labkit.app.interaction.rectangle— Declare an editable rectangular plot region.labkit.app.interaction.regionSelection— Declare a transient click-or-drag region gesture.
Source
This page is generated from the MATLAB help text in +labkit/+app/+interaction/scaleBarGeometry.m.