mbedward / jaitools

Raster image processing for Java developers
17 stars 15 forks source link

ROIGeometry must handle the emtpy geometry case #225

Closed aaime closed 8 years ago

aaime commented 10 years ago

While working with imagery it may happen that a call to intersect results in an empty geometry, but ROIGeometry fails if passed an empty one. We should behave normally with it too (it's just a case in which the ROI is empty)

mbedward commented 10 years ago

Sounds good Andrea. Are you working on it or do you want me to have a look ?

aaime commented 10 years ago

I'm not working on it right now. So if you feel bored go right ahead :-)

mbedward commented 10 years ago

I've been adding some unit tests in which ROIGeometry is passed an empty Geometry but haven't seen any failures yet. Can you give me an example that provokes an error ?

aaime commented 10 years ago

I've seen it happening as one tries to get and use the image version of the roigeometry out of an empty geometry

mbedward commented 10 years ago

Cool - I'll delve into that

mbedward commented 10 years ago

OK - so I see the problem now. How best to handle it ? JAI doesn't seem to like creating empty images (ImageLayout constructor throws an exception if passed zero width / height). Maybe add a new ImageOp for an empty image which could be used by VectorBinarize when the geometry is empty ? Would that work with your use cases Andrea ? Other ideas also welcome :)

aaime commented 8 years ago

Stumbled into this one again... we need to check what ROIShape is doing in the same situation.

aaime commented 8 years ago

Ok, tested it with ROIShape, and it just fails:

@Test
    public void testEmptyIntersection() {
        ROIShape rs1 = new ROIShape(new Rectangle2D.Double(0, 0, 10, 10));
        ROIShape rs2 = new ROIShape(new Rectangle2D.Double(20, 0, 10, 10));
        ROI intersection = rs1.intersect(rs2);
        intersection.getAsImage();
    }

results in:

java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0
    at java.awt.image.SampleModel.<init>(SampleModel.java:126)
    at java.awt.image.MultiPixelPackedSampleModel.<init>(MultiPixelPackedSampleModel.java:147)
    at java.awt.image.MultiPixelPackedSampleModel.<init>(MultiPixelPackedSampleModel.java:107)
    at java.awt.image.Raster.createPackedRaster(Raster.java:846)
    at java.awt.image.Raster.createPackedRaster(Raster.java:588)
    at java.awt.image.BufferedImage.<init>(BufferedImage.java:442)
    at javax.media.jai.ROIShape.getAsImage(ROIShape.java:1129)
    at org.jaitools.imageutils.ROIGeometryTest.testEmptyIntersection(ROIGeometryTest.java:356)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Sooo... I must have been seeing things! Closing for the moment, until I have a new vision :-p