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).
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/
# 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")
"/home/isaiah/.julia/OpenSlide/test/CMU-1-Small-Region.svs"
# load the slide
@time img = OpenSlide.open_slide(imgfile)
elapsed time: 0.046075237 seconds (1129724 bytes allocated)
OpenSlideImage("/home/isaiah/.julia/OpenSlide/test/CMU-1-Small-Region.svs",1,[[2220,2967]],Ptr{openslide_t} @0x0000000005a6f000)
# read the entire level
@time imgdata = OpenSlide.read_slide(img);
elapsed time: 0.287445549 seconds (68811292 bytes allocated)
arraysize(imgdata)
(2220,2967,3)
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,:])
PyObject <matplotlib.image.AxesImage object at 0xdb76310>
# 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)
figure(figsize=[2,2])
imshow(imgdata2)
PyObject <matplotlib.image.AxesImage object at 0xa9ce510>
# get image properties
props = OpenSlide.properties(img)
props["tiff.ResolutionUnit"]
"inch"
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).
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
libopenslide.jl::_rgbfromrowflat