biopb.image¶
biopb.image ¶
Ops ¶
Bases: object
A server of named ops over tensors and JSON.
There is no call deadline: a client times out on silence between events, and stops a call by cancelling it. A failure inside a call is the RPC's status: INVALID_ARGUMENT for arguments the op refuses, INTERNAL otherwise.
OpsServicer ¶
Bases: object
A server of named ops over tensors and JSON.
There is no call deadline: a client times out on silence between events, and stops a call by cancelling it. A failure inside a call is the RPC's status: INVALID_ARGUMENT for arguments the op refuses, INTERNAL otherwise.
OpsStub ¶
Bases: object
A server of named ops over tensors and JSON.
There is no call deadline: a client times out on silence between events, and stops a call by cancelling it. A failure inside a call is the RPC's status: INVALID_ARGUMENT for arguments the op refuses, INTERNAL otherwise.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel
|
A grpc.Channel. |
required |
Source code in src/main/python/biopb/image/rpc_ops_pb2_grpc.py
deserialize_image_data ¶
deserialize_image_data(
image_data: ImageData, *, cache_bytes: int = 1000000000
) -> Union[np.ndarray, da.Array]
Convert protobuf ImageData to a numpy array or dask array.
Handles both eager (inline) and lazy (Flight server) data representations. Also handles legacy pixels field for backward compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_data
|
ImageData
|
protobuf ImageData message |
required |
Keyword Args: cache_bytes: Cache size for lazy_data chunk cache (default 1GB).
Returns:
| Type | Description |
|---|---|
Union[ndarray, Array]
|
numpy array for eager_data, or dask array for lazy_data. |
Source code in src/main/python/biopb/image/_utils.py
get_image_data_dim_labels ¶
get_image_data_dim_labels(
image_data: ImageData, *, implicit: bool = False
) -> Optional[Sequence[str]]
Get a copy of the dimension labels from ImageData.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_data
|
ImageData
|
ImageData protobuf message |
required |
implicit
|
bool
|
If True and dim_labels field is unset, return heuristic labels based on shape. Heuristics: - 2D -> ['y', 'x'] - 3D and dim[0] <= 4 -> ['c', 'y', 'x'] - 3D and dim[-1] <= 4 -> ['y', 'x', 'c'] - All other cases -> None |
False
|
Returns:
| Type | Description |
|---|---|
Optional[Sequence[str]]
|
List of dimension labels, or None if unset and implicit=False or |
Optional[Sequence[str]]
|
heuristics don't apply. |
Source code in src/main/python/biopb/image/_utils.py
mask_to_roi ¶
Convert a binary mask to a ROI protobuf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
ndarray
|
Binary mask as numpy array (2D or 3D). |
required |
bitorder
|
str
|
Bit order for packing ('big' or 'little'). Defaults to 'big'. |
'big'
|
Returns:
| Type | Description |
|---|---|
ROI
|
ROI protobuf message containing the mask data. |
Source code in src/main/python/biopb/image/_utils.py
normalize_array_dims ¶
normalize_array_dims(
arr: Union[ndarray, Array],
dim_labels: Sequence[str],
target_dim_labels: Sequence[str],
) -> Union[np.ndarray, da.Array]
Normalize array dimensions to match target dimension labels.
Transposes, squeezes, and adds singleton dimensions to convert an array with given dimension labels to match the target dimension order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Union[ndarray, Array]
|
Input array (numpy or dask) |
required |
dim_labels
|
Sequence[str]
|
Current dimension labels for each axis of arr. If None, raises ValueError. |
required |
target_dim_labels
|
Sequence[str]
|
Target dimension labels for the output array. |
required |
Returns:
| Type | Description |
|---|---|
Union[ndarray, Array]
|
Array with dimensions reordered to match target_dim_labels. |
Union[ndarray, Array]
|
The output will have len(target_dim_labels) dimensions. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If dim_labels is None, if dim_labels length doesn't match array ndim, if dim_labels or target_dim_labels has duplicates, or if a dimension exists in dim_labels but not target_dim_labels with size > 1 (cannot squeeze non-singleton dimension). |
Source code in src/main/python/biopb/image/_utils.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | |
roi_to_mask ¶
Convert a ROI protobuf to a binary mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roi
|
ROI
|
ROI protobuf message containing shape (point, rectangle, polygon, or mask). |
required |
mask
|
ndarray
|
Template numpy array defining output shape and dtype. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Binary mask as numpy array with same shape/dtype as input mask. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If mask dimension is not 2 or 3. |
NotImplementedError
|
For unsupported ROI types or 3D polygons. |
Source code in src/main/python/biopb/image/_utils.py
serialize_from_numpy_to_image_data ¶
serialize_from_numpy_to_image_data(
np_img: ndarray,
*,
dim_labels: Optional[Sequence[str]] = None
) -> ImageData
Convert numpy array to protobuf ImageData with eager_data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
np_img
|
ndarray
|
image as numpy array (any memory order is accepted) |
required |
Keyword Args: dim_labels: Dimension labels for the tensor. Must be same length as np_img.ndim. Returns: protobuf ImageData with eager_data set.