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)
Repository for learning Python (Python Tutorial)

Repository for learning Python (Python Tutorial) Languages and Tools ?? Overview ?? Repository for learning Python (Python Tutorial) Languages and Too

Swiftman 2 Aug 22, 2022
A python package to avoid writing and maintaining duplicated python docstrings.

docstring-inheritance is a python package to avoid writing and maintaining duplicated python docstrings.

Antoine Dechaume 15 Dec 7, 2022
advance python series: Data Classes, OOPs, python

Working With Pydantic - Built-in Data Process ========================== Normal way to process data (reading json file): the normal princiople, it's f

Phung Hưng Binh 1 Nov 8, 2021
A comprehensive and FREE Online Python Development tutorial going step-by-step into the world of Python.

FREE Reverse Engineering Self-Study Course HERE Fundamental Python The book and code repo for the FREE Fundamental Python book by Kevin Thomas. FREE B

Kevin Thomas 7 Mar 19, 2022
A simple USI Shogi Engine written in python using python-shogi.

Revengeshogi My attempt at creating a USI Shogi Engine in python using python-shogi. Current State of Engine Currently only generating random moves us

null 1 Jan 6, 2022
Python-slp - Side Ledger Protocol With Python

Side Ledger Protocol Run python-slp node First install Mongo DB and run the mong

Solar 3 Mar 2, 2022
Python-samples - This project is to help someone need some practices when learning python language

Python-samples - This project is to help someone need some practices when learning python language

Gui Chen 0 Feb 14, 2022
Valentine-with-Python - A Python program generates an animation of a heart with cool texts of your loved one

Valentine with Python Valentines with Python is a mini fun project I have coded.

Niraj Tiwari 4 Dec 31, 2022
A curated list of awesome tools for Sphinx Python Documentation Generator

Awesome Sphinx (Python Documentation Generator) A curated list of awesome extra libraries, software and resources for Sphinx (Python Documentation Gen

Hyunjun Kim 831 Dec 27, 2022
API Documentation for Python Projects

API Documentation for Python Projects. Example pdoc -o ./html pdoc generates this website: pdoc.dev/docs. Installation pip install pdoc pdoc is compat

mitmproxy 1.4k Jan 7, 2023
🏆 A ranked list of awesome python developer tools and libraries. Updated weekly.

Best-of Python Developer Tools ?? A ranked list of awesome python developer tools and libraries. Updated weekly. This curated list contains 250 awesom

Machine Learning Tooling 646 Jan 7, 2023
Run `black` on python code blocks in documentation files

blacken-docs Run black on python code blocks in documentation files. install pip install blacken-docs usage blacken-docs provides a single executable

Anthony Sottile 460 Dec 23, 2022
Legacy python processor for AsciiDoc

AsciiDoc.py This branch is tracking the alpha, in-progress 10.x release. For the stable 9.x code, please go to the 9.x branch! AsciiDoc is a text docu

AsciiDoc.py 178 Dec 25, 2022
📖 Generate markdown API documentation from Google-style Python docstring. The lazy alternative to Sphinx.

lazydocs Generate markdown API documentation for Google-style Python docstring. Getting Started • Features • Documentation • Support • Contribution •

Machine Learning Tooling 118 Dec 31, 2022
A Python module for creating Excel XLSX files.

XlsxWriter XlsxWriter is a Python module for writing files in the Excel 2007+ XLSX file format. XlsxWriter can be used to write text, numbers, formula

John McNamara 3.1k Dec 29, 2022
API spec validator and OpenAPI document generator for Python web frameworks.

API spec validator and OpenAPI document generator for Python web frameworks.

1001001 249 Dec 22, 2022
Materi workshop "Light up your Python!" Himpunan Mahasiswa Sistem Informasi Fakultas Ilmu Komputer Universitas Singaperbangsa Karawang, 4 September 2021 (Online via Zoom).

Workshop Python UNSIKA 2021 Materi workshop "Light up your Python!" Himpunan Mahasiswa Sistem Informasi Fakultas Ilmu Komputer Universitas Singaperban

Eka Putra 20 Mar 24, 2022
Exercism exercises in Python.

Exercism exercises in Python.

Exercism 1.3k Jan 4, 2023
This is a repository for "100 days of code challenge" projects. You can reach all projects from beginner to professional which are written in Python.

100 Days of Code It's a challenge that aims to gain code practice and enhance programming knowledge. Day #1 Create a Band Name Generator It's actually

SelenNB 2 May 12, 2022