Adding image annotations programmatically
Posted: Thu Oct 08, 2020 4:37 pm
Recently I was asked how to put annotations to an image in order to identify certain pixels. While there is an elaborate annotation tool the question actually was how to create the annotations by an ImageLab script (ILabPascal). Here's a short sample script which shows how to add a few annotations.
The result of this script can be seen in the attachment below. Please visit the help pages for details on the parameters of the method "AnnotateImage"
- Hans
Code: Select all
program Annotate;
{
#AUTHOR Hans Lohninger
#DATETIME 2020-10-08 18:23:55
#VERSION 1.0
#CAPTION a short demo to show program-generated annotations
#MINILABVERSION 3.36
}
const
DELTA = 10; // shift of label in world coordinates
LENARROW = 20; // length of arrow in pixels
var
centerX : double;
centerY : double;
XUnit : double;
YUnit : double;
begin
centerx := MData.IndexToWorld(dimX, MData.SizeX div 2); // center of image
centerY := MData.IndexToWorld(dimY, MData.SizeY div 2);
XUnit := MData.UnitSize (dimX, 1); // unit length
YUnit := MData.UnitSize (dimY, 1);
Img2DGui (0,0,0,0,true); // activate 2D Imager GUI
Frm2dImg.ClearAnnotations (0); // clear old annotations
// now create four different annotations
// please note that the following commands assume that both the x- and the y-axis
// is in positive direction (i.e. from left to right and from bottom to top)
Frm2dImg.AnnotateImage (0, centerX, centerY-DELTA*YUnit, dirUpward, LENARROW, clNavy, clWhite,
'UP-verylong 012345678901234567890123456789', false);
Frm2dImg.AnnotateImage (0, centerX, centerY+DELTA*YUnit, dirDownWard, LENARROW, clWhite, clBlack,
'DOWN', false);
Frm2dImg.AnnotateImage (0, centerX+DELTA*XUnit, centerY, dirLeftWard, LENARROW, clRed, clWhite,
'LEFT', false);
Frm2dImg.AnnotateImage (0, centerX-DELTA*XUnit, centerY, dirRightWard, LENARROW, clYellow, clYellow,
'RIGHT', true);
end.
- Hans