I am using OpenIMAJ library, it is working well on "JPEG" and "PNG" files but on tiff files it is giving me an error. Here is the code:
import org.openimaj.image.ImageUtilities;
import org.openimaj.image.MBFImage;
....
File file = new File("/home/mosab/Desktop/input/tif.tif");
MBFImage input = ImageUtilities.readMBF(file);
And here is the error:
Exception in thread "main" java.io.IOException: org.apache.sanselan.ImageReadException: Tiff: unknown compression: 7
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:189)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:126)
at org.openimaj.image.ImageUtilities.readMBF(ImageUtilities.java:355)
at org.mosab.TestOpenIMAJ.TestKmeans.main(TestKmeans.java:49)
Caused by: org.apache.sanselan.ImageReadException: Tiff: unknown compression: 7
at org.apache.sanselan.formats.tiff.datareaders.DataReader.decompress(DataReader.java:135)
at org.apache.sanselan.formats.tiff.datareaders.DataReaderStrips.readImageData(DataReaderStrips.java:96)
at org.apache.sanselan.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:505)
at org.apache.sanselan.formats.tiff.TiffDirectory.getTiffImage(TiffDirectory.java:163)
at org.apache.sanselan.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:441)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1264)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1163)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1136)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:187)
... 3 more
This is the tiff file (GeoTiff specifically) that I am using:
"https://drive.google.com/file/d/0ByKaCojxzNa9MWxPTUJjZURHR1E/view?usp=sharing"
Does it mean that OpenIMAJ library doesn't support tiff format/GeoTiff?
I supposed that OpenIMAJ doesn't support tiff so I tried "TwelveMonkeys" library to read that file. "TwelveMonkeys" library separately/alone is able to read the file. Therefore, I imported the TwelveMonkeys library to work together with OpenIMAJ and hence support tiff files and that worked for some tiff files but for that file It didn't work (Although "TwelveMonkeys" was able to read it alone in seperate project) and I got this exception:
Exception in thread "main" java.io.IOException: Resetting to invalid mark
at java.io.BufferedInputStream.reset(BufferedInputStream.java:448)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:185)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:126)
at org.openimaj.image.ImageUtilities.readMBF(ImageUtilities.java:355)
at org.mosab.TestOpenIMAJ.TestKmeans.main(TestKmeans.java:49)
Later when I tracked the error message I found something may be related to the size of the file because it is around 26mb and I noticed that the error originates from the method "read" of class "org.openimaj.image.ExtendedImageIO" which I think it uses size of maximum 10mb:
public static BufferedImage read(InputStream input) throws IOException {
if (input == null) {
throw new IllegalArgumentException("input == null!");
}
final NonClosableInputStream buffer = new NonClosableInputStream(input);
buffer.mark(10 * 1024 * 1024); // 10mb I think here is the problem
BufferedImage bi;
try {
bi = readInternal(buffer);
} catch (final Exception ex) {
bi = null;
}
if (bi == null) {
buffer.reset();
try {
bi = Sanselan.getBufferedImage(buffer);
} catch (final Throwable e) {
throw new IOException(e);
}
}
return bi;
}
So how can I fix this issue and read that tiff file in OpenIMAJ(To further apply facilities, OpenIMAJ provides, on it like clustering/segmentation)?