makeRectangle(x, y, w, h, r) yields different corner radii

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

makeRectangle(x, y, w, h, r) yields different corner radii

Bill Christens-Barry
I've noticed that the macro command:

    makeRectangle(<topLeftX>, <topLeftY>, <width>, <height>, <radius>)

for making a rectangular ROI with rounded corners actually results in a rectangle with 4 different corner shapes (MacOS 10.9.5, ImageJ 1.49i4). For example, the macro command:

    makeRectangle(100, 100, 120, 40, 11);
    run("Draw");

leads to a rectangle in which each of the corners has a different shape. The displayed ROI outline for the rounded rectangle has the same incorrect shape, and I've consistently seen this effect with a variety of different odd and even corner radius values.

This macro command passes equal corner width and corner height values in its call to the java.awt.geom.RoundRectangle2D method (see http://imagej.nih.gov/ij/source/ij/gui/Roi.java). The upper left and lower right corners of the created ROI are circular arcs but they have different radii, and the upper right and lower left corners are noncircular ellipse quadrants.

The result is that the upper right corner appears to be one pixel too tall, while the lower left corner appears to be one pixel too wide. The lower right corner appears to be both too wide and too tall by one pixel each.

I suspect that the problem arises in java.awt.geom.RoundRectangle2D, but haven't tested this. Is this a known issue and, better yet, is there a known or suggested solution?

Thanks,

Bill

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: makeRectangle(x, y, w, h, r) yields different corner radii

Rasband, Wayne (NIH/NIMH) [E]
On Sep 30, 2014, at 10:30 AM, Bill Christens-Barry wrote:

> I've noticed that the macro command:
>
>    makeRectangle(<topLeftX>, <topLeftY>, <width>, <height>, <radius>)
>
> for making a rectangular ROI with rounded corners actually results in a rectangle with 4 different corner shapes (MacOS 10.9.5, ImageJ 1.49i4). For example, the macro command:
>
>    makeRectangle(100, 100, 120, 40, 11);
>    run("Draw");
>
> leads to a rectangle in which each of the corners has a different shape.

This bug is fixed in the latest ImageJ daily build (1.49i6). View the fix (in Roi.java) at

   https://github.com/imagej/imagej1/commits

-wayne


> The displayed ROI outline for the rounded rectangle has the same incorrect shape, and I've consistently seen this effect with a variety of different odd and even corner radius values.
>
> This macro command passes equal corner width and corner height values in its call to the java.awt.geom.RoundRectangle2D method (see http://imagej.nih.gov/ij/source/ij/gui/Roi.java). The upper left and lower right corners of the created ROI are circular arcs but they have different radii, and the upper right and lower left corners are noncircular ellipse quadrants.
>
> The result is that the upper right corner appears to be one pixel too tall, while the lower left corner appears to be one pixel too wide. The lower right corner appears to be both too wide and too tall by one pixel each.
>
> I suspect that the problem arises in java.awt.geom.RoundRectangle2D, but haven't tested this. Is this a known issue and, better yet, is there a known or suggested solution?
>
> Thanks,
>
> Bill
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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