ratiopath.openslide.OpenSlide
Bases: OpenSlide
A wrapper around the OpenSlide library to provide additional functionality.
Source code in ratiopath/openslide.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
closest_level(mpp)
Finds the closest slide level to match the desired MPP.
This method compares the desired MPP (µm/px) with the MPP of the available levels in the slide and selects the level with the closest match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mpp
|
float | tuple[float, float]
|
The desired µm/px value. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The index of the level with the closest µm/px resolution to the desired value. |
Source code in ratiopath/openslide.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
read_region_relative(location, level, size)
Reads a region from the slide with coordinates relative to the specified level.
This method adjusts the coordinates based on the level's downsampling factor before reading the region from the slide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
tuple[int, int]
|
The (x, y) coordinates at the specified level. |
required |
level
|
int
|
The level of the slide to read from. |
required |
size
|
tuple[int, int]
|
The (width, height) of the region to read. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
The image of the requested region. |
Source code in ratiopath/openslide.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
read_tile(x, y, extent_x, extent_y, level, background=255)
Reads a tile from the slide at the specified coordinates and level.
This method reads a tile from the slide based on the provided x and y coordinates, tile extent, and level. It also composites the tile onto a white background to remove any alpha channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int | Scalar
|
The x-coordinate of the tile. |
required |
y
|
int | Scalar
|
The y-coordinate of the tile. |
required |
extent_x
|
int | Scalar
|
The width of the tile in pixels. |
required |
extent_y
|
int | Scalar
|
The height of the tile in pixels. |
required |
level
|
int | Scalar
|
The level of the slide to read from. |
required |
background
|
tuple[int, int, int] | int
|
The RGB value (0-255) to use for transparent areas. Defaults to 255 (white). |
255
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The RGB image of the requested tile. |
Source code in ratiopath/openslide.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
slide_resolution(level)
Returns the resolution of the slide in µm/px at the given level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
The level of the slide to calculate the resolution. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
The [x, y] resolution of the slide in µm/px. |
Source code in ratiopath/openslide.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |