Login  Register

Re: Point Tool >> getSelectionBounds >> Discrepant Coordinates

Posted by Herbie on Jan 11, 2021; 10:47am
URL: http://imagej.273.s1.nabble.com/behavior-of-variable-when-function-is-called-tp5024336p5024358.html

Dear Wayne,
dear Michael Schmid,

many thanks for your immediate help and action!

Point-RoI coordinates always appear now as expected when using:
   x_0 = roi.getBounds().x;
   y_0 = roi.getBounds().y;

Best

Herbie

::::::::::::::::::::::::::::::::::::::::::
Am 11.01.21 um 00:54 schrieb Wayne Rasband:

> Hi Herbie,
>
> Thanks to Michael Schmid, the latest daily build (1.53h37) fixes bugs that caused the roi.getBounds() method to not work as expected with polyline and point selections on images zoomed more than 150%. The getBounds() method returns integer values so there is no need to round or convert to int.
>
> The getSelectionBounds() macro function in the daily build calls roi.getBounds(), so there is also no need to round the values. Use the new Roi.getFloatBounds() macro function to get the bounds as real numbers.
>
> I attached a test macro (with screenshot) that prints and draws the values from Roi.getBounds() (same as getSelectionBounds) and Roi.getFloatBounds().
>
> -wayne
>
>    Overlay.addSelection
>    Roi.getBounds(x, y, width, height)
>    Roi.getFloatBounds(x2, y2, width2, height2)
>    print("getBounds: "+x, y, width, height)
>    print("getFloatBounds: "+x2, y2, width2, height2)
>    makeRectangle(x, y, width, height)
>    Overlay.addSelection
>    makeRectangle(x2, y2, width2, height2)
>    Overlay.addSelection
>
>
>
>
>
>
>> On Jan 8, 2021, at 5:10 AM, Herbie <[hidden email]> 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