Python bindings to OpenSlide

Overview

OpenSlide Python

OpenSlide Python is a Python interface to the OpenSlide library.

OpenSlide is a C library that provides a simple interface for reading whole-slide images, also known as virtual slides, which are high-resolution images used in digital pathology. These images can occupy tens of gigabytes when uncompressed, and so cannot be easily read using standard tools or libraries, which are designed for images that can be comfortably uncompressed into RAM. Whole-slide images are typically multi-resolution; OpenSlide allows reading a small amount of image data at the resolution closest to a desired zoom level.

OpenSlide can read virtual slides in several formats:

Requirements

  • Python >= 3.6
  • OpenSlide >= 3.4.0
  • Pillow

Installation

  1. Install OpenSlide.
  2. pip install openslide-python

More Information

License

OpenSlide Python is released under the terms of the GNU Lesser General Public License, version 2.1.

Comments
  • `MemoryError: Integer overflow in ysize` reading ndpi image

    `MemoryError: Integer overflow in ysize` reading ndpi image

    Context

    Issue type: bug report Operating system: Ubuntu 17.10 (Artful Aardvark) Platform: 64-bit x86 OpenSlide Python version (openslide.__version__): 1.1.1 OpenSlide version (openslide.__library_version__): 3.4.1 Slide format (e.g. SVS, NDPI, MRXS): NDPI

    Details

    When trying to read this NDPI image, size (51200, 38144) ~ 1.82 Gpixels,

    http://openslide.cs.cmu.edu/download/openslide-testdata/Hamamatsu/CMU-1.ndpi

    with OpenSlide, the code

    import openslide
    slide = openslide.OpenSlide("CMU-1.ndpi")
    foo = slide.read_region(location=(0, 0), level=0, size=slide.dimensions)
    

    gives the error

    Traceback (most recent call last):
      File "<input>", line 4, in <module>
      File "/home/rcasero/.conda/envs/elastixity/lib/python3.6/site-packages/openslide/__init__.py", line 223, in read_region
        level, size[0], size[1])
      File "/home/rcasero/.conda/envs/elastixity/lib/python3.6/site-packages/openslide/lowlevel.py", line 260, in read_region
        return _load_image(buf, (w, h))
      File "/home/rcasero/.conda/envs/elastixity/lib/python3.6/site-packages/openslide/lowlevel.py", line 65, in _load_image
        return PIL.Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
      File "/home/rcasero/.conda/envs/elastixity/lib/python3.6/site-packages/PIL/Image.py", line 2398, in frombuffer
        core.map_buffer(data, size, decoder_name, None, 0, args)
    MemoryError: Integer overflow in ysize
    

    Package versions:

    python                    3.6.4                hc3d631a_1
    openslide-python          1.1.1                     <pip>
    Pillow                    5.1.0                     <pip>
    
    defect 
    opened by rcasero 20
  • WindowsError when importing openslide using 64-bit version

    WindowsError when importing openslide using 64-bit version

    Context

    Issue type (bug report perhaps?): Operating system (Windows 10): Platform (64-bit): OpenSlide version (2016-7-17 64 bit release): Slide format (NA):

    Details

    Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "C:\dev_res\python\python2_713\lib\site-packages\openslide\__init__.py", line 29, in <module>
            from openslide import lowlevel
        File "C:\dev_res\python\python2_713\lib\site-packages\openslide\lowlevel.py", line 41, in <module>
            _lib = cdll.LoadLibrary('libopenslide-0.dll')
        File "C:\dev_res\python\python2_713\lib\ctypes\__init__.py", line 440, in LoadLibrary
            return self._dlltype(name)
        File "C:\dev_res\python\python2_713\lib\ctypes\__init__.py", line 362, in __init__
            self._handle = _dlopen(self._name, mode)
    WindowsError: [Error 127] The specified procedure could not be found'
    

    I installed the OpenSlide binaries and added the bin folder to my system path. I then installed python-openslide using pip. I tried same workflow with Python 3.5.3 and encountered the same problem. Interestingly, when I tested this with the 32-bit version of Python(2.7)/OpenSlide I did not have this issue. However, I have a 64-bit machine and would prefer to use the 64-bit versions.

    Not sure if this is a bug or is specific to my configuration. Any help would be greatly appreciated!

    invalid 
    opened by macmatt22 17
  • Remove Feature module to match setuptools >=46.0.0

    Remove Feature module to match setuptools >=46.0.0

    https://github.com/pypa/setuptools/issues/65 https://github.com/pypa/setuptools/issues/2017 https://github.com/openslide/openslide/issues/287

    untested

    opened by userkkw 13
  • Fix failure to find libopenslide-0.dll on Windows

    Fix failure to find libopenslide-0.dll on Windows

    In issue #51 I suggested doing this; it was mentioned in issue #23 as well. On every machine, on which I tried installing the library, I had to edit this line.

    opened by simo1427 9
  • Remove Feature from setup.py

    Remove Feature from setup.py

    Hi,

    from setuptools 46.0, Feature support was completely removed: https://github.com/pypa/setuptools/commit/c71969013d726c5cbd06dc81770ab064f3e783ff and https://github.com/pypa/setuptools/pull/1979.

    There are some Feature usages in this module:

    https://github.com/openslide/openslide-python/blob/8e2c948fa66dcda34e2627b9afcde50ebfa301af/setup.py#L2

    https://github.com/openslide/openslide-python/blob/8e2c948fa66dcda34e2627b9afcde50ebfa301af/setup.py#L19

    So suppose these should be removed. Thanks.

    defect 
    opened by sikuan 9
  • Openslide can't find my dylib files

    Openslide can't find my dylib files

    Context

    Issue type (bug report or feature request): Operating system Mac OS 10.12 Platform 64-bit x86 OpenSlide Python version (openslide.__version__): OpenSlide version (openslide.__library_version__): Slide format (e.g. SVS, NDPI, MRXS):

    Details

    I am working on installing openslide on my Mac OS but can't get it to work. I am facing this error:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File ".../lib/python2.7/site-packages/openslide/__init__.py", line 29, in <module>
        from openslide import lowlevel
      File ".../lib/python2.7/site-packages/openslide/lowlevel.py", line 55, in <module>
        "Is OpenSlide installed?")
    ImportError: Couldn't locate OpenSlide dylib.  Is OpenSlide installed?
    

    openslide is already installed and I can view it under lib/python2.7/site-packages

    Please advise.

    Thanks

    invalid 
    opened by aaljuhani 9
  • MRXS file  seem error with read_region function

    MRXS file seem error with read_region function

    MRXS file seem error with read_region function

    Operating system (Ubuntu 18.04): Slide format (MRXS):

    Details

    Code: path= './CMU-1-Saved-1_16.mrxs' slide = OpenSlide(path) slide.read_region((0,0),level,slide.level_dimensions[level])

    only level==0 can correct display image, otherwise image with read_region will like this:

    (slide.read_region((0,0),3,slide.level_dimensions[3]))

    and the MRXS flie come from (https://openslide.org/formats/mirax/)

    Is any wrong with my code?

    opened by AndrewTal 8
  • error in importing openlide

    error in importing openlide

    I have tried to install in opensLide in collab so I got the below error.....can anyone help me with this....


    OSError Traceback (most recent call last) in () ----> 1 import openslide

    3 frames /usr/lib/python3.6/ctypes/init.py in init(self, name, mode, handle, use_errno, use_last_error) 346 347 if handle is None: --> 348 self._handle = _dlopen(self._name, mode) 349 else: 350 self._handle = handle

    OSError: libopenslide.so.0: cannot open shared object file: No such file or directory

    invalid 
    opened by saisriteja 8
  • FileNotFoundError: Could not find module 'libopenslide-0.dll'.

    FileNotFoundError: Could not find module 'libopenslide-0.dll'.

    Context

    Issue type (bug report or feature request): bug Operating system (e.g. Fedora 24, Mac OS 10.11, Windows 10): Windows 10 Platform (e.g. 64-bit x86, 32-bit ARM): 64 bit OpenSlide Python version (openslide.__version__): 1.1.2 OpenSlide version (openslide.__library_version__): openslide-win64-20171122

    Details

    The problem happens only with python 3.8 while running a test suite that import openslide. Openslide bin directory is in the PATH env variable but:

        import openslide
    c:\python38\lib\site-packages\openslide\__init__.py:35: in <module>
        from openslide import lowlevel
    c:\python38\lib\site-packages\openslide\lowlevel.py:43: in <module>
        _lib = cdll.LoadLibrary('libopenslide-0.dll')
    c:\python38\lib\ctypes\__init__.py:447: in LoadLibrary
        return self._dlltype(name)
    c:\python38\lib\ctypes\__init__.py:369: in __init__
        self._handle = _dlopen(self._name, mode)
    E   FileNotFoundError: Could not find module 'libopenslide-0.dll'. Try using the full path with constructor syntax.
    

    I saw other related issues (https://github.com/openslide/openslide-python/issues/23) that have been fixed replacing line 41 on lowlevel.py with

    _lib = cdll.LoadLibrary(ctypes.util.find_library("libopenslide-0.dll"))
    

    Any idea?

    opened by ernestoarbitrio 7
  • Urgent: Facing issues with the Level-Dimensions in Leica .scn Images

    Urgent: Facing issues with the Level-Dimensions in Leica .scn Images

    hello @bgilbert , @jaharkes

    Context

    Issue type (bug report or feature request): Bug Operating system ( Windows ): Windows 8.1 and also Tried on Linux Server Machine (ppc64le) Platform (64-bit): OpenSlide Python version - 1.1.1: OpenSlide version - 3.4.1 Slide format - .scn (Leica SCN Images)

    Details

    I am facing issues regarding the Whole Slide Image for Leica .scn images. Whenever I use the slide.level_dimensions and slide.properties functions from the openslide python package to get information about the dimensions and the overall information about the slide properties, it gives incorrect information about the level dimensions. The information doesn't seem to match the information from the image.

    My code details to reproduce to issue are:

    import openslide slide = openslide.OpenSlide('./nims-002.scn') print("Level count: %d" % slide.level_count) print("Level dimensions: " + str(slide.level_dimensions)) print("Properties: " + str(slide.properties)) print("Dimensions: " + str(slide.dimensions))

    I am hereby attaching the details of 2 Whole Slide Image and their information from the slide.level_dimension and slide.properties function and those extracted from actual Whole Slide Images. The width and height at each and every level dont seem to match to the original scn image at all. As a result I get tiles with huge y-coordinates and few tiles that are completely black. For two different Whole Slide Images, slide.level_dimensions and slide.properties function gives same level values and same dimensions. How is it possible when both of them have different values of the levels and different dimensions all together?

    Request you to kindly inspect the issue and let me know about it, as I am unable to proceed with my research.

    a2 nims-002.txt

    a4 nims-004.txt

    Regards, Hitesha

    opened by hitesha14 7
  • Use find_library to load libopenslide-0.dll for Windows

    Use find_library to load libopenslide-0.dll for Windows

    Currently user has to copy libopenslide-0.dll into system folder. If user has downloaded the openslide zip and added the openslide/bin to PATH, it fails to load libopenslide-0.dll. Hence better to use find_library to find and load the dll file for windows as well.

    opened by SachidanandAlle 6
  • Build for Python 3.11

    Build for Python 3.11

    Adding wheels for a new Python release

    • Update Git main
      • [x] git checkout main
      • [x] Add classifier for new Python version to setup.py
      • [x] Add new Python version to lists in .github/workflows/python.yml
      • [x] Commit and open a PR
      • [x] Merge the PR when CI passes
      • [x] Add new Python jobs to branch protection required checks
    • Build new wheels
      • [x] Check out a new branch from the most recent release tag
      • [x] Add new Python version to lists in .github/workflows/python.yml, commit, and open a DNM PR
      • [x] Find the workflow run for the PR; download its wheels artifact
      • [x] Close the PR
    • [x] In OpenSlide Python checkout, git checkout v<version> && git clean -dxf && mkdir dist
    • [x] Copy downloaded wheels from new Python release only into dist directory
    • [x] twine upload dist/*
    • [x] Upload new wheels to GitHub release
    • [ ] Update MacPorts package
    • [ ] Update website: Python 3 versions in download/index.md
    release 
    opened by bgilbert 1
  • workflows: build wheels for all OS; python 3.11 support

    workflows: build wheels for all OS; python 3.11 support

    Changes:

    • Modified CI to build wheels for all relevant operating systems, as discussed in https://github.com/openslide/openslide-python/issues/187 and https://github.com/openslide/openslide-python/issues/126.
    • Support for Python 3.11 was also added, both setup.py and CI were modified to account for this.
    • Changed to consistently write "X" instead of X for python versions in CI.

    Note:

    • Wheels for Python 3.12 works fine for UNIX-based systems, but as Pillow don't yet support Python 3.12 on Windows (see CI build here), I only set support for Python versions 3.7-3.11.
    • In addition, it is likely more optimal to run tests on a separate virtual machine than where the binaries where built, to properly test that they work as intended, but I believe this is outside the scope of this PR.

    What also should be added before merge:

    • [ ] Manulinux build
    opened by andreped 3
  • Precompiled wheels for all operating systems

    Precompiled wheels for all operating systems

    Context

    Issue type (bug report or feature request): There are various situations where building the package might fail. For instance on Windows, if VS Build Tools are not available. I see that this has been handled by building precompiled wheels for Windows specifically (see here). However, depending on the end-user's settings, it may happen that the user is unable to build themselves, even on Ubuntu, during installation.

    I therefore, believe it would be more optimal if we build wheels for all relevant operating systems and python versions, which should remove this issue.

    That is quite easy to do as we only need to modify the workflow to do that: https://github.com/openslide/openslide-python/blob/main/.github/workflows/python.yml

    Details

    This was recently a problem when trying to install MONAI Label on a client machine which did not have install python dev tools which resulted in python setup.py install failing for openslide-python. This will no longer be a problem if precompiled wheels are provided. I believe the MONAI Label team would be very interested in this (@diazandr3s).

    If this is of interest, shall I make a PR to add support for various relevant operating systems and specific python versions?

    opened by andreped 7
  • Different pixel value when opening same slide on Linux and Windows

    Different pixel value when opening same slide on Linux and Windows

    Context

    Issue type (bug report or feature request): Different pixel value when opening same slide on Linux and Windows Operating system (e.g. Fedora 24, Mac OS 10.11, Windows 10): Ubuntu 20.04.4 LTS, Windows 10 Platform (e.g. 64-bit x86, 32-bit ARM): OpenSlide Python version (openslide.__version__): 1.2.0 (on both OS) OpenSlide version (openslide.__library_version__): 3.4.1 (on both OS) Slide format (e.g. SVS, NDPI, MRXS): NDPI

    Details

    Dear all,

    When trying to read a slide from Warwick HER2 dataset in a single array at level 5, I get different values depending I am using openslide on Windows or Linux. Both versions of openslide python are the same as the openslide library version. The offset value is relatively small since it seems to differ by only one unit (cf tables on the left of the screenshots I joined). However, this difference is enough to impact my processing afterward. You can also notice on the screenshots I joined that, for instance, you get something significantly different when summing the value of pixels.

    Thank you for your help,

    Linux capture: capture_openslide_issue_linux

    Windows capture: capture_openslide_issue_windows

    opened by loic-lb 2
  • Consider switching from setuptools to Poetry

    Consider switching from setuptools to Poetry

    It's cleaner, apparently popular, and appears to support everything we need.

    WIP in https://github.com/openslide/openslide-python/pull/164, though we should break that out into a separate PR.

    enhancement 
    opened by bgilbert 1
Releases(v1.2.0)
Convert excel xlsx file's table to csv file, A GUI application on top of python/pyqt and other opensource softwares.

Convert excel xlsx file's table to csv file, A GUI application on top of python/pyqt and other opensource softwares.

David A 0 Jan 20, 2022
A Python library for setting up projects using tabular data.

A Python library for setting up projects using tabular data. It can create project folders, standardize delimiters, and convert files to CSV from either individual files or a directory.

0 Dec 13, 2022
This repo contains everything you'll ever need to learn/revise python basics

Python Notes/cheat sheet Simplified notes to get your Python basics right Just compare code and output side by side and feel the rush of enlightenment

Hem 5 Oct 06, 2022
The sarge package provides a wrapper for subprocess which provides command pipeline functionality.

Overview The sarge package provides a wrapper for subprocess which provides command pipeline functionality. This package leverages subprocess to provi

Vinay Sajip 14 Dec 18, 2022
Comprehensive Python Cheatsheet

Comprehensive Python Cheatsheet Download text file, Buy PDF, Fork me on GitHub or Check out FAQ. Contents 1. Collections: List, Dictionary, Set, Tuple

Jefferson 1 Jan 23, 2022
Python script to generate Vale linting rules from word usage guidance in the Red Hat Supplementary Style Guide

ssg-vale-rules-gen Python script to generate Vale linting rules from word usage guidance in the Red Hat Supplementary Style Guide. These rules are use

Vale at Red Hat 1 Jan 13, 2022
A Python Package To Generate Strong Passwords For You in Your Projects.

shPassGenerator Version 1.0.6 Ready To Use Developed by Shervin Badanara (shervinbdndev) on Github Language and technologies used in This Project Work

Shervin 11 Dec 19, 2022
✨ Real-life Data Analysis and Model Training Workshop by Global AI Hub.

🎓 Data Analysis and Model Training Course by Global AI Hub Syllabus: Day 1 What is Data? Multimedia Structured and Unstructured Data Data Types Data

Global AI Hub 71 Oct 28, 2022
The mitosheet package, trymito.io, and other public Mito code.

Mito Monorepo Mito is a spreadsheet that lives inside your JupyterLab notebooks. It allows you to edit Pandas dataframes like an Excel file, and gener

Mito 1.4k Dec 31, 2022
In this Github repository I will share my freqtrade files with you. I want to help people with this repository who don't know Freqtrade so much yet.

My Freqtrade stuff In this Github repository I will share my freqtrade files with you. I want to help people with this repository who don't know Freqt

Simon Kebekus 104 Dec 31, 2022
More detailed upload statistics for Nicotine+

More Upload Statistics A small plugin for Nicotine+ 3.1+ to create more detailed upload statistics. ⚠ No data previous to enabling this plugin will be

Nick 1 Dec 17, 2021
SCTYMN is a GitHub repository that includes some simple scripts(currently only python scripts) that can be useful.

Simple Codes That You Might Need SCTYMN is a GitHub repository that includes some simple scripts(currently only python scripts) that can be useful. In

CodeWriter21 2 Jan 21, 2022
NetBox plugin that stores configuration diffs and checks templates compliance

Config Officer - NetBox plugin NetBox plugin that deals with Cisco device configuration (collects running config from Cisco devices, indicates config

77 Dec 21, 2022
Create docsets for Dash.app-compatible API browser.

doc2dash: Create Docsets for Dash.app and Clones doc2dash is an MIT-licensed extensible Documentation Set generator intended to be used with the Dash.

Hynek Schlawack 498 Dec 30, 2022
Jupyter Notebooks as Markdown Documents, Julia, Python or R scripts

Have you always wished Jupyter notebooks were plain text documents? Wished you could edit them in your favorite IDE? And get clear and meaningful diff

Marc Wouts 5.7k Jan 04, 2023
DataAnalysis: Some data analysis projects in charles_pikachu

DataAnalysis DataAnalysis: Some data analysis projects in charles_pikachu You can star this repository to keep track of the project if it's helpful fo

9 Nov 04, 2022
Repository for tutorials, examples and starter scripts for using the MTU HPC cluster

MTU-HPC-Starter Repository for tutorials, examples and starter scripts for using the MTU HPC cluster Connecting to the MTU HPC cluster Within the coll

1 Jan 31, 2022
Documentation for the lottie file format

Lottie Documentation This repository contains both human-readable and machine-readable documentation about the Lottie format The documentation is avai

LottieFiles 25 Jan 05, 2023
Yu-Gi-Oh! Master Duel translation script

Yu-Gi-Oh! Master Duel translation script

715 Jan 08, 2023
Automated generation of real Swagger/OpenAPI 2.0 schemas from Django REST Framework code.

drf-yasg - Yet another Swagger generator Generate real Swagger/OpenAPI 2.0 specifications from a Django Rest Framework API. Compatible with Django Res

Cristi Vîjdea 3k Dec 31, 2022