Login  Register

Re: Point Tool >> getSelectionBounds >> Discrepant Coordinates

Posted by Michael Schmid on Jan 08, 2021; 10:29am
URL: http://imagej.273.s1.nabble.com/behavior-of-variable-when-function-is-called-tp5024336p5024341.html

Hi Herbie,

when you create a point selection at zoom level > 150% the coordinates
will usually have non-integer values (subpixel resolution). If you have
the point tool (not the multi-point tool), you can get the coordinates
with Edit>Selection>Properties (shortcut y) and 'List coordinates'.

The bounding box with roi.getBounds() is integer. The ROI class also has
a method that returns the bounding box with floating-point values:
    Rectangle2D.Double getFloatBounds()


Michael
________________________________________________________________
On 08.01.21 11:10, Herbie wrote:

> Dear experts and especially Wayne,
>
> please consider the following situation:
>
> A___________________________________________
> 1. Open an 8-bit image with zoom e.g. 400%
> 2. Use the point tool
> 3. Make a point selection at x=5, y=10 according
>     to the coordinates shown in the IJ-toolbar
>
> B___________________________________________
> 1. Run the macro:
>     //
>     getSelectionBounds( x, y, width, height );
>     print( round(x), round(y) );
>     //
> 2. The log-window shows:
>     5 10
>
> C___________________________________________
> 1. Run the compiled plugin:
>     //
>     import java.awt.*;
>     import ij.*;
>     import ij.gui.*;
>     import ij.process.*;
>     import ij.plugin.filter.PlugInFilter;
>     public class My_PlugInFilter implements PlugInFilter {
>      protected ImagePlus imp;
>      public int setup( String arg, ImagePlus imp ) {
>          if ( IJ.versionLessThan( "1.53g" ) )
>              return DONE;
>          if( imp != null ) {
>              this.imp = imp;
>          }
>          return DOES_8G;
>      }
>      public void run( ImageProcessor ip ) {
>          Roi roi = imp.getRoi();
>          int x_0 = (int)Math.round( roi.getBounds().x );
>          int y_0 = (int)Math.round( roi.getBounds().y );
>          IJ.log( ""+x_0+"; "+y_0 );
>      }
>     }
>     //
> 2. The log-window *sometimes* shows:
>     5; 10
> 3. However, in many cases the result is "5; 9", "4; 9", or "4; 10"
> 4. The plugin-result depends on how the point selection was set in the
> zoomed image
> 5. The discrepancy is not observed if the image is not initially zoomed
>
> What am I doing wrong?
>
> Regards
>
> Herbie

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html