Login  Register

Re: Point Tool >> getSelectionBounds >> Discrepant Coordinates

Posted by Peter Haub on Jan 08, 2021; 11:28am
URL: http://imagej.273.s1.nabble.com/behavior-of-variable-when-function-is-called-tp5024336p5024342.html

Hi Herbie,

the macro functions calls the function
getBounds() in Functions.java.
This functions returns floating point values after internally calling
roi.getFloatBounds() .

Your plugin returns roi.getBounds().x and roi.getBounds().y
which are floor(roi.getFloatBounds().x) and floor(roi.getFloatBounds().y).

Hope that helps

Peter

On 08.01.2021 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

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