CLabels:delete CLabels:Attach

CLabels:Add


The Add method creates a text label on an image like that shown below. The script that create this is given in the Examples section.

 

Syntax

bSuccess = CLabels:Add( CImage, x, y, str )

    CImage specifies the target image where the label will be drawn.

    x,y specifies the pixel coordinates for the label, beginning at (1,1).

    str is the text of the label.

    On success, true is returned.

    If the method fails or the CImageView is nil, then false is returned.

Remarks

This method draws a label on a displayed image, a CImage, attached to a CImageView object. The label consists of a marker and a text string. The marker and text string are both optional. If the text string spans multiple lines, the string should be formatted using \r\n escape characters between lines (see example below). The Preferences method can also be used to choose the label attributes before labels are added. See the Mira User's Guide for further information about adding labels to images.

The label attributes and the label text can be changed after the label is created by using the buttons on the Label toolbar on the image window. See the Mira User's Guide for further information.

Example

This example produced the result shown above. The following script fragment opens multiple images into a window, then tracks a centroid position through the image set. A label containing the centroid coordinates is drawn at each position on each image. After each image, the centroid coordinates are used as starting coordinates in the Calc method for computing the centroid for the next image in the loop:

 

V = LoadImages()

-- load and display images in a loop

L = CLabels:new( V )

-- create a CLabels object

C = CCentroid:new()

-- create a CCentroid object

x = 192 ; y = 390

-- starting position for centroid

for i=1,V:Count() do

-- loop over all images

  V:SetIndex( i )

-- change to the next image

  I = V:GetImage()

-- attach the current displayed image

  if ( C:Calc( I, x, y ) ) then

 

    x = C:X() ; y = C:Y()

-- get the centroid position

    s = Sprintf("Centroid:\r\n%lg,%lg",x,y)

-- label text

    L:Add( I, x, y, s )

-- draw the label on this image

  end

 

end

 

C:delete()

-- delete the object

L:delete()

-- delete the object

Related Topics

CLabels, CCentroid