Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F106821800
slide.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Apr 1, 03:43
Size
3 KB
Mime Type
text/x-python
Expires
Thu, Apr 3, 03:43 (2 d)
Engine
blob
Format
Raw Data
Handle
25282618
Attached To
rDESUTOPLATFORM Desuto Platform
slide.py
View Options
import
openslide
from
openslide
import
OpenSlide
,
OpenSlideError
import
os
import
json
class
Slide
:
def
__init__
(
self
,
imagepath
):
self
.
osr
=
OpenSlide
(
imagepath
);
# Microns per pixel y
def
mpp_y
(
self
):
return
self
.
osr
.
properties
.
get
(
openslide
.
PROPERTY_NAME_MPP_X
)
# Microns per pixel x
def
mpp_x
(
self
):
return
self
.
osr
.
properties
.
get
(
openslide
.
PROPERTY_NAME_MPP_Y
)
# Pixels mer milimeter
def
px_mm
(
self
):
return
1
/
(((
float
(
self
.
mpp_x
())
+
float
(
self
.
mpp_y
()))
/
2
)
/
1000
)
# Pixels mer milimeter
def
px_m
(
self
):
return
self
.
px_mm
()
*
1000
;
# Vendor
def
vendor
(
self
):
return
self
.
osr
.
properties
.
get
(
openslide
.
PROPERTY_NAME_VENDOR
)
# X coordinate of the rectangle bounding the non-empty region of the slide, if available
def
bounds_x
(
self
):
return
self
.
osr
.
properties
.
get
(
openslide
.
PROPERTY_NAME_BOUNDS_X
)
# X coordinate of the rectangle bounding the non-empty region of the slide, if available
def
bounds_y
(
self
):
return
self
.
osr
.
properties
.
get
(
openslide
.
PROPERTY_NAME_BOUNDS_Y
)
# width of the rectangle bounding the non-empty region of the slide, if available.
def
bounds_width
(
self
):
return
self
.
osr
.
properties
.
get
(
openslide
.
PROPERTY_NAME_BOUNDS_WIDTH
)
# Height of the rectangle bounding the non-empty region of the slide, if available.
def
bounds_height
(
self
):
return
self
.
osr
.
properties
.
get
(
openslide
.
PROPERTY_NAME_BOUNDS_HEIGHT
)
# x, y and rectangle width & height bounding the non-empty region of the slide, if available. JSON
def
bounds
(
self
):
info
=
{}
info
[
'x'
]
=
self
.
bounds_x
()
info
[
'y'
]
=
self
.
bounds_y
()
info
[
'width'
]
=
self
.
bounds_width
()
info
[
'height'
]
=
self
.
bounds_height
()
return
json
.
dumps
(
info
)
# Number of magnification levels
def
nbr_levels
(
self
):
return
self
.
osr
.
level_count
# A list of downsample factors for each level of the slide. level_downsamples[k] is the downsample factor of level k.
def
level_downsamples
(
self
):
return
self
.
osr
.
level_downsamples
# A list of (width, height) tuples, one for each level of the slide. level_dimensions[k] are the dimensions of level k.
def
level_dimensions
(
self
):
return
self
.
osr
.
level_dimensions
# Best level for displaying the given downsample.
def
best_level_for_downsample
(
self
,
downsample
):
return
self
.
osr
.
get_best_level_for_downsample
(
float
(
downsample
))
# Magnification level
def
magnification
(
self
):
return
self
.
osr
.
properties
.
get
(
openslide
.
PROPERTY_NAME_OBJECTIVE_POWER
)
def
common_info
(
self
):
info
=
{}
info
[
'pmm'
]
=
self
.
px_mm
()
info
[
'pm'
]
=
self
.
px_m
()
info
[
'nbrlevels'
]
=
self
.
nbr_levels
()
info
[
'leveldownsamples'
]
=
self
.
level_downsamples
()
info
[
'leveldimensions'
]
=
self
.
level_dimensions
()
info
[
'bounds'
]
=
{}
info
[
'bounds'
][
'x'
]
=
self
.
bounds_x
()
info
[
'bounds'
][
'y'
]
=
self
.
bounds_y
()
info
[
'bounds'
][
'width'
]
=
self
.
bounds_width
()
info
[
'bounds'
][
'height'
]
=
self
.
bounds_height
()
return
json
.
dumps
(
info
);
Event Timeline
Log In to Comment