@@ -93,111 +93,123 @@ OpenSlide objects
93
93
94
94
.. module :: openslide
95
95
96
- .. class :: OpenSlide(filename)
96
+ .. class :: OpenSlide(filename: str | bytes | ~os.PathLike[typing.Any] )
97
97
98
98
An open whole-slide image.
99
99
100
100
If any operation on the object fails, :exc: `OpenSlideError ` is raised.
101
101
OpenSlide has latching error semantics: once :exc: `OpenSlideError ` is
102
102
raised, all future operations on the :class: `OpenSlide `, other than
103
- :meth: `close() `, will also raise :exc: `OpenSlideError `.
103
+ :meth: `close `, will also raise :exc: `OpenSlideError `.
104
104
105
- :meth: `close() ` is called automatically when the object is deleted.
105
+ :meth: `close ` is called automatically when the object is deleted.
106
106
The object may be used as a context manager, in which case it will be
107
107
closed upon exiting the context.
108
108
109
- :param str filename: the file to open
109
+ :param filename: the file to open
110
110
:raises OpenSlideUnsupportedFormatError: if the file is not recognized by
111
111
OpenSlide
112
112
:raises OpenSlideError: if the file is recognized but an error occurred
113
113
114
- .. classmethod :: detect_format(filename)
114
+ .. classmethod :: detect_format(filename: str | bytes | ~os.PathLike[typing.Any]) -> str | None
115
115
116
116
Return a string describing the format vendor of the specified file.
117
117
This string is also accessible via the :data: `PROPERTY_NAME_VENDOR `
118
118
property.
119
119
120
120
If the file is not recognized, return :obj: `None `.
121
121
122
- :param str filename: the file to examine
122
+ :param filename: the file to examine
123
123
124
124
.. attribute :: level_count
125
125
126
126
The number of levels in the slide. Levels are numbered from ``0 ``
127
127
(highest resolution) to ``level_count - 1 `` (lowest resolution).
128
128
129
+ :type: int
130
+
129
131
.. attribute :: dimensions
130
132
131
133
A ``(width, height) `` tuple for level 0 of the slide.
132
134
135
+ :type: tuple[int, int]
136
+
133
137
.. attribute :: level_dimensions
134
138
135
- A list of ``(width, height) `` tuples, one for each level of the slide.
139
+ A tuple of ``(width, height) `` tuples, one for each level of the slide.
136
140
``level_dimensions[k] `` are the dimensions of level ``k ``.
137
141
142
+ :type: tuple[tuple[int, int], ...]
143
+
138
144
.. attribute :: level_downsamples
139
145
140
- A list of downsample factors for each level of the slide.
146
+ A tuple of downsample factors for each level of the slide.
141
147
``level_downsamples[k] `` is the downsample factor of level ``k ``.
142
148
149
+ :type: tuple[float, ...]
150
+
143
151
.. attribute :: properties
144
152
145
153
Metadata about the slide, in the form of a
146
154
:class: `~collections.abc.Mapping ` from OpenSlide property name to
147
- property value. Property values are always strings. OpenSlide
148
- provides some :ref: `standard-properties `, plus
149
- additional properties that vary by slide format.
155
+ property value. OpenSlide provides some :ref: `standard-properties `,
156
+ plus additional properties that vary by slide format.
157
+
158
+ :type: ~collections.abc.Mapping[str, str]
150
159
151
160
.. attribute :: associated_images
152
161
153
162
Images, such as label or macro images, which are associated with this
154
163
slide. This is a :class: `~collections.abc.Mapping ` from image
155
- name to RGBA :class: `Image < PIL.Image.Image> `.
164
+ name to RGBA :class: `~ PIL.Image.Image `.
156
165
157
166
Unlike in the C interface, these images are not premultiplied.
158
167
168
+ :type: ~collections.abc.Mapping[str, ~PIL.Image.Image]
169
+
159
170
.. attribute :: color_profile
160
171
161
172
The embedded :ref: `color profile <color-management >` for this slide,
162
- as a Pillow :class: `~PIL.ImageCms.ImageCmsProfile `, or :obj: `None ` if
163
- not available.
173
+ or :obj: `None ` if not available.
174
+
175
+ :type: ~PIL.ImageCms.ImageCmsProfile | None
164
176
165
- .. method :: read_region(location, level, size)
177
+ .. method :: read_region(location: tuple[int, int], level: int , size: tuple[int, int]) -> ~PIL.Image.Image
166
178
167
- Return an RGBA :class: `Image < PIL.Image.Image> ` containing the
168
- contents of the specified region.
179
+ Return an RGBA :class: `~ PIL.Image.Image ` containing the contents of
180
+ the specified region.
169
181
170
182
Unlike in the C interface, the image data is not premultiplied.
171
183
172
- :param tuple location: ``(x, y) `` tuple giving the top left pixel in
173
- the level 0 reference frame
174
- :param int level: the level number
175
- :param tuple size: ``(width, height) `` tuple giving the region size
184
+ :param location: ``(x, y) `` tuple giving the top left pixel in the
185
+ level 0 reference frame
186
+ :param level: the level number
187
+ :param size: ``(width, height) `` tuple giving the region size
176
188
177
- .. method :: get_best_level_for_downsample(downsample)
189
+ .. method :: get_best_level_for_downsample(downsample: float) -> int
178
190
179
191
Return the best level for displaying the given downsample.
180
192
181
- :param float downsample: the desired downsample factor
193
+ :param downsample: the desired downsample factor
182
194
183
- .. method :: get_thumbnail(size)
195
+ .. method :: get_thumbnail(size: tuple[int, int]) -> ~PIL.Image.Image
184
196
185
- Return an :class: `Image < PIL.Image.Image> ` containing an RGB thumbnail
186
- of the slide.
197
+ Return an :class: `~ PIL.Image.Image ` containing an RGB thumbnail of the
198
+ slide.
187
199
188
- :param tuple size: the maximum size of the thumbnail as a
189
- `` (width, height) `` tuple
200
+ :param size: the maximum size of the thumbnail as a `` (width, height) ``
201
+ tuple
190
202
191
- .. method :: set_cache(cache)
203
+ .. method :: set_cache(cache: OpenSlideCache) -> None
192
204
193
205
Use the specified :class: `OpenSlideCache ` to store recently decoded
194
206
slide tiles. By default, the :class: `OpenSlide ` has a private cache
195
207
with a default size.
196
208
197
- :param OpenSlideCache cache: a cache object
209
+ :param cache: a cache object
198
210
:raises OpenSlideVersionError: if OpenSlide is older than version 4.0.0
199
211
200
- .. method :: close()
212
+ .. method :: close() -> None
201
213
202
214
Close the OpenSlide object.
203
215
@@ -254,15 +266,15 @@ reusing it for multiple slide regions::
254
266
Caching
255
267
-------
256
268
257
- .. class :: OpenSlideCache(capacity)
269
+ .. class :: OpenSlideCache(capacity: int )
258
270
259
271
An in-memory tile cache.
260
272
261
273
Tile caches can be attached to one or more :class: `OpenSlide ` objects
262
274
with :meth: `OpenSlide.set_cache ` to cache recently-decoded tiles. By
263
275
default, each :class: `OpenSlide ` has its own cache with a default size.
264
276
265
- :param int capacity: the cache capacity in bytes
277
+ :param capacity: the cache capacity in bytes
266
278
:raises OpenSlideVersionError: if OpenSlide is older than version 4.0.0
267
279
268
280
@@ -335,7 +347,7 @@ Exceptions
335
347
336
348
Once :exc: `OpenSlideError ` has been raised by a particular
337
349
:class: `OpenSlide `, all future operations on that :class: `OpenSlide `
338
- (other than :meth: `close() < OpenSlide.close> `) will also raise
350
+ (other than :meth: `~ OpenSlide.close `) will also raise
339
351
:exc: `OpenSlideError `.
340
352
341
353
.. exception :: OpenSlideUnsupportedFormatError
@@ -354,20 +366,24 @@ Exceptions
354
366
Wrapping a Pillow Image
355
367
=======================
356
368
357
- .. class :: ImageSlide(file)
369
+ .. class :: AbstractSlide
358
370
359
- A wrapper around an :class: `Image <PIL.Image.Image> ` object that
360
- provides an :class: `OpenSlide `-compatible API.
371
+ The abstract base class of :class: `OpenSlide ` and :class: `ImageSlide `.
361
372
362
- :param file: a filename or :class: `Image <PIL.Image.Image> ` object
373
+ .. class :: ImageSlide(file: str | bytes | ~os.PathLike[typing.Any] | ~PIL.Image.Image)
374
+
375
+ A wrapper around an :class: `~PIL.Image.Image ` object that provides an
376
+ :class: `OpenSlide `-compatible API.
377
+
378
+ :param file: a filename or :class: `~PIL.Image.Image ` object
363
379
:raises OSError: if the file cannot be opened
364
380
365
- .. function :: open_slide(filename)
381
+ .. function :: open_slide(filename: str | bytes | ~os.PathLike[typing.Any]) -> OpenSlide | ImageSlide
366
382
367
383
Return an :class: `OpenSlide ` for whole-slide images and an
368
384
:class: `ImageSlide ` for other types of images.
369
385
370
- :param str filename: the file to open
386
+ :param filename: the file to open
371
387
:raises OpenSlideError: if the file is recognized by OpenSlide but an
372
388
error occurred
373
389
:raises OSError: if the file is not recognized at all
@@ -385,72 +401,79 @@ Deep Zoom or a similar format.
385
401
386
402
.. _`Deep Zoom` : https://docs.microsoft.com/en-us/previous-versions/windows/silverlight/dotnet-windows-silverlight/cc645050(v=vs.95)
387
403
388
- .. class :: DeepZoomGenerator(osr, tile_size= 254, overlap= 1, limit_bounds= False)
404
+ .. class :: DeepZoomGenerator(osr: AbstractSlide , tile_size: int = 254, overlap: int = 1, limit_bounds: bool = False)
389
405
390
- A Deep Zoom generator that wraps an
391
- :class: `OpenSlide < openslide.OpenSlide> ` or
392
- :class: `ImageSlide < openslide.ImageSlide> ` object .
406
+ A Deep Zoom generator that wraps an :class: ` ~openslide.OpenSlide ` object,
407
+ :class: `~ openslide.ImageSlide ` object, or user-provided instance of
408
+ :class: `~ openslide.AbstractSlide ` .
393
409
394
410
:param osr: the slide object
395
- :param int tile_size: the width and height of a single tile. For best
396
- viewer performance, ``tile_size + 2 * overlap `` should be a power of two.
397
- :param int overlap: the number of extra pixels to add to each interior edge
398
- of a tile
399
- :param bool limit_bounds: ``True `` to render only the non-empty slide
400
- region
411
+ :param tile_size: the width and height of a single tile. For best viewer
412
+ performance, ``tile_size + 2 * overlap `` should be a power of two.
413
+ :param overlap: the number of extra pixels to add to each interior edge of a
414
+ tile
415
+ :param limit_bounds: :obj: `True ` to render only the non-empty slide region
401
416
402
417
.. attribute :: level_count
403
418
404
419
The number of Deep Zoom levels in the image.
405
420
421
+ :type: int
422
+
406
423
.. attribute :: tile_count
407
424
408
425
The total number of Deep Zoom tiles in the image.
409
426
427
+ :type: int
428
+
410
429
.. attribute :: level_tiles
411
430
412
- A list of ``(tiles_x, tiles_y) `` tuples for each Deep Zoom level.
431
+ A tuple of ``(tiles_x, tiles_y) `` tuples for each Deep Zoom level.
413
432
``level_tiles[k] `` are the tile counts of level ``k ``.
414
433
434
+ :type: tuple[tuple[int, int], ...]
435
+
415
436
.. attribute :: level_dimensions
416
437
417
- A list of ``(pixels_x, pixels_y) `` tuples for each Deep Zoom level.
438
+ A tuple of ``(pixels_x, pixels_y) `` tuples for each Deep Zoom level.
418
439
``level_dimensions[k] `` are the dimensions of level ``k ``.
419
440
420
- .. method :: get_dzi(format)
441
+ :type: tuple[tuple[int, int], ...]
442
+
443
+ .. method :: get_dzi(format: str) -> str
421
444
422
445
Return a string containing the XML metadata for the Deep Zoom ``.dzi ``
423
446
file.
424
447
425
- :param str format: the delivery format of the individual tiles
426
- (`` png `` or ``jpeg ``)
448
+ :param format: the delivery format of the individual tiles (`` png `` or
449
+ ``jpeg ``)
427
450
428
- .. method :: get_tile(level, address)
451
+ .. method :: get_tile(level: int , address: tuple[int, int]) -> ~PIL.Image.Image
429
452
430
- Return an RGB :class: `Image < PIL.Image.Image> ` for a tile.
453
+ Return an RGB :class: `~ PIL.Image.Image ` for a tile.
431
454
432
- :param int level: the Deep Zoom level
433
- :param tuple address: the address of the tile within the level as a
455
+ :param level: the Deep Zoom level
456
+ :param address: the address of the tile within the level as a
434
457
``(column, row) `` tuple
435
458
436
- .. method :: get_tile_coordinates(level, address)
459
+ .. method :: get_tile_coordinates(level: int , address: tuple[int, int]) -> tuple[tuple[int, int], int, tuple[int, int]]
437
460
438
461
Return the :meth: `OpenSlide.read_region()
439
462
<openslide.OpenSlide.read_region> ` arguments corresponding to the
440
463
specified tile.
441
464
442
- Most applications should use :meth: `get_tile() ` instead.
465
+ Most applications should use :meth: `get_tile ` instead.
443
466
444
- :param int level: the Deep Zoom level
445
- :param tuple address: the address of the tile within the level as a
467
+ :param level: the Deep Zoom level
468
+ :param address: the address of the tile within the level as a
446
469
``(column, row) `` tuple
447
470
448
- .. method :: get_tile_dimensions(level, address)
471
+ .. method :: get_tile_dimensions(level: int , address: tuple[int, int]) -> tuple[int, int]
449
472
450
473
Return a ``(pixels_x, pixels_y) `` tuple for the specified tile.
451
474
452
- :param int level: the Deep Zoom level
453
- :param tuple address: the address of the tile within the level as a
475
+ :param level: the Deep Zoom level
476
+ :param address: the address of the tile within the level as a
454
477
``(column, row) `` tuple
455
478
456
479
0 commit comments