We're Hiring!

Hi-res bio-formats 2D images to DeepZoom (OpenSeadragon)

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

Hi-res bio-formats 2D images to DeepZoom (OpenSeadragon)

Postby darwinjob » Mon Dec 05, 2016 4:15 pm

Hi
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/
darwinjob
 
Posts: 18
Joined: Mon Sep 16, 2013 11:58 am

Re: Hi-res bio-formats 2D images to DeepZoom (OpenSeadragon)

Postby hflynn » Tue Dec 13, 2016 1:35 pm

Hi,

Thanks very much for sharing this. Is it okay if we aim to reproduce this info as an example in one of our code repos on GitHub so it is easier for the wider community to find in the future? We will of course credit you,

Thanks,
Helen
hflynn
 
Posts: 97
Joined: Tue Sep 25, 2012 1:59 pm
Location: Dundee

Re: Hi-res bio-formats 2D images to DeepZoom (OpenSeadragon)

Postby darwinjob » Tue Dec 13, 2016 4:08 pm

Of course! Happy to help :)
Peace 8-)
darwinjob
 
Posts: 18
Joined: Mon Sep 16, 2013 11:58 am


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 1 guest

cron