Author Topic: AnnotateImage - Feature request  (Read 2295 times)

Offline Armando

  • Newcomer
  • Posts: 22
AnnotateImage - Feature request
« on: 2019 March 14 04:50:19 »
Hi,

I'm a newbie and I've no experience with PI scripts programming. I'm going to suggest a feature to improve AnnotateImage script.
Sorry if I chose a wrong sub-board.

I found that annotations affect all the "expected" objects in the field covered by the frame. So, except for catalogs offering mag values with which filtering objects by mag is possible, all objects are labeled even if barely visible or not visible at all...
I'd like an option to enable a filter to discard objects that are not visible.

I edited the script so that a label won't be added if the value of the pixel at the center of the expected object is too small (I simply added the 1st line of code):

Code: [Select]
if (imageWnd.mainView.image.sample(drawInfo[i].pI.x,drawInfo[i].pI.y, 0) >0.2)
    this.DrawLabel(g, objects[i], this.gprops.labelFields[l], l, font, drawInfo[i].size + hole, drawInfo[i].pI, graphicsScale);

On a stretched image it seems working. Obviously threshold (0.2 in the code) is to be tuned accordingly...
I played with a grayscale photo. Obviously the check should take care of the type of photo (and use L values to properly work).

A better solution could be computing the mean value on the area covered by the object (and the catalog offers the dimension of the object) and setting a threshold slightly higher than background.

What do you think?

Thank You and Clear Skies!
Armando Beneduce

Offline Armando

  • Newcomer
  • Posts: 22
Re: AnnotateImage - Feature request
« Reply #1 on: 2019 March 14 09:33:23 »
I just edited the code used to add labels.
The following code should compute the mean value over the area covered by the object; it seems working but it's too slow:

Code: [Select]
if (this.gprops.showLabels)
{
  g.pen = penLabel;
  var width = imageWnd.mainView.image.width;
  var height = imageWnd.mainView.image.height;
 
  for (var i = 0; i < objects.length; i++)
    if (objects[i]!=null && drawInfo[i])
    {
      var sum=0.0;
      var cont=0;
      var radius = objects[i].diameter / 2 / metadata.resolution;
      var radius_2 = Math.pow(radius, 2);
      for (var m=Math.max(drawInfo[i].pI.x-radius,0); m<Math.min(drawInfo[i].pI.x+radius, width); m++)
        for (var n=Math.max(drawInfo[i].pI.y-radius,0); n<Math.min(drawInfo[i].pI.y+radius, height); n++)
          //if (Math.pow(m-drawInfo[i].pI.x,2)+Math.pow(n-drawInfo[i].pI.y,2)<radius_2)
          if ((m-drawInfo[i].pI.x)*(m-drawInfo[i].pI.x)+(n-drawInfo[i].pI.y)*(n-drawInfo[i].pI.y)<radius_2)
          {
            sum+=imageWnd.mainView.image.sample(m,n, 0);
            cont++;
          }
      //console.writeln("cont: ", cont);
      //if (imageWnd.mainView.image.sample(drawInfo[i].pI.x,drawInfo[i].pI.y, 0) >0.2)
      if (sum/cont>0.2)
        for (var l = 0; l < 8; l++)
          this.DrawLabel(g, objects[i], this.gprops.labelFields[l], l, font, drawInfo[i].size + hole, drawInfo[i].pI, graphicsScale);
    }
}

What is wrong? Could speed be related to image.sample?

Thanks again
Armando

Offline Armando

  • Newcomer
  • Posts: 22
Re: AnnotateImage - Feature request
« Reply #2 on: 2019 March 14 13:19:22 »
I just found that using Matrix (and Matrix.at() in place of image.sample() ) fixes the issue.

Clear Skies!
Armando