ShapeRoi OvalRoi preservation unintuitiveness / bug

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

ShapeRoi OvalRoi preservation unintuitiveness / bug

Ben Woodcroft
Hi all,

ShapeRoi is doing something here that to me, seems untintuitive, if not an
outright bug:
(tried on Windows XP using ImageJ 1.37v and 1.38p on windows). Haven't tried
it elsewhere.

The corner of the square containing the oval is included when it is just an
oval, but not when to a ShapeRoi using the constructor:



CODE:
import ij.gui.OvalRoi;
import ij.gui.ShapeRoi;

public class ShapeRoiBug {
    public static void main(String[] args) {
        OvalRoi or1 = new OvalRoi(0, 0, 3, 3);
        System.out.println ("corner contained oval: "+ or1.contains(0, 0));

        ShapeRoi shape = new ShapeRoi(or1);
        System.out.println("corner contained shape: "+ shape.contains(0,
0));
    }
}



PRODUCES:
corner contained oval: false
corner contained shape: true


For further visualisation, this is what happens when I iterate over the
square using Roi.contains():
printing OvalRoi:
0 1 0
1 1 1
0 1 0
printing ShapeRoi:
1 1 1
1 1 1
1 1 1



So it seems ShapeRoi is not preserving the original roi properly. Is that
normal?

Thanks,
ben
Reply | Threaded
Open this post in threaded view
|

Re: ShapeRoi OvalRoi preservation unintuitiveness / bug

Michael Schmid
Hi Ben,

you are right, OvalRoi.contains(x,y) does not work the same
way as Java handles selections. I'll suggest a fix to Wayne
in a separate mail, but don't expect it to be implemented very
soon, I think he is out of office for a few days.

Michael
________________________________________________________________

On 6 May 2007, at 03:57, Ben Woodcroft wrote:

> Hi all,
>
> ShapeRoi is doing something here that to me, seems untintuitive, if  
> not an
> outright bug:
> (tried on Windows XP using ImageJ 1.37v and 1.38p on windows).  
> Haven't tried
> it elsewhere.
(...)
Reply | Threaded
Open this post in threaded view
|

Re: ShapeRoi OvalRoi preservation unintuitiveness / bug

Ben Woodcroft
Hi again,

Thanks for looking into that. I seem to be having many issues with the
contains() of Roi and it's subclasses. Here is another such example, this
time from PointRoi (tested on Windows XP and Ubuntu Edgy using ImageJ 1.37vand
1.38p)

CODE:
import ij.ImagePlus;
import ij.gui.PointRoi;
import ij.process.ByteProcessor;

public class PointRoiContains {
    public static void main(String[] args){
        PointRoi points;

        points = new PointRoi(3, 6);
        System.out.println(points.contains(3, 6));
        System.out.println(points.contains(0, 0));

        points = new PointRoi(new int[]{3}, new int[]{6}, 1);
        System.out.println(points.contains(3, 6));
        System.out.println(points.contains(0, 0));

        ImagePlus img = new ImagePlus("test", new ByteProcessor(10,10));
        img.show();
        points = new PointRoi(3, 6, img);
        System.out.println(points.contains(3, 6));
        System.out.println(points.contains(0, 0));

        // maybe getMask() can be used to get around the problem
        System.out.println(points.getMask().getPixel(3, 6));
        System.out.println(points.getMask().getPixel(0, 0));
    }
}




PRODUCES:
false
false
false
false
false
false
0
255



According to the Javadoc, "This class represents selection consisting of one
or more points."

So I have 2 concerns:

   1. contains() does not seem to work when used in this context.
   2. getMask() returns a mask that is relative to the bounding box given
   by getBounds()? If so I did not expect that, and I could not find
   documentation to support that hypothesis.

Thanks,
ben

On 5/8/07, Michael Schmid <[hidden email]> wrote:

>
> Hi Ben,
>
> you are right, OvalRoi.contains(x,y) does not work the same
> way as Java handles selections. I'll suggest a fix to Wayne
> in a separate mail, but don't expect it to be implemented very
> soon, I think he is out of office for a few days.
>
> Michael
> ________________________________________________________________
>
> On 6 May 2007, at 03:57, Ben Woodcroft wrote:
>
> > Hi all,
> >
> > ShapeRoi is doing something here that to me, seems untintuitive, if
> > not an
> > outright bug:
> > (tried on Windows XP using ImageJ 1.37v and 1.38p on windows).
> > Haven't tried
> > it elsewhere.
> (...)
>
Reply | Threaded
Open this post in threaded view
|

