Skip to content

Commit

Permalink
Bioio
Browse files Browse the repository at this point in the history
  • Loading branch information
alanocallaghan committed Oct 17, 2024
1 parent fad10bf commit 2c8b1a6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
28 changes: 14 additions & 14 deletions notebooks/opening_images.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"source": [
"# Opening images\n",
"\n",
"This notebook will show how to access metadata and pixel values of images with QuBaLab.\n",
"This notebook will show you how to access metadata and pixel values of images with QuBaLab.\n",
"\n",
"A few classes and functions of the QuBaLab package will be presented throughout this notebook. To have more details on them, you can go to the documentation on https://qupath.github.io/qubalab/ and type a class/function name in the search bar. You will then see details on parameters functions take.\n",
"A few classes and functions of the QuBaLab package will be presented in this notebook. To view more details on them, you can go to the documentation at https://qupath.github.io/qubalab-docs/ and type a class/function name in the search bar. You will then see details on the arguments that functions accept.\n",
"\n",
"QuBaLab uses the `ImageServer` class to open an image and get its metadata and pixel values. `ImageServer` is an abstract class, so it cannot be directly used. Instead, you have to choose an implementation based on the type of image you want to open:\n",
"QuBaLab uses the `ImageServer` class to open an image and get its metadata and pixel values. `ImageServer` is an abstract class, so it cannot be directly created. Instead, you have to choose an implementation based on the type of image you want to open:\n",
"\n",
"* If you need to open an RGB pyramidal image, you can use the `OpenSlideServer`. This class internally uses [OpenSlide](https://openslide.org/): it can read all resolutions of a large pyramidal image but is only suitable for RGB images.\n",
"* If you need to open any kind of microscopy image, you can use the `AICSImageIoServer`. This class internally uses [AICSImageIO](https://github.com/AllenCellModeling/aicsimageio) which is suited for a lot of formats. However, this library does not properly support pyramids, so you might only get the full resolution image when opening a pyramidal image.\n",
"* If your image has an embedded ICC profile, or if you want to apply a custom ICC Profile to an image, you can use the `IccProfileServer`. This takes another `ImageServer` as a parameter and change pixels values. You can find more information about ICC profiles on [this link](http://www.andrewjanowczyk.com/application-of-icc-profiles-to-digital-pathology-images/).\n",
"* If you want to represent objects such as annotations or detections on an image, you can use the `LabeledImageServer`. Pixel values are labels corresponding to image features (such as annotations) present on an image. See the *working_with_objects.ipynb* notebook for more information.\n",
"* If you want to access an image opened in QuPath, you can use the `QuPathServer`. See the *communicating_with_qupath.ipynb* notebook for more information.\n",
"* If you need to open an RGB pyramidal image, you can use an `OpenSlideServer`. This class internally uses [OpenSlide](https://openslide.org/): it can read all resolutions of a large pyramidal image but is only suitable for RGB images.\n",
"* If you need to open any kind of microscopy image, you can use an `AICSImageIoServer`. This class internally uses [AICSImageIO](https://github.com/AllenCellModeling/aicsimageio) which is suited for a lot of formats. However, this library does not properly support pyramids, so you might only get the full resolution image when opening a pyramidal image.\n",
"* If your image has an embedded ICC profile, or if you want to apply a custom ICC Profile to an image, you can use an `IccProfileServer`. This takes another `ImageServer` as a parameter and changes pixels values based on the transforms defined in the ICC profile. You can find more information about ICC profiles on [this link](http://www.andrewjanowczyk.com/application-of-icc-profiles-to-digital-pathology-images/).\n",
"* If you want to represent objects such as annotations or detections on an image, you can use a `LabeledImageServer`. Pixel values are labels corresponding to image features (such as annotations) present on an image. See the *working_with_objects.ipynb* notebook for more information.\n",
"* If you want to access an image opened in QuPath, you can use a `QuPathServer`. See the *communicating_with_qupath.ipynb* notebook for more information.\n",
"\n",
"All these `ImageServer` are used in the same way, only their creation differ. This notebook will show how to create and use these servers."
]
Expand All @@ -27,11 +27,11 @@
"id": "7fb5756f-d27e-4720-bbcd-f430b7562351",
"metadata": {},
"source": [
"## ImageServers creation\n",
"## ImageServer creation\n",
"\n",
"To create an `ImageServer`, you have to use one of the implementations presented above.\n",
"\n",
"This notebook will download several sample images of large size. You can change the line below to define a folder where images will be stored once downloaded (or leave it blank not to use any cache)."
"This notebook will download several large sample images. You can change the line below to define a folder where images will be stored once downloaded (or leave it blank not to use any cache)."
]
},
{
Expand Down Expand Up @@ -190,7 +190,7 @@
"source": [
"### QuPathServer\n",
"\n",
"A `QuPathServer` allows to read an image opened in QuPath\n",
"A `QuPathServer` allows you to read an image opened in QuPath\n",
"\n",
"We will not detail the creation of this server here. Take a look at the *communicating_with_qupath.ipynb* notebook for more information. However, all functions presented below are also valid for a `QuPathServer`."
]
Expand All @@ -200,9 +200,9 @@
"id": "1e0a79f3-9467-4a52-ad80-82e74721c9cc",
"metadata": {},
"source": [
"## ImageServers usage\n",
"## ImageServer usage\n",
"\n",
"To access metadata and pixel values of an `ImageServer`, you can use the functions presented below.\n",
"To access metadata and pixel values from an `ImageServer`, you can use the functions presented below.\n",
"\n",
"These functions are available for any implementation of `ImageServer`. We will use the `OpenSlideServer` created above but they are also valid for any other `ImageServer`."
]
Expand All @@ -224,7 +224,7 @@
"source": [
"### Image metadata\n",
"\n",
"Image metadata is access with the `ImageServer.metadata` property."
"Image metadata is accessed with the `ImageServer.metadata` property."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/working_with_objects.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"source": [
"# Working with objects\n",
"\n",
"This notebook will show how to exchange objects (e.g. annotations, detections) between QuPath and Python.\n",
"This notebook will show you how to exchange objects (e.g. annotations, detections) between QuPath and Python.\n",
"\n",
"As we will communicate with QuPath, it is recommended to go through the *communicating_with_qupath.ipynb* notebook first. Also, as we will work with images, it is recommended to go through the *opening_images.ipynb* notebook first.\n",
"\n",
Expand Down
15 changes: 8 additions & 7 deletions qubalab/images/aicsimageio_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import dask.array as da
import math
from pathlib import Path
from aicsimageio import AICSImage
# from aicsimageio import AICSImage
from bioio import BioImage
from dataclasses import astuple
from .image_server import ImageServer
from .metadata.image_metadata import ImageMetadata
Expand Down Expand Up @@ -35,7 +36,7 @@ def __init__(self, path: str, scene: int = 0, detect_resolutions=True, aics_kwar
"""
super().__init__(**kwargs)
self._path = path
self._reader = AICSImage(path, dask_tiles=True, **aics_kwargs)
self._reader = BioImage(path, dask_tiles=True, **aics_kwargs)
self._scene = scene
self._detect_resolutions = detect_resolutions

Expand Down Expand Up @@ -73,7 +74,7 @@ def _read_block(self, level: int, region: Region2D) -> np.ndarray:
return self._reader.get_image_dask_data(axes)[t, z, :, y:y + height, x:x + width].compute()

@staticmethod
def _get_shapes(reader: AICSImage, scene: int) -> tuple[ImageShape, ...]:
def _get_shapes(reader: BioImage, scene: int) -> tuple[ImageShape, ...]:
shapes = []
for scene in reader.scenes[scene:]:
shape = AICSImageIoServer._get_scene_shape(reader, scene)
Expand All @@ -85,7 +86,7 @@ def _get_shapes(reader: AICSImage, scene: int) -> tuple[ImageShape, ...]:
return tuple(shapes)

@staticmethod
def _get_scene_shape(reader: AICSImage, scene: int) -> ImageShape:
def _get_scene_shape(reader: BioImage, scene: int) -> ImageShape:
reader.set_scene(scene)

return ImageShape(
Expand All @@ -97,12 +98,12 @@ def _get_scene_shape(reader: AICSImage, scene: int) -> ImageShape:
)

@staticmethod
def _get_pixel_calibration(reader: AICSImage, scene: int) -> PixelCalibration:
def _get_pixel_calibration(reader: BioImage, scene: int) -> PixelCalibration:
reader.set_scene(scene)
sizes = reader.physical_pixel_sizes

if sizes.X or sizes.Y or sizes.Z:
# The AICSImage library does not currently handle unit attachment, so the pixel unit is returned
# The bioio library does not currently handle unit attachment, so the pixel unit is returned
return PixelCalibration(
PixelLength(sizes.X) if sizes.X is not None else PixelLength(),
PixelLength(sizes.Y) if sizes.Y is not None else PixelLength(),
Expand All @@ -112,7 +113,7 @@ def _get_pixel_calibration(reader: AICSImage, scene: int) -> PixelCalibration:
return PixelCalibration()

@staticmethod
def _is_rgb(reader: AICSImage, scene: int) -> bool:
def _is_rgb(reader: BioImage, scene: int) -> bool:
reader.set_scene(scene)
return ('S' in reader.dims.order and reader.dims.S in [3, 4]) or (reader.dtype == np.uint8 and reader.dims.C == 3)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ packages =
python_requires = >= 3.10
install_requires =
tiffslide ~= 2.1.2
aicsimageio ~= 4.11.0
bioio ~= 1.0.0
dask-image ~= 2024.5.3
py4j ~= 0.10.9.7
geojson ~= 3.1.0
Expand Down

0 comments on commit 2c8b1a6

Please sign in to comment.