For those who might be interested in the subject.
This is a really simple way to create online viewers for your hi-res images.
In addition to bio-formats library you will need PyramidIO:
https://github.com/usnistgov/pyramidio
and the implementation of PartialImageReader interface:
- Code: Select all
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.lang.NotImplementedException;
import loci.formats.FormatException;
import loci.formats.ImageReader;
import loci.formats.gui.BufferedImageReader;
import gov.nist.isg.pyramidio.PartialImageReader;
public class BioFormatsPartialImageReader implements PartialImageReader {
private BufferedImageReader bufferedImageReader;
private ImageReader imageReader;
public BioFormatsPartialImageReader(ImageReader imageReader) {
this.imageReader = imageReader;
bufferedImageReader = new BufferedImageReader(imageReader);
}
public BufferedImage read() throws IOException {
throw new NotImplementedException("XXX");
}
public BufferedImage read(Rectangle rectangle) throws IOException {
try {
return bufferedImageReader.openImage(0, rectangle.x, rectangle.y,
rectangle.width, rectangle.height);
} catch (FormatException e) {
throw new IOException(e);
}
}
public int getWidth() {
return imageReader.getSizeX();
}
public int getHeight() {
return imageReader.getSizeY();
}
}
Then, to create the pyramid:
- Code: Select all
public class App {
public static void main(String[] args) {
ImageReader imageReaderBF = new ImageReader();
try {
imageReaderBF.setId("path_to_you_file");
ScalablePyramidBuilder spb = new ScalablePyramidBuilder(tileSize, tileOverlap, tileFormat, "dzi");
FilesArchiver archiver = new DirectoryArchiver(new File("path_to_output_folder"));
PartialImageReader pir = new BioFormatsPartialImageReader(imageReaderBF);
spb.buildPyramid(pir, "pyramidName", archiver, 1, amout_of_image_to_cache);
} catch (FormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
The resulting pyramid can be used with OpenSeadragon library to create online viewer:
- Code: Select all
<div id="openseadragon1" style="width: 800px; height: 600px;"></div>
<script src="openseadragon.min.js"></script>
<script type="text/javascript">
var viewer = OpenSeadragon({
id: "openseadragon1",
prefixUrl: "images/",
tileSources: "output2/pyramidName.dzi"
});
</script>
Example (processed from 119780x102791 pixels, TIFF, JPEG-compressed ):
http://folk.uio.no/dmitrd/openseadragon/