Re: ShapeRoi OvalRoi preservation unintuitiveness / bug

Wayne Rasband
In reply to this post by Ben Woodcroft
This bug is fixed in ImageJ 1.38r, thanks to an improved  
OvalRoi.contains() method contributed by Michael Schmid. The improved  
version works the same way as ShapeRoi.contains() and as the  
Edit>Fill command. V1.38r will be available by the end of this week.

-wayne

On May 5, 2007, at 9:57 PM, Ben Woodcroft wrote:

> Hi all,
>
> ShapeRoi is doing something here that to me, seems untintuitive, if  
> not an
> outright bug:
> (tried on Windows XP using ImageJ 1.37v and 1.38p on windows).  
> Haven't tried
> it elsewhere.
>
> The corner of the square containing the oval is included when it is  
> just an
> oval, but not when to a ShapeRoi using the constructor:
>
>
>
> CODE:
> import ij.gui.OvalRoi;
> import ij.gui.ShapeRoi;
>
> public class ShapeRoiBug {
>    public static void main(String[] args) {
>        OvalRoi or1 = new OvalRoi(0, 0, 3, 3);
>        System.out.println ("corner contained oval: "+ or1.contains
> (0, 0));
>
>        ShapeRoi shape = new ShapeRoi(or1);
>        System.out.println("corner contained shape: "+ shape.contains
> (0,
> 0));
>    }
> }
>
>
>
> PRODUCES:
> corner contained oval: false
> corner contained shape: true
>
>
> For further visualisation, this is what happens when I iterate over  
> the
> square using Roi.contains():
> printing OvalRoi:
> 0 1 0
> 1 1 1
> 0 1 0
> printing ShapeRoi:
> 1 1 1
> 1 1 1
> 1 1 1
>
>
>
> So it seems ShapeRoi is not preserving the original roi properly.  
> Is that
> normal?
>
> Thanks,
> ben
Reply | Threaded
Open this post in threaded view
|

Re: ShapeRoi OvalRoi preservation unintuitiveness / bug

Ben Woodcroft
In reply to this post by Ben Woodcroft
fantastic! so quick..

The contains confusion now appears gone. However, the output of the code
from the previous post now becomes:
corner contained oval: true
corner contained shape: true
printing OvalRoi:
1 1 1
1 1 1
1 1 1
printing ShapeRoi:
1 1 1
1 1 1
1 1 1

It appears the OvalRoi constructor is now also changed functionality,
exploring more:

CODE:
import roi.RoiUtil;
import ij.gui.OvalRoi;
import ij.gui.Roi;
import ij.gui.ShapeRoi;

public class ShapeRoiBug {
    public static void main(String[] args) {
        OvalRoi or1;
        ShapeRoi shape;

        or1 = new OvalRoi(0, 0, 3, 3);
        System.out.println("corner contained oval: "+ or1.contains(0, 0));

        shape = new ShapeRoi(or1);
        System.out.println ("corner contained shape: "+ shape.contains(0,
0));

        log(or1);
        log(shape);


        or1 = new OvalRoi(0, 0, 3, 5);
        System.out.println("corner contained oval: "+ or1.contains(0, 0));

        shape = new ShapeRoi(or1);
        System.out.println("corner contained shape: "+ shape.contains(0,
0));

        log(or1);
        log(shape);


        or1 = new OvalRoi(0, 0, 4, 4);
        System.out.println("corner contained oval: "+ or1.contains(0, 0));

        shape = new ShapeRoi(or1);
        System.out.println ("corner contained shape: "+ shape.contains(0,
0));

        log(or1);
        log(shape);


        or1 = new OvalRoi(0, 0, 5, 5);
        System.out.println("corner contained oval: "+ or1.contains(0, 0));

        shape = new ShapeRoi(or1);
        System.out.println("corner contained shape: "+ shape.contains(0,
0));

        log(or1);
        log(shape);
    }

    private static void log(Roi roi) {
        RoiUtil.logRoi(roi);  //this is my code for printing an Roi, which
iterates over the bounding rectangle with contains()
    }
}

PRODUCES
corner contained oval: true
corner contained shape: true
1 1 1
1 1 1
1 1 1

1 1 1
1 1 1
1 1 1

corner contained oval: false
corner contained shape: false
0 1 1 1 0
1 1 1 1 1
0 1 1 1 0

0 1 1 1 0
1 1 1 1 1
0 1 1 1 0

corner contained oval: false
corner contained shape: false
0 1 1 0
1 1 1 1
1 1 1 1
0 1 1 0

0 1 1 0
1 1 1 1
1 1 1 1
0 1 1 0

