Skip to content

Commit

Permalink
Remove openslide-python
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn committed Jan 23, 2025
1 parent a4c14a8 commit 99e7b0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
43 changes: 11 additions & 32 deletions panimg/image_builders/tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
from panimg.image_builders.dicom import get_dicom_headers_by_study
from panimg.models import MAXIMUM_SEGMENTS_LENGTH, ColorSpace, TIFFImage

try:
import openslide
except (OSError, ModuleNotFoundError):
openslide = False

try:
import pyvips
except OSError:
Expand Down Expand Up @@ -140,35 +135,25 @@ def _get_voxel_spacing_mm(tags, tag):
def _extract_openslide_properties(
*, gc_file: GrandChallengeTiffFile, image
) -> GrandChallengeTiffFile:
if not gc_file.voxel_width_mm and "openslide.mpp-x" in image.properties:
gc_file.voxel_width_mm = (
float(image.properties["openslide.mpp-x"]) / 1000
)
if not gc_file.voxel_height_mm and "openslide.mpp-y" in image.properties:
gc_file.voxel_height_mm = (
float(image.properties["openslide.mpp-y"]) / 1000
)
if not gc_file.voxel_width_mm and "openslide.mpp-x" in image.get_fields():
gc_file.voxel_width_mm = float(image.get("openslide.mpp-x")) / 1000
if not gc_file.voxel_height_mm and "openslide.mpp-y" in image.get_fields():
gc_file.voxel_height_mm = float(image.get("openslide.mpp-y")) / 1000
if (
not gc_file.image_height
and "openslide.level[0].height" in image.properties
and "openslide.level[0].height" in image.get_fields()
):
gc_file.image_height = int(
image.properties["openslide.level[0].height"]
)

gc_file.image_height = int(image.get("openslide.level[0].height"))
if (
not gc_file.image_width
and "openslide.level[0].width" in image.properties
and "openslide.level[0].width" in image.get_fields()
):
gc_file.image_width = int(image.properties["openslide.level[0].width"])

gc_file.image_width = int(image.get("openslide.level[0].width"))
if (
not gc_file.resolution_levels
and "openslide.level-count" in image.properties
and "openslide.level-count" in image.get_fields()
):
gc_file.resolution_levels = int(
image.properties["openslide.level-count"]
)
gc_file.resolution_levels = int(image.get("openslide.level-count"))
return gc_file


Expand Down Expand Up @@ -263,7 +248,7 @@ def _load_with_tiff(
def _load_with_openslide(
*, gc_file: GrandChallengeTiffFile
) -> GrandChallengeTiffFile:
open_slide_file = openslide.open_slide(str(gc_file.path.absolute()))
open_slide_file = pyvips.Image.openslideload(str(gc_file.path.absolute()))
gc_file = _extract_openslide_properties(
gc_file=gc_file, image=open_slide_file
)
Expand Down Expand Up @@ -525,12 +510,6 @@ def _load_gc_files(
def image_builder_tiff( # noqa: C901
*, files: set[Path]
) -> Iterator[TIFFImage]:
if openslide is False:
raise ImportError(
f"Could not import openslide, which is required for the "
f"{__name__} image builder. Either ensure that libopenslide-dev "
f"is installed or remove {__name__} from your list of builders."
)

if pyvips is False:
raise ImportError(
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ numpy = ">=1.22"
SimpleITK = ">=2.0,!=2.1.1.1"
pydicom = ">=2.2"
Pillow = "*"
openslide-python = "*"
pyvips = "*"
tifffile = "*"
construct = "*"
Expand Down

0 comments on commit 99e7b0c

Please sign in to comment.