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)
Rust Markdown Parsing Benchmarks

Rust Markdown Parsing Benchmarks This repo tries to assess Rust markdown parsing

Ed Page 1 Aug 24, 2022
Python Advanced --- numpy, decorators, networking

Python Advanced --- numpy, decorators, networking (and more?) Hello everyone 👋 This is the project repo for the "Python Advanced - ..." introductory

Andreas Poehlmann 2 Nov 05, 2021
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
Project created to help beginner programmers to study, despite the lack of internet!

Project created to help beginner programmers to study, despite the lack of internet!

Dev4Dev 2 Oct 25, 2021
script to calculate total GPA out of 4, based on input gpa.csv

gpa_calculator script to calculate total GPA out of 4 based on input gpa.csv to use, create a total.csv file containing only one integer showing the t

Mohamad Bastin 1 Feb 07, 2022
Toolchain for project structure and documents optimisation

ritocco Toolchain for project structure and documents optimisation

Harvey Wu 1 Jan 12, 2022
Some of the best ways and practices of doing code in Python!

Pythonicness ❤ This repository contains some of the best ways and practices of doing code in Python! Features Properly formatted codes (PEP 8) for bet

Samyak Jain 2 Jan 15, 2022
A markdown wiki and dashboarding system for Datasette

datasette-notebook A markdown wiki and dashboarding system for Datasette This is an experimental alpha and everything about it is likely to change. In

Simon Willison 19 Apr 20, 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

1 Jan 06, 2022
Python bindings to OpenSlide

OpenSlide Python OpenSlide Python is a Python interface to the OpenSlide library. OpenSlide is a C library that provides a simple interface for readin

OpenSlide 297 Dec 21, 2022
An awesome Data Science repository to learn and apply for real world problems.

AWESOME DATA SCIENCE An open source Data Science repository to learn and apply towards solving real world problems. This is a shortcut path to start s

Academic.io 20.3k Jan 09, 2023
A collection of lecture notes, drawings, flash cards, mind maps, scripts

Neuroanatomy A collection of lecture notes, drawings, flash cards, mind maps, scripts and other helpful resources for the course "Functional Organizat

Georg Reich 3 Sep 21, 2022
Testing-crud-login-drf - Creation of an application in django on music albums

testing-crud-login-drf Creation of an application in django on music albums Befo

Juan 1 Jan 11, 2022
PowerApps-docstring is a console based, pipeline ready application that automatically generates user and technical documentation for Power Apps.

powerapps-docstring PowerApps-docstring is a console based, pipeline ready application that automatically generates user and technical documentation f

Sebastian Muthwill 30 Nov 23, 2022
A web app builds using streamlit API with python backend to analyze and pick insides from multiple data formats.

Data-Analysis-Web-App Data Analysis Web App can analysis data in multiple formates(csv, txt, xls, xlsx, ods, odt) and gives shows you the analysis in

Kumar Saksham 19 Dec 09, 2022
A `:github:` role for Sphinx

sphinx-github-role A github role for Sphinx. Usage Basic usage MyST: :caption: index.md See {github}`astrojuanlu/sphinx-github-role#1`. reStructuredT

Juan Luis Cano Rodríguez 4 Nov 22, 2022
The source code that powers readthedocs.org

Welcome to Read the Docs Purpose Read the Docs hosts documentation for the open source community. It supports Sphinx docs written with reStructuredTex

Read the Docs 7.4k Dec 25, 2022
A clean customizable documentation theme for Sphinx

A clean customizable documentation theme for Sphinx

Pradyun Gedam 1.5k Jan 06, 2023
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

Introduction Swagger UI allows anyone — be it your development team or your end consumers — to visualize and interact with the API’s resources without

Swagger 23.2k Dec 29, 2022
Test utility for validating OpenAPI documentation

DRF OpenAPI Tester This is a test utility to validate DRF Test Responses against OpenAPI 2 and 3 schema. It has built-in support for: OpenAPI 2/3 yaml

snok 106 Jan 05, 2023