qubalab.qupath package
qubalab.qupath.qupath_gateway module
- qubalab.qupath.qupath_gateway.add_objects(features: list[Feature] | Feature, image_data: JavaObject | None = None, gateway: JavaGateway | None = None)
Add the provided features to the current or provided ImageData.
- Parameters:
features – the features to add. Can be a list or a single Feature
image_data – the image_data to add features to. Can be None to use the current ImageData opened in QuPath
gateway – the gateway to use. Can be None to use the default gateway
- qubalab.qupath.qupath_gateway.count_objects(image_data: JavaObject | None = None, gateway: JavaGateway | None = None, object_type: ObjectType | None = None) int
Get a count of all objects in the current or specified image.
Since requesting the objects can be slow, this can be used to check if a reasonable number of objects is available.
- Parameters:
image_data – the image_data to retrieve objects from. Can be None to use the current ImageData opened in QuPath
gateway – the gateway to use. Can be None to use the default gateway
object_type – the type of object to get. Can be None to get all objects except the root
- Returns:
the number of such objects in the current or specified image
- qubalab.qupath.qupath_gateway.create_gateway(auto_convert=True, auth_token=None, port=25333, set_as_default=True, **kwargs) JavaGateway
Create a new JavaGateway to communicate with QuPath.
This requires launching QuPath and activating Py4J from there first.
- Parameters:
auto_convert – if True, the gateway will try to automatically convert Python objects like sequences and maps to Java Objects
auth_token – the authentication token to use to connect. Can be None if no authentication is used
port – the port to use to connect
set_as_default – whether to set the created gateway as the default gateway
kwargs – additional arguments to give to the JavaGateway constructor
- Returns:
the created gateway
- Raises:
RuntimeError – if the connection to QuPath couldn’t be established
- qubalab.qupath.qupath_gateway.create_snapshot(gateway: JavaGateway | None = None, snapshot_type: str = 'qupath') ndarray
Create and return a snapshot of QuPath.
- Parameters:
gateway – the gateway to use. Can be None to use the default gateway
snapshot_type – what to include in the snapshot. ‘qupath’ for the entire qupath window or ‘viewer’ for only the viewer
- Returns:
a numpy array with dimensions (y, x, c) representing an RGB image
- Raises:
ValueError – if the snapshot type was not recognized
- qubalab.qupath.qupath_gateway.delete_objects(image_data: JavaObject | None = None, gateway: JavaGateway | None = None, object_type: ObjectType | None = None)
Delete all specified objects (e.g. annotations, detections) from the current or provided ImageData.
- Parameters:
image_data – the image_data to remove the objects from. Can be None to use the current ImageData opened in QuPath
gateway – the gateway to use. Can be None to use the default gateway
object_type – the type of object to remove. Can be None to remove all objects
- qubalab.qupath.qupath_gateway.get_current_image_data(gateway: JavaGateway | None = None) JavaObject
Get the current ImageData opened in QuPath through the provided gateway.
- Parameters:
gateway – the gateway to use. Can be None to use the default gateway
- Returns:
the current ImageData opened in QuPath
- qubalab.qupath.qupath_gateway.get_default_gateway() JavaGateway
Return the default gateway. It will be created if it doesn’t already exist.
- Returns:
the default gateway
- qubalab.qupath.qupath_gateway.get_objects(image_data: JavaObject | None = None, gateway: JavaGateway | None = None, object_type: ObjectType | None = None, converter: str | None = None) list[Feature] | list[ImageFeature] | list[JavaObject]
Get the objects (e.g. detections, annotations) of the current or specified image in QuPath.
- Parameters:
image_data – the image_data to retrieve objects from. Can be None to use the current ImageData opened in QuPath
gateway – the gateway to use. Can be None to use the default gateway
object_type – the type of object to get. Can be None to get all objects except the root
converter – can be ‘geojson’ to get an extended GeoJSON feature represented as a QuBaLab ‘ImageObject’, or ‘simple_feature’ to get a regular GeoJSON ‘Feature’. By default, the Py4J representation of the QuPath Java object is returned.
- Returns:
the list of objects of the specified image. The type of the objects depends on the converted parameter
- qubalab.qupath.qupath_gateway.get_project(gateway: JavaGateway | None = None) JavaObject
Return the currently opened QuPath project.
- Parameters:
gateway – the gateway to use. Can be None to use the default gateway
- Returns:
a Java Object representing the currently opened QuPath project
- qubalab.qupath.qupath_gateway.refresh_qupath(gateway: JavaGateway | None = None)
Update the current QuPath interface.
This is sometimes needed to update the QuPath window when some changes are made to hierarchy.
- Parameters:
gateway – the gateway to use. Can be None to use the default gateway
- qubalab.qupath.qupath_gateway.set_default_gateway(gateway: JavaGateway)
Set the default JavaGateway to use if one is not otherwise specified.
This default gateway will be used if no gateway is provided in some functions of this file.
- Parameters:
gateway – the gateway that should be the default gateway