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)
This is the data scrapped of all the pitches made up potential startup's to established bussiness tycoons of India with all the details of Investments made, equity share, Name of investor etc.

SharkTankInvestor This is the data scrapped of all the pitches made up potential startup's to established bussiness tycoons of India with all the deta

Subradip Poddar 2 Aug 02, 2022
Course Materials for Math 340

UBC Math 340 Materials This repository aims to be the one repository for which you can find everything you about Math 340. Lecture Notes Lecture Notes

2 Nov 25, 2021
204-python-string-21BCA90 created by GitHub Classroom

204-Python This repository is created for subject "204 Programming Skill" Python Programming. This Repository contain list of programs of python progr

VIDYABHARTI TRUST COLLEGE OF BCA 6 Mar 31, 2022
Make posters from Markdown files.

MkPosters Create posters using Markdown. Supports icons, admonitions, and LaTeX mathematics. At the moment it is restricted to the specific layout of

Patrick Kidger 243 Dec 20, 2022
A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..

apispec A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification). Features Supports th

marshmallow-code 1k Jan 01, 2023
FxBuzzly - Buzzly.art links do not embed in Discord, this fixes them (rudimentarily)

fxBuzzly Buzzly.art links do not embed in Discord, this fixes them (rudimentaril

Dania Rifki 2 Oct 27, 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
Pydantic model generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.

datamodel-code-generator This code generator creates pydantic model from an openapi file and others. Help See documentation for more details. Supporte

Koudai Aono 1.3k Dec 29, 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
Uses diff command to compare expected output with student's submission output

AUTOGRADER for GRADESCOPE using diff with partial grading Description: Uses diff command to compare expected output with student's submission output U

2 Jan 11, 2022
pytorch_example

pytorch_examples machine learning site map 정리자료 Resnet https://wolfy.tistory.com/243 convolution 연산 정리 https://gaussian37.github.io/dl-concept-covolut

injae hwang 1 Nov 24, 2021
Ultimaker Cura 2 Mooraker Upload Plugin

Klipper & Cura - Cura2MoonrakerPlugin Allows you to upload Gcode directly from Cura to your Klipper-based 3D printer (Fluidd, Mainsailos etc.) using t

214 Jan 03, 2023
Course materials for: Geospatial Data Science

Course materials for: Geospatial Data Science These course materials cover the lectures for the course held for the first time in spring 2022 at IT Un

Michael Szell 266 Jan 02, 2023
Exercism exercises in Python.

Exercism exercises in Python.

Exercism 1.3k Jan 04, 2023
NoVmpy - NoVmpy with python

git clone -b dev-1 https://github.com/wallds/VTIL-Python.git cd VTIL-Python py s

263 Dec 23, 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
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
🍭 epub generator for lightnovel.us 轻之国度 epub 生成器

lightnovel_epub 本工具用于基于轻之国度网页生成epub小说。 注意:本工具仅作学习交流使用,作者不对内容和使用情况付任何责任! 原理 直接抓取 HTML,然后将其中的图片下载至本地,随后打包成 EPUB。

gyro永不抽风 188 Dec 30, 2022
Python Eacc is a minimalist but flexible Lexer/Parser tool in Python.

Python Eacc is a parsing tool it implements a flexible lexer and a straightforward approach to analyze documents.

Iury de oliveira gomes figueiredo 60 Nov 16, 2022
An MkDocs plugin to export content pages as PDF files

MkDocs PDF Export Plugin An MkDocs plugin to export content pages as PDF files The pdf-export plugin will export all markdown pages in your MkDocs rep

Terry Zhao 266 Dec 13, 2022