axtimwalde/mpicbg

ArrayIndexOutOfBoundsException for MOPS

Closed this issue · 4 comments

Hi,

I'm currently making some experiments with image classification, but I'm very new to this, so apologies in advance, if I should ask something obvious. I have been using the SIFT feature extraction from mpicbg successfully for some classification tasks, and wanted to try MOPS with the same images. However, for some files, I am getting an ArrayIndexOutOfBoundsException.

The code looks similar to this:

BufferedImage image = ImageIO.read(new File("chair_0033.jpg"));

BufferedImageOp grayscaleOp = new ColorConvertOp(ColorSpace.getInstance(CS_GRAY), null);
BufferedImage greyscaleImage = new BufferedImage(image.getWidth(), image.getHeight(), TYPE_BYTE_GRAY);
grayscaleOp.filter(image, greyscaleImage);

MOPS mops = new MOPS(new FloatArray2DMOPS(new FloatArray2DMOPS.Param()));
mops.extractFeatures(new ByteProcessor(greyscaleImage));

Which gives me the following exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 36
    at mpicbg.imagefeatures.FloatArray2DMOPS.processCandidate(FloatArray2DMOPS.java:337)
    at mpicbg.imagefeatures.FloatArray2DMOPS.runOctave(FloatArray2DMOPS.java:432)
    at mpicbg.imagefeatures.FloatArray2DMOPS.run(FloatArray2DMOPS.java:479)
    at mpicbg.imagefeatures.FloatArray2DMOPS.extractFeatures(FloatArray2DMOPS.java:758)
    at mpicbg.ij.MOPS.extractFeatures(MOPS.java:104)
    at mpicbg.ij.FeatureTransform.extractFeatures(FeatureTransform.java:53)
    at my.package.MopsIssue.main(MopsIssue.java:31)

I have attached a sample file, where the issue occurs. Any hints or feedback appreciated.

This does look like a bug coming from a rounding error.

@qqilihq
For what it's worth, using a different set of parameters can avoid the issue:

Param param = new FloatArray2DMOPS.Param();
param.minOctaveSize =  64;
param.maxOctaveSize = 128;

MOPS mops = new MOPS(new FloatArray2DMOPS( param ));

@axtimwalde
I'll file a pull request shortly with a fix

Cool, thank you!!

@qqilihq
Some things I forgot to mention:

  • there's no guarantee that those parameters will work for every image, they just happened to avoid the bug for that particular one.
  • It's also probable that those parameters are worse (in terms of performance) than the defaults
  • If things are urgent, you can grab my fix directly from bogovicj@372cd96

Resolved by #27