OpenSlide.jl

This package is a Julia language wrapper for OpenSlide.

OpenSlide is a vendor-neutral library providing a common API to read virtual slide images generated by several different microscope vendors.

Julia is a new language for technical computing with familiar and script-friendly syntax, an extensive mathematical library and array-oriented computing built-in, and a high performance just-in-time compiler (< 2x of C code).

Installation

The package may be added by running the following command at the Julia prompt:

    julia> Pkg.add("OpenSlide")

Source code for the package is available from: http://github.com/ihnorton/OpenSlide.jl.git

The example image used in this notebook is available from: http://openslide.cs.cmu.edu/download/openslide-testdata/

High-level usage


In [1]:
# load the package
using OpenSlide

# construct path to test file inside of directory
# note: test file is not part of code distribution and must be downloaded separately.

imgfile = Pkg.dir("OpenSlide", "test", "CMU-1-Small-Region.svs")


Out[1]:
"/home/isaiah/.julia/OpenSlide/test/CMU-1-Small-Region.svs"

In [2]:
# load the slide

@time img = OpenSlide.open_slide(imgfile)


elapsed time: 0.046075237 seconds (1129724 bytes allocated)
Out[2]:
OpenSlideImage("/home/isaiah/.julia/OpenSlide/test/CMU-1-Small-Region.svs",1,[[2220,2967]],Ptr{openslide_t} @0x0000000005a6f000)

In [2]:
# read the entire level

@time imgdata = OpenSlide.read_slide(img);


elapsed time: 0.287445549 seconds (68811292 bytes allocated)

In [3]:
arraysize(imgdata)


Out[3]:
(2220,2967,3)

In [13]:
using PyPlot

# Plot a sub-region
# We keep the figure small in order to reduce the size of the notebook, but larger figure size will work fine.
figure(figsize=[2,2])
imshow(imgdata[1200:1500,800:1100,:])


Out[13]:
PyObject <matplotlib.image.AxesImage object at 0xdb76310>

In [6]:
# read a given extent and level (shown for example, but note that this image has only one level!)

@time imgdata2 = OpenSlide.read_slide(img; origin = [1200,800], extent = [300,300], level = 1);


elapsed time: 0.001220545 seconds (901960 bytes allocated)

In [12]:
figure(figsize=[2,2])
imshow(imgdata2)


Out[12]:
PyObject <matplotlib.image.AxesImage object at 0xa9ce510>

In [14]:
# get image properties

props = OpenSlide.properties(img)

props["tiff.ResolutionUnit"]


Out[14]:
"inch"

Low-level API

The package also includes wrappers for all of the non-deprecated functions in openslide.h (see src/libopenslide.jl). All functions have been stripped of the openslide_ prefix, except for openslide_open (so as not to conflict with Julia's open function).

Function listing

    get_property_names,
    get_property_value,
    can_open,
    openslide_open,
    get_level_count,
    close_slide,
    get_level0_dimensions,
    get_level_dimensions,
    get_level_downsample,
    get_best_level_for_downsample,
    read_region,
    get_associated_image_names,
    read_associated_image,
    get_error,
    openslide_version

Notes

  • Julia's default array ordering is column-major. Data from OpenSlide must be appropriately converted, see libopenslide.jl::_rgbfromrowflat