corner contained oval: false
corner contained shape: false
0 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
0 1 1 1 0

0 1 1 1 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
0 1 1 1 0


Also, any news on the PointRoi bug?

Thanks,
ben

On 5/8/07, Rasband Wayne < [hidden email]> wrote:

> Hi Ben
>
> This bug is fixed in ImageJ 1.38r, which is attached. It has a new
> OvalRoi.contains method, contributed by Michael Schmid, that is
> consistent with ShapeRoi.contains() and also with the the Edit>Fill
> command.
>
> -wayne
>
>
> On May 5, 2007, at 9:57 PM, Ben Woodcroft wrote:
>
> > Hi all,
> >
> > ShapeRoi is doing something here that to me, seems untintuitive, if
> > not an
> > outright bug:
> > (tried on Windows XP using ImageJ 1.37v and 1.38p on windows).
> > Haven't tried
> > it elsewhere.
> >
> > The corner of the square containing the oval is included when it is
> > just an
> > oval, but not when to a ShapeRoi using the constructor:
> >
> >
> >
> > CODE:
> > import ij.gui.OvalRoi;
> > import ij.gui.ShapeRoi;
> >
> > public class ShapeRoiBug {
> >    public static void main(String[] args) {
> >        OvalRoi or1 = new OvalRoi(0, 0, 3, 3);
> >         System.out.println ("corner contained oval: "+ or1.contains
> > (0, 0));
> >
> >        ShapeRoi shape = new ShapeRoi(or1);
> >        System.out.println("corner contained shape: "+ shape.contains
> > (0,
> > 0));
> >    }
> > }
> >
> >
> >
> > PRODUCES:
> > corner contained oval: false
> > corner contained shape: true
> >
> >
> > For further visualisation, this is what happens when I iterate over
> > the
> > square using Roi.contains():
> > printing OvalRoi:
> > 0 1 0
> > 1 1 1
> > 0 1 0
> > printing ShapeRoi:
> > 1 1 1
> > 1 1 1
> > 1 1 1
> >
> >
> >
> > So it seems ShapeRoi is not preserving the original roi properly.
> > Is that
> > normal?
> >
> > Thanks,
> > ben
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: ShapeRoi OvalRoi preservation unintuitiveness / bug

Ben Woodcroft
In reply to this post by Ben Woodcroft
On 5/8/07, Rasband Wayne <[hidden email]> wrote:

>
> > The contains confusion now appears gone. However, the output of the
> > code from the previous post now becomes:
> > corner contained oval: true
> > corner contained shape: true
> > printing OvalRoi:
> > 1 1 1
> > 1 1 1
> > 1 1 1
> > printing ShapeRoi:
> > 1 1 1
> > 1 1 1
> > 1 1 1
> >
> > It appears the OvalRoi constructor is now also changed
> > functionality, exploring more:
>
> The OvalRoi constructor did not change.


Aplogies. When I use getMask() with the with 1.37v and 1.38p I get the
111,111,111, but when I use contains I get 010,111,010.

The 1.38r fix has now made them consistent. Apologies for being slow.

> Also, any news on the PointRoi bug?
>
> I would expect PointRoi.contains() to return false for a single point
> since a point in ImageJ, and in Java, has a width and height of zero.
>
> -wayne


My confusion with the PointRoi class stemmed from the fact that I was
thinking of it as a collection of points, rather than an area of contained
within a Polygon defined by those points. I might suggest changing the
javadoc class description of PointRoi to something that takes this into
account. Currently it is:

This class represents selection consisting of one or more points.


I will now define a new class myself, which is basically a set of
points/pixels, and contains(x,y) only returns true if (x,y) is one of those
points - hopefully I'll release it too.


Thank a lot for your time,
ben
Reply | Threaded
Open this post in threaded view
|

Re: ShapeRoi OvalRoi preservation unintuitiveness / bug

Wayne Rasband
The PointRoi class is a collection of points. In ImageJ 1.38r, it has a
contains(x,y) method that only returns true if (x,y) is one of the
points.

-wayne

> My confusion with the PointRoi class stemmed from the fact that I was
> thinking of it as a collection of points, rather than an area of
> contained
> within a Polygon defined by those points. I might suggest changing the
> javadoc class description of PointRoi to something that takes this into
> account. Currently it is:
>
> This class represents selection consisting of one or more points.
>
>
> I will now define a new class myself, which is basically a set of
> points/pixels, and contains(x,y) only returns true if (x,y) is one of
> those
> points - hopefully I'll release it too.
>
>
> Thank a lot for your time,
> ben
>