Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert slides to DeepZoom #4

Closed
tlestang opened this issue Jul 12, 2019 · 1 comment
Closed

Convert slides to DeepZoom #4

tlestang opened this issue Jul 12, 2019 · 1 comment
Assignees

Comments

@tlestang
Copy link

tlestang commented Jul 12, 2019

OpenSeadragon cannot read whole slide images formats (from Aperio, Hamamatsu and so on)
But it can read DeepZoom.
So whole slide images must be first converted to Deepzoom.

The main tool for that is libvips, it relies on openslide to read whole slide images.
libvips defines a function vips_dzsave

int
vips_dzsave (VipsImage *in,
             const char *name,
             ...);

Can also be used from the command line vips utility

vips dzsave CMU-3.ndpi CMU-3.dzi

How to use libvips and openslide from javascript ?

Someone asking for node.js bindings for openslide on the
openslide repo (openslide/openslide#204)

Main libvips developer John Cupitt suggests to use sharp

sharp

sharp('input.tiff')
 .png()
 .tile({
   size: 512
 })
 .toFile('output.dz', function(err, info) {
   // output.dzi is the Deep Zoom XML definition
   // output_files contains 512x512 tiles grouped by zoom level
 });

The documentation used to include installation instructions for installing sharp with openslide support but now no mention of openslide anymore...

I naively tried

sharp('CMU-3.ndpi')
  .png()
  .tile({
    size: 512
  })
  .toFile('output.dz', function(err, info) {
    // output.dzi is the Deep Zoom XML definition
    // output_files contains 512x512 tiles grouped by zoom level
  });

but doesn't produce any output.

In may 2017 jcupitt writes

@xmkevin, sharp can read all the formats that openslide can read,
you just need to enable openslide support. There are some notes in the README.

Somehow one may has to /enable openslide support/ and I'm not sure what that means. Potentially useful to figure it out because sharp, coupled with openslide seems to be able to do precisely what we are looking for.

node-vips

Sept. 2017: Experimental node binding for libvips
(https://github.com/libvips/node-vips)

The gitHub repo provide an example reading a whole slide image with openslide:

var vips = require('vips');

// get a rect from a level
// autocrop trims off pixels outside the image bounds
var image = vips.Image.openslideload('somefile.svs', {level: 2, autocrop: true});
console.log('level size:', image.width, 'x', image.height);
// try 'vipsheader -a somefile.svs' at the command-line to see all the metadata
// fields you can get
console.log('associated images are:', image.get('slide-associated-images'));
// crop is left, top, width, height in pixels
// images are RGBA with premultiplication taken out
image.crop(100, 100, 1000, 1000).writeToFile('x.png');

// extract an associated image
image = vips.Image.openslideload('somefile.svs', {associated: 'label'});
image.writeToFile('label.png');

That also looks like exactly what we'd need.

  • question What bother writing node bindings when sharp can do it ? Isn't it redundant with sharp ? How does sharp differ from libvips (in terms of functionalities)

!!! !!! Had to update libvips to the latest version.
Didn't work with the libvips-dev available in the ubuntu repo, so installed from source.

Now possible to read a slide using vips in javascript

const vips = require('vips');
var image = vips.Image.openslideload('CMU-3.ndpi')
  • ISSUE Cannot figure out how to use dzsave using javascript bindings
// None of these work
var test = vips.Image.dzsave('CMU-3.ndpi', 'test.dz')
image.dzsave('output.dz')
vips.Image.dzsave('CMU-3.dzi')

dzsave is only mentioned in lib/autogen.js

  vips.Image.prototype.dzsave = function (filename, options) {
    return vips.call('dzsave', this, filename, options);
  };

  vips.Image.prototype.dzsaveBuffer = function (options) {
    return vips.call('dzsave_buffer', this, options);
  };
@abhidg
Copy link
Contributor

abhidg commented Jan 14, 2020

This is being worked on in https://github.com/OxfordRSE/Electron-Sight/tree/i4-convert-slides-deepzoom. Opening .ndpi files now automatically converts to dzi and shows it.
Still to be done:

  • Do not recreate dzi if it already exists
  • Actually synchronize with vips process to report progress
  • Warn if vips not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants