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)
Documentation and issues for Pylance - Fast, feature-rich language support for Python

Documentation and issues for Pylance - Fast, feature-rich language support for Python

Microsoft 1.5k Dec 29, 2022
A python package to import files from an adjacent folder

EasyImports About EasyImports is a python package that allows users to easily access and import files from sister folders: f.ex: - Project - Folde

1 Jun 22, 2022
Parser manager for parsing DOC, DOCX, PDF or HTML files

Parser manager Description Parser gets PDF, DOC, DOCX or HTML file via API and saves parsed data to the database. Implemented in Ruby 3.0.1 using Acti

Эдем 4 Dec 04, 2021
Official Matplotlib cheat sheets

Official Matplotlib cheat sheets

Matplotlib Developers 6.7k Jan 09, 2023
Gaphor is the simple modeling tool

Gaphor Gaphor is a UML and SysML modeling application written in Python. It is designed to be easy to use, while still being powerful. Gaphor implemen

Gaphor 1.3k Jan 03, 2023
This program has been coded to allow the user to rename all the files in the entered folder.

Bulk_File_Renamer This program has been coded to allow the user to rename all the files in the entered folder. The only required package is "termcolor

1 Jan 06, 2022
🐱‍🏍 A curated list of awesome things related to Hugo themes.

awesome-hugo-themes Automated deployment @ 2021-10-12 06:24:07 Asia/Shanghai &sorted=updated Theme Author License GitHub Stars Updated Blonde wamo MIT

13 Dec 12, 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
A curated list of python programming language blogs

Python Blogs A curated list of python programming language blogs Contribute Companies/Organization # A B C D E F G H I J K L M N O P Q R S T U V W X Y

Rizky D. Onto 48 Nov 15, 2022
An ongoing curated list of OS X best applications, libraries, frameworks and tools to help developers set up their macOS Laptop.

macOS Development Setup Welcome to MacOS Local Development & Setup. An ongoing curated list of OS X best applications, libraries, frameworks and tools

Paul Veillard 3 Apr 03, 2022
Python Deep Dive Course - Accompanying Materials

Python Deep Dive Various Jupyter notebooks and Python sources associated with my Udemy Python 3 Deep Dive course series: Part 1: Mainly functional pro

Fred Baptiste 1.1k Dec 30, 2022
Elliptic curve cryptography (ed25519) beginner tutorials in Python 3

ed25519_tutorials Elliptic curve cryptography (ed25519) beginner tutorials in Python 3 Instructions Just download the repo and read the tutorial files

6 Dec 27, 2022
Generate modern Python clients from OpenAPI

openapi-python-client Generate modern Python clients from OpenAPI 3.x documents. This generator does not support OpenAPI 2.x FKA Swagger. If you need

555 Jan 02, 2023
Hasköy is an open-source variable sans-serif typeface family

Hasköy Hasköy is an open-source variable sans-serif typeface family. Designed with powerful opentype features and each weight includes latin-extended

67 Jan 04, 2023
xeuledoc - Fetch information about a public Google document.

xeuledoc - Fetch information about a public Google document.

Malfrats Industries 651 Dec 27, 2022
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
OpenTelemetry Python API and SDK

Getting Started • API Documentation • Getting In Touch (GitHub Discussions) Contributing • Examples OpenTelemetry Python This page describes the Pytho

OpenTelemetry - CNCF 1.1k Jan 08, 2023
Mkdocs obsidian publish - Publish your obsidian vault through a python script

Mkdocs Obsidian Mkdocs Obsidian is an association between a python script and a

Mara 49 Jan 09, 2023
step by step guide for beginners for getting started with open source

Step-by-Step Guide for beginners for getting started with Open-Source Here The Contribution Begins 💻 If you are a beginner then this repository is fo

Arpit Jain 66 Jan 03, 2023
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