Skip to content

Commit

Permalink
Merge branch 'main' of github.com:qupath/qubalab
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Oct 28, 2024
2 parents 593c9ec + b182784 commit c874a73
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 45 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
name: test

on:
push:
branches:
main
pull_request:
workflow_dispatch:

Expand All @@ -16,9 +19,12 @@ jobs:
- name: Set up python
id: setup-python
uses: actions/setup-python@v5

- name: Install Openslide
run: sudo apt install openslide-tools

- name: Install
run: pip install .[test]
run: pip install .[test,openslide]

- name: Run tests
run: pytest
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ You can find the documentation on https://qupath.github.io/qubalab-docs/.
This project contains the QuBaLab package in the `qubalab` folder.
Take a look at the *Installation* section to install it.

Some notebooks present in the `notebooks` folder show how to use the QuBaLab
package. If you want to run them, you can take a look at the *Development* section.
If you just want to go through them, look at the
Some notebooks in the `notebooks` folder demonstrate how to use QuBaLab.
If you want to run them, you can take a look at the *Development* section.
If you just want to browse the content in them, look at the
[documentation](https://qupath.github.io/qubalab/notebooks.html).

## Installation
Expand Down
2 changes: 2 additions & 0 deletions qubalab/images/openslide_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class OpenSlideServer(ImageServer):
"""
An image server that relies on OpenSlide (https://openslide.org/) to read RGB images.
This server may only be able to detect the full resolution of a pyramidal image.
OpenSlide provides some properties to define a rectangle bounding the non-empty region of the slide
(see https://openslide.org/api/python/#standard-properties). If such properties are found, only this
rectangle will be read (but note that this behaviour was not properly tested).
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ packages =
python_requires = >= 3.10
install_requires =
tiffslide ~= 2.4.0
aicsimageio ~= 4.13.0
dask[array] >= 2021.4.1
aicsimageio >= 4.10.0
dask-image >= 0.6.0
py4j ~= 0.10.9.7
geojson ~= 3.1.0
Expand Down
41 changes: 4 additions & 37 deletions tests/images/test_openslide_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,12 @@ def test_image_shapes():

shapes = openslide_server.metadata.shapes

assert shapes == multi_resolution_uint8_3channels.get_shapes()
# only the full resolution can be detected
assert shapes[0] == multi_resolution_uint8_3channels.get_shapes()[0]

openslide_server.close()


def test_image_pixel_calibration():
openslide_server = OpenSlideServer(multi_resolution_uint8_3channels.get_path())

pixel_calibration = openslide_server.metadata.pixel_calibration

assert pixel_calibration == PixelCalibration(
PixelLength.create_microns(multi_resolution_uint8_3channels.get_pixel_size_x_y_in_micrometers()),
PixelLength.create_microns(multi_resolution_uint8_3channels.get_pixel_size_x_y_in_micrometers())
)

openslide_server.close()


def test_is_rgb():
openslide_server = OpenSlideServer(multi_resolution_uint8_3channels.get_path())
Expand Down Expand Up @@ -93,7 +82,8 @@ def test_downsamples():

downsamples = openslide_server.metadata.downsamples

assert downsamples == multi_resolution_uint8_3channels.get_downsamples()
# only the full resolution can be detected
assert downsamples[0] == multi_resolution_uint8_3channels.get_downsamples()[0]

openslide_server.close()

Expand All @@ -119,26 +109,3 @@ def test_read_full_resolution_image():
np.testing.assert_array_equal(image, expected_pixels)

openslide_server.close()


def test_read_lower_resolution_image():
level = len(multi_resolution_uint8_3channels.get_shapes()) - 1
lowest_resolution = multi_resolution_uint8_3channels.get_shapes()[level]
downsample = multi_resolution_uint8_3channels.get_downsamples()[level]
openslide_server = OpenSlideServer(multi_resolution_uint8_3channels.get_path())
expected_pixels = np.array(
[[[multi_resolution_uint8_3channels.get_pixel_value(downsample, x, y, c)
for x in range(lowest_resolution.x)]
for y in range(lowest_resolution.y)]
for c in range(lowest_resolution.c)],
multi_resolution_uint8_3channels.get_dtype()
)

image = openslide_server.read_region(
downsample,
Region2D(width=openslide_server.metadata.width, height=openslide_server.metadata.height)
)

np.testing.assert_array_equal(image, expected_pixels)

openslide_server.close()
8 changes: 6 additions & 2 deletions tests/res/multi_resolution_uint8_3channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def _write_image(pixels: np.array):
metadata=metadata,
subifds=number_of_subresolutions,
resolution=(number_of_pixels_per_cm, number_of_pixels_per_cm),
resolutionunit=3 # indicate that the resolution above is in cm^-1
resolutionunit=3, # indicate that the resolution above is in cm^-1,
photometric='rgb',
tile=(128, 128)
)

# Write sub resolutions
Expand All @@ -89,7 +91,9 @@ def _write_image(pixels: np.array):
metadata=metadata,
subfiletype=1, # indicate that the image is part of a multi-page image
resolution=(number_of_pixels_per_cm / downsample, number_of_pixels_per_cm / downsample),
resolutionunit=3
resolutionunit=3,
photometric='rgb',
tile=(128, 128)
)


Expand Down

0 comments on commit c874a73

Please sign in to comment.