Adding image annotations programmatically

Feel free to discuss any questions regarding Epina ImageLab :-)
Post Reply
User avatar
hlohning
Posts: 8
Joined: Fri Sep 04, 2020 7:45 pm

Adding image annotations programmatically

Post by hlohning »

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.

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.
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
Attachments
annotate_20201008.jpg
annotate_20201008.jpg (47.66 KiB) Viewed 116895 times
Last edited by hlohning on Fri Oct 09, 2020 5:09 pm, edited 1 time in total.
---
Hans Lohninger
Epina GmbH
Retz, Austria
zgajarsk
Posts: 3
Joined: Thu Oct 08, 2020 10:32 am

Re: Adding image annotations programmatically

Post by zgajarsk »

Very helpful, thank you!

Kind regards,
Zuzana
Post Reply