mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Squashed commit of the following:
commit 33b660ee19fa58e84643bba0b875c874a7d3da12 Author: Leonid Kostrykin <void@evoid.de> Date: Tue Mar 5 20:58:24 2024 +0000 Fix XSD commit 4ee6112b84d3406d6ba98dd190fe07fda2d90307 Author: Leonid Kostrykin <void@evoid.de> Date: Tue Mar 5 20:53:14 2024 +0000 Add `labels` attribute for `has_image_labels` and `has_image_mean_object_size` commit 4ff401c4f0731cc3aceb9c511f7c3c61abf2b19c Author: Leonid Kostrykin <void@evoid.de> Date: Tue Mar 5 20:32:57 2024 +0000 Replace `image_has_labels` by `has_image_labels` and `has_image_mean_object_size` commit 09149d1394a1b81c8c3036316ab2be355db24cde Author: Leonid Kostrykin <void@evoid.de> Date: Tue Mar 5 19:51:56 2024 +0000 Fix bug commit 28fedb98f19a35ab6a4747aa5b435c329277df50 Author: Leonid Kostrykin <void@evoid.de> Date: Tue Mar 5 19:44:12 2024 +0000 Replace `image_has_intensities` by `has_image_mean_intensity` and `has_image_center_of_mass` commit fe96916ca28752f5c5512658db53c4162d8d7d66 Author: Leonid Kostrykin <void@evoid.de> Date: Tue Mar 5 19:10:38 2024 +0000 Replace `image_has_metadata` by `has_image_width`, etc.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import io
|
||||
from typing import (
|
||||
Any,
|
||||
List,
|
||||
Optional,
|
||||
Tuple,
|
||||
@@ -7,6 +8,8 @@ from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
from ._util import _assert_number
|
||||
|
||||
try:
|
||||
import numpy
|
||||
except ImportError:
|
||||
@@ -44,28 +47,79 @@ def _assert_float(
|
||||
assert actual <= float(range_max), f"Wrong {label}: {actual} (must be {range_max} or smaller)"
|
||||
|
||||
|
||||
def assert_image_has_metadata(
|
||||
def assert_has_image_width(
|
||||
output_bytes: bytes,
|
||||
width: Optional[Union[int, str]] = None,
|
||||
height: Optional[Union[int, str]] = None,
|
||||
channels: Optional[Union[int, str]] = None,
|
||||
value: Optional[Union[int, str]] = None,
|
||||
delta: Union[int, str] = 0,
|
||||
min: Optional[Union[int, str]] = None,
|
||||
max: Optional[Union[int, str]] = None,
|
||||
negate: Union[bool, str] = False,
|
||||
) -> None:
|
||||
"""
|
||||
Assert the image output has specific metadata.
|
||||
Asserts the specified output is an image and has a width of the specified value.
|
||||
"""
|
||||
buf = io.BytesIO(output_bytes)
|
||||
with Image.open(buf) as im:
|
||||
_assert_number(
|
||||
im.size[0],
|
||||
value,
|
||||
delta,
|
||||
min,
|
||||
max,
|
||||
negate,
|
||||
"{expected} width {n}+-{delta}",
|
||||
"{expected} width to be in [{min}:{max}]",
|
||||
)
|
||||
|
||||
assert width is None or im.size[0] == int(width), f"Image has wrong width: {im.size[0]} (expected {int(width)})"
|
||||
|
||||
assert height is None or im.size[1] == int(
|
||||
height
|
||||
), f"Image has wrong height: {im.size[1]} (expected {int(height)})"
|
||||
def assert_has_image_height(
|
||||
output_bytes: bytes,
|
||||
value: Optional[Union[int, str]] = None,
|
||||
delta: Union[int, str] = 0,
|
||||
min: Optional[Union[int, str]] = None,
|
||||
max: Optional[Union[int, str]] = None,
|
||||
negate: Union[bool, str] = False,
|
||||
) -> None:
|
||||
"""
|
||||
Asserts the specified output is an image and has a height of the specified value.
|
||||
"""
|
||||
buf = io.BytesIO(output_bytes)
|
||||
with Image.open(buf) as im:
|
||||
_assert_number(
|
||||
im.size[1],
|
||||
value,
|
||||
delta,
|
||||
min,
|
||||
max,
|
||||
negate,
|
||||
"{expected} height {n}+-{delta}",
|
||||
"{expected} height to be in [{min}:{max}]",
|
||||
)
|
||||
|
||||
actual_channels = len(im.getbands())
|
||||
assert channels is None or actual_channels == int(
|
||||
channels
|
||||
), f"Image has wrong number of channels: {actual_channels} (expected {int(channels)})"
|
||||
|
||||
def assert_has_image_channels(
|
||||
output_bytes: bytes,
|
||||
value: Optional[Union[int, str]] = None,
|
||||
delta: Union[int, str] = 0,
|
||||
min: Optional[Union[int, str]] = None,
|
||||
max: Optional[Union[int, str]] = None,
|
||||
negate: Union[bool, str] = False,
|
||||
) -> None:
|
||||
"""
|
||||
Asserts the specified output is an image and has the specified number of channels.
|
||||
"""
|
||||
buf = io.BytesIO(output_bytes)
|
||||
with Image.open(buf) as im:
|
||||
_assert_number(
|
||||
len(im.getbands()),
|
||||
value,
|
||||
delta,
|
||||
min,
|
||||
max,
|
||||
negate,
|
||||
"{expected} image channels {n}+-{delta}",
|
||||
"{expected} image channels to be in [{min}:{max}]",
|
||||
)
|
||||
|
||||
|
||||
def _compute_center_of_mass(im_arr: "numpy.typing.NDArray") -> Tuple[float, float]:
|
||||
@@ -79,17 +133,12 @@ def _compute_center_of_mass(im_arr: "numpy.typing.NDArray") -> Tuple[float, floa
|
||||
return (im_arr * xx).sum(), (im_arr * yy).sum()
|
||||
|
||||
|
||||
def assert_image_has_intensities(
|
||||
def _get_image(
|
||||
output_bytes: bytes,
|
||||
channel: Optional[Union[int, str]] = None,
|
||||
mean_intensity: Optional[Union[float, str]] = None,
|
||||
mean_intensity_min: Optional[Union[float, str]] = None,
|
||||
mean_intensity_max: Optional[Union[float, str]] = None,
|
||||
center_of_mass: Optional[Union[Tuple[float, float], str]] = None,
|
||||
eps: Union[float, str] = 0.01,
|
||||
) -> None:
|
||||
) -> "numpy.typing.NDArray":
|
||||
"""
|
||||
Assert the image output has specific intensity content.
|
||||
Returns the output image or a specific channel.
|
||||
"""
|
||||
buf = io.BytesIO(output_bytes)
|
||||
with Image.open(buf) as im:
|
||||
@@ -99,79 +148,143 @@ def assert_image_has_intensities(
|
||||
if channel is not None:
|
||||
im_arr = im_arr[:, :, int(channel)]
|
||||
|
||||
# Perform `mean_intensity` assertions.
|
||||
# Return the image
|
||||
return im_arr
|
||||
|
||||
|
||||
def assert_has_image_mean_intensity(
|
||||
output_bytes: bytes,
|
||||
channel: Optional[Union[int, str]] = None,
|
||||
value: Optional[Union[float, str]] = None,
|
||||
delta: Union[float, str] = 0.01,
|
||||
min: Optional[Union[float, str]] = None,
|
||||
max: Optional[Union[float, str]] = None,
|
||||
) -> None:
|
||||
"""
|
||||
Asserts the specified output is an image and has the specified mean intensity value.
|
||||
"""
|
||||
im_arr = _get_image(output_bytes, channel)
|
||||
_assert_float(
|
||||
actual=im_arr.mean(),
|
||||
label="mean intensity",
|
||||
tolerance=eps,
|
||||
expected=mean_intensity,
|
||||
range_min=mean_intensity_min,
|
||||
range_max=mean_intensity_max,
|
||||
tolerance=delta,
|
||||
expected=value,
|
||||
range_min=min,
|
||||
range_max=max,
|
||||
)
|
||||
|
||||
# Perform `center_of_mass` assertion.
|
||||
if center_of_mass is not None:
|
||||
if isinstance(center_of_mass, str):
|
||||
center_of_mass_parts = [c.strip() for c in center_of_mass.split(",")]
|
||||
assert len(center_of_mass_parts) == 2
|
||||
center_of_mass = (float(center_of_mass_parts[0]), float(center_of_mass_parts[1]))
|
||||
assert len(center_of_mass) == 2, "center_of_mass must have two components"
|
||||
actual_center_of_mass = _compute_center_of_mass(im_arr)
|
||||
distance = numpy.linalg.norm(numpy.subtract(center_of_mass, actual_center_of_mass))
|
||||
assert distance <= float(
|
||||
eps
|
||||
), f"Wrong center of mass: {actual_center_of_mass} (expected {center_of_mass}, distance: {distance}, eps: {eps})"
|
||||
|
||||
|
||||
def assert_image_has_labels(
|
||||
def assert_has_image_center_of_mass(
|
||||
output_bytes: bytes,
|
||||
number_of_objects: Optional[Union[int, str]] = None,
|
||||
mean_object_size: Optional[Union[float, str]] = None,
|
||||
mean_object_size_min: Optional[Union[float, str]] = None,
|
||||
mean_object_size_max: Optional[Union[float, str]] = None,
|
||||
exclude_labels: Optional[Union[str, List[int]]] = None,
|
||||
eps: Union[float, str] = 0.01,
|
||||
channel: Optional[Union[int, str]] = None,
|
||||
point: Optional[Union[Tuple[float, float], str]] = None,
|
||||
delta: Union[float, str] = 0.01,
|
||||
) -> None:
|
||||
"""
|
||||
Assert the image output has specific label content.
|
||||
Asserts the specified output is an image and has the specified center of mass.
|
||||
"""
|
||||
buf = io.BytesIO(output_bytes)
|
||||
with Image.open(buf) as im:
|
||||
im_arr = numpy.array(im)
|
||||
im_arr = _get_image(output_bytes, channel)
|
||||
if point is not None:
|
||||
if isinstance(point, str):
|
||||
point_parts = [c.strip() for c in point.split(",")]
|
||||
assert len(point_parts) == 2
|
||||
point = (float(point_parts[0]), float(point_parts[1]))
|
||||
assert len(point) == 2, "point must have two components"
|
||||
actual_center_of_mass = _compute_center_of_mass(im_arr)
|
||||
distance = numpy.linalg.norm(numpy.subtract(point, actual_center_of_mass))
|
||||
assert distance <= float(
|
||||
delta
|
||||
), f"Wrong center of mass: {actual_center_of_mass} (expected {point}, distance: {distance}, delta: {delta})"
|
||||
|
||||
|
||||
def _get_image_labels(
|
||||
output_bytes: bytes,
|
||||
channel: Optional[Union[int, str]] = None,
|
||||
labels: Optional[Union[str, List[int]]] = None,
|
||||
exclude_labels: Optional[Union[str, List[int]]] = None,
|
||||
) -> Tuple["numpy.typing.NDArray", List[Any]]:
|
||||
"""
|
||||
Determines the unique labels in the output image or a specific channel.
|
||||
"""
|
||||
assert labels is None or exclude_labels is None
|
||||
im_arr = _get_image(output_bytes, channel)
|
||||
|
||||
def cast_label(label):
|
||||
label = label.strip()
|
||||
if numpy.issubdtype(im_arr.dtype, numpy.integer):
|
||||
return int(label)
|
||||
if numpy.issubdtype(im_arr.dtype, float):
|
||||
return float(label)
|
||||
raise AssertionError(f'Unsupported image label type: "{im_arr.dtype}"')
|
||||
|
||||
# Determine labels present in the image.
|
||||
labels = numpy.unique(im_arr)
|
||||
present_labels = numpy.unique(im_arr)
|
||||
|
||||
# Apply filtering due to `labels` (keep only those).
|
||||
if labels is None:
|
||||
labels = list()
|
||||
if isinstance(labels, str):
|
||||
labels = [cast_label(label) for label in labels.split(",") if len(label) > 0]
|
||||
if len(labels) > 0:
|
||||
present_labels = [label for label in present_labels if label in labels]
|
||||
|
||||
# Apply filtering due to `exclude_labels`.
|
||||
if exclude_labels is None:
|
||||
exclude_labels = list()
|
||||
if isinstance(exclude_labels, str):
|
||||
|
||||
def cast_label(label):
|
||||
if numpy.issubdtype(im_arr.dtype, numpy.integer):
|
||||
return int(label)
|
||||
if numpy.issubdtype(im_arr.dtype, float):
|
||||
return float(label)
|
||||
raise AssertionError(f'Unsupported image label type: "{im_arr.dtype}"')
|
||||
|
||||
exclude_labels = [cast_label(label) for label in exclude_labels.split(",") if len(label) > 0]
|
||||
labels = [label for label in labels if label not in exclude_labels]
|
||||
present_labels = [label for label in present_labels if label not in exclude_labels]
|
||||
|
||||
# Perform `number_of_objects` assertion.
|
||||
if number_of_objects is not None:
|
||||
actual_number_of_objects = len(labels)
|
||||
expected_number_of_objects = int(number_of_objects)
|
||||
assert (
|
||||
actual_number_of_objects == expected_number_of_objects
|
||||
), f"Wrong number of objects: {actual_number_of_objects} (expected {expected_number_of_objects})"
|
||||
# Return the image data and the labels.
|
||||
return im_arr, present_labels
|
||||
|
||||
# Perform `mean_object_size` assertion.
|
||||
actual_mean_object_size = sum((im_arr == label).sum() for label in labels) / len(labels)
|
||||
|
||||
def assert_has_image_labels(
|
||||
output_bytes: bytes,
|
||||
channel: Optional[Union[int, str]] = None,
|
||||
exclude_labels: Optional[Union[str, List[int]]] = None,
|
||||
value: Optional[Union[int, str]] = None,
|
||||
delta: Union[int, str] = 0,
|
||||
min: Optional[Union[int, str]] = None,
|
||||
max: Optional[Union[int, str]] = None,
|
||||
negate: Union[bool, str] = False,
|
||||
) -> None:
|
||||
"""
|
||||
Asserts the specified output is an image and has the specified number of unique values (e.g., uniquely labeled objects).
|
||||
"""
|
||||
present_labels = _get_image_labels(output_bytes, channel, exclude_labels)[1]
|
||||
_assert_number(
|
||||
len(present_labels),
|
||||
value,
|
||||
delta,
|
||||
min,
|
||||
max,
|
||||
negate,
|
||||
"{expected} labels {n}+-{delta}",
|
||||
"{expected} labels to be in [{min}:{max}]",
|
||||
)
|
||||
|
||||
|
||||
def assert_has_image_mean_object_size(
|
||||
output_bytes: bytes,
|
||||
channel: Optional[Union[int, str]] = None,
|
||||
labels: Optional[Union[str, List[int]]] = None,
|
||||
exclude_labels: Optional[Union[str, List[int]]] = None,
|
||||
value: Optional[Union[float, str]] = None,
|
||||
delta: Union[float, str] = 0.01,
|
||||
min: Optional[Union[float, str]] = None,
|
||||
max: Optional[Union[float, str]] = None,
|
||||
) -> None:
|
||||
"""
|
||||
Asserts the specified output is an image with labeled objects which have the specified mean size (number of pixels).
|
||||
"""
|
||||
im_arr, present_labels = _get_image_labels(output_bytes, channel, labels, exclude_labels)
|
||||
actual_mean_object_size = sum((im_arr == label).sum() for label in present_labels) / len(present_labels)
|
||||
_assert_float(
|
||||
actual=actual_mean_object_size,
|
||||
label="mean object size",
|
||||
tolerance=eps,
|
||||
expected=mean_object_size,
|
||||
range_min=mean_object_size_min,
|
||||
range_max=mean_object_size_max,
|
||||
tolerance=delta,
|
||||
expected=value,
|
||||
range_min=min,
|
||||
range_max=max,
|
||||
)
|
||||
|
||||
@@ -2248,9 +2248,13 @@ module.
|
||||
<xs:documentation xml:lang="en"><![CDATA[Assertions for image data]]></xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:choice>
|
||||
<xs:element name="image_has_metadata" type="AssertImageHasMetadata" />
|
||||
<xs:element name="image_has_intensities" type="AssertImageHasIntensities" />
|
||||
<xs:element name="image_has_labels" type="AssertImageHasLabels" />
|
||||
<xs:element name="has_image_width" type="AssertHasImageWidth" />
|
||||
<xs:element name="has_image_height" type="AssertHasImageHeight" />
|
||||
<xs:element name="has_image_channels" type="AssertHasImageChannels" />
|
||||
<xs:element name="has_image_mean_intensity" type="AssertHasImageMeanIntensity" />
|
||||
<xs:element name="has_image_center_of_mass" type="AssertHasImageCenterOfMass" />
|
||||
<xs:element name="has_image_labels" type="AssertHasImageLabels" />
|
||||
<xs:element name="has_image_mean_object_size" type="AssertHasImageMeanObjectSize" />
|
||||
</xs:choice>
|
||||
</xs:group>
|
||||
<xs:group name="TestAssertionsH5">
|
||||
@@ -2751,120 +2755,260 @@ $attribute_list::5
|
||||
<xs:attributeGroup ref="AssertAttributePath"/>
|
||||
<xs:attributeGroup ref="AssertAttributeNegate"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="AssertImageHasMetadata">
|
||||
<xs:complexType name="AssertHasImageWidth">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en"><![CDATA[
|
||||
Asserts the image has the specified metadata.
|
||||
|
||||
```xml
|
||||
<image_has_metadata width="512" height="512" channels="3" />
|
||||
```
|
||||
Asserts the output is an image and has a specific width (in pixels) of ``value``
|
||||
plus/minus ``delta`` (e.g., ``<has_image_width value="512" delta="2" />``).
|
||||
Alternatively the range of the expected width can be specified by ``min`` and/or ``max``.
|
||||
|
||||
$attribute_list::5
|
||||
]]>
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:attribute name="width" type="xs:integer" use="optional">
|
||||
<xs:attribute name="value" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required width of the image.</xs:documentation>
|
||||
<xs:documentation xml:lang="en">Expected width of the image (in pixels).`</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="height" type="xs:integer" use="optional">
|
||||
<xs:attribute name="delta" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required height of the image.</xs:documentation>
|
||||
<xs:documentation xml:lang="en">Maximum allowed difference of the image width (in pixels, default is 0). The observed width has to be in the range ``value +- delta``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="channels" type="xs:integer" use="optional">
|
||||
<xs:attribute name="min" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required number of channels of the image (e.g., 1 for grayscale, 3 for RGB, 4 for RGBA images).</xs:documentation>
|
||||
<xs:documentation xml:lang="en">Minimum allowed width of the image (in pixels).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="max" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Maximum allowed width of the image (in pixels).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attributeGroup ref="AssertAttributeNegate"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="AssertImageHasIntensities">
|
||||
<xs:complexType name="AssertHasImageHeight">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en"><![CDATA[
|
||||
Asserts the image intensities comply with the specified constraints.
|
||||
|
||||
```xml
|
||||
<image_has_intensities mean_intensity="0.83" center_of_mass="511.07, 223.34" eps="0.01" />
|
||||
```
|
||||
Asserts the output is an image and has a specific height (in pixels) of ``value``
|
||||
plus/minus ``delta`` (e.g., ``<has_image_height value="512" delta="2" />``).
|
||||
Alternatively the range of the expected height can be specified by ``min`` and/or ``max``.
|
||||
|
||||
$attribute_list::5
|
||||
]]>
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:attribute name="mean_intensity" type="xs:float" use="optional">
|
||||
<xs:attribute name="value" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Expected height of the image (in pixels).`</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="delta" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Maximum allowed difference of the image height (in pixels, default is 0). The observed height has to be in the range ``value +- delta``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="min" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Minimum allowed height of the image (in pixels).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="max" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Maximum allowed height of the image (in pixels).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attributeGroup ref="AssertAttributeNegate"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="AssertHasImageChannels">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en"><![CDATA[
|
||||
Asserts the output is an image and has a specific number of channels of ``value``
|
||||
plus/minus ``delta`` (e.g., ``<has_image_height value="512" delta="2" />``).
|
||||
Alternatively the range of the expected number of channels can be specified by ``min`` and/or ``max``.
|
||||
|
||||
$attribute_list::5
|
||||
]]>
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:attribute name="value" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Expected number of channels of the image.`</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="delta" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Maximum allowed difference of the number of channels (default is 0). The observed number of channels has to be in the range ``value +- delta``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="min" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Minimum allowed number of channels.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="max" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Maximum allowed number of channels.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attributeGroup ref="AssertAttributeNegate"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="AssertHasImageMeanIntensity">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en"><![CDATA[
|
||||
Asserts the output is an image and has a specific mean intensity value of ``value``
|
||||
plus/minus ``delta`` (e.g., ``<image_has_mean_intensity value="0.83" />``).
|
||||
Alternatively the range of the expected mean intensity value can be specified by ``min`` and/or ``max``.
|
||||
|
||||
$attribute_list::5
|
||||
]]>
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:attribute name="value" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required mean value of the image intensities.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="mean_intensity_min" type="xs:float" use="optional">
|
||||
<xs:attribute name="delta" type="xs:float" use="optional" default="0.01">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The absolute tolerance to be used for ``value`` (defaults to ``0.01``). The observed mean value of the image intensities has to be in the range ``value +- delta``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="min" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">A lower bound of the required mean value of the image intensities.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="mean_intensity_max" type="xs:float" use="optional">
|
||||
<xs:attribute name="max" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">An upper bound of the required mean value of the image intensities.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="center_of_mass" type="xs:string" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required center of mass of the image intensities (horizontal and vertical coordinate, separated by a comma).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="eps" type="xs:float" use="optional" default="0.01">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The absolute tolerance to be used for the ``mean_intensity`` and ``center_of_mass`` assertions (defaults to ``0.01``).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="channel" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Restricts the ``mean_intensity``, ``mean_intensity_min``, ``mean_intensity_max``, and ``center_of_mass`` assertions to a specific channel of the image (where the value ``0`` corresponds to the first image channel).</xs:documentation>
|
||||
<xs:documentation xml:lang="en">Restricts the assertion to a specific channel of the image (where ``0`` corresponds to the first image channel).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="AssertImageHasLabels">
|
||||
<xs:complexType name="AssertHasImageCenterOfMass">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en"><![CDATA[
|
||||
Asserts the labels in a label image comply with the specified constraints.
|
||||
|
||||
```xml
|
||||
<number_of_objects number_of_objects="187" mean_object_size="111.87" eps="0.01" exclude_labels="0" />
|
||||
```
|
||||
Asserts the output is an image and has a specific center of mass of ``point``,
|
||||
or has an Euclidean distance of ``delta`` or less to that point (e.g.,
|
||||
``<has_image_center_of_mass point="511.07, 223.34" />``).
|
||||
|
||||
$attribute_list::5
|
||||
]]>
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:attribute name="number_of_objects" type="xs:integer" use="optional">
|
||||
<xs:attribute name="point" type="xs:string" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required number of unique labels in the image. It is assumed that each individual object corresponds to a unique label.</xs:documentation>
|
||||
<xs:documentation xml:lang="en">The required center of mass of the image intensities (horizontal and vertical coordinate, separated by a comma).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="mean_object_size" type="xs:float" use="optional">
|
||||
<xs:attribute name="delta" type="xs:float" use="optional" default="0.01">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required mean size of the objects in the image, where the size of an object is measured by the number of pixels. It is assumed that each individual object corresponds to a unique label.</xs:documentation>
|
||||
<xs:documentation xml:lang="en">The maximum allowed Euclidean distance to the required center of mass (defaults to ``0.01``).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="mean_object_size_min" type="xs:float" use="optional">
|
||||
<xs:attribute name="channel" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">A lower bound of the required mean size of the objects in the image, where the size of an object is measured by the number of pixels. It is assumed that each individual object corresponds to a unique label.</xs:documentation>
|
||||
<xs:documentation xml:lang="en">Restricts the assertion to a specific channel of the image (where ``0`` corresponds to the first image channel).</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="mean_object_size_max" type="xs:float" use="optional">
|
||||
</xs:complexType>
|
||||
<xs:complexType name="AssertHasImageLabels">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en"><![CDATA[
|
||||
Asserts the output is an image and has the specified number of labels, or unique values (e.g.,
|
||||
``<has_image_labels value="187" exclude_labels="0" />``).
|
||||
The primary usage of this assertion is to verify the number of objects in images with uniquely labeled objects.
|
||||
|
||||
$attribute_list::5
|
||||
]]>
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:attribute name="value" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">An upper bound of the required mean size of the objects in the image, where the size of an object is measured by the number of pixels. It is assumed that each individual object corresponds to a unique label.</xs:documentation>
|
||||
<xs:documentation xml:lang="en">Expected number of labels.`</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="eps" type="xs:float" use="optional" default="0.01">
|
||||
<xs:attribute name="delta" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The absolute tolerance to be used for the ``mean_object_size`` assertion (defaults to 0.01).</xs:documentation>
|
||||
<xs:documentation xml:lang="en">Maximum allowed difference of the number of labels (default is 0). The observed number of labels has to be in the range ``value +- delta``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="min" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Minimum allowed number of labels.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="max" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Maximum allowed number of labels.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="channel" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Restricts the assertion to a specific channel of the image (where ``0`` corresponds to the first image channel). Must be used with multi-channel imags.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="labels" type="xs:string" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">List of labels, separated by a comma. Labels *not* on this list will be excluded from consideration. Cannot be used in combination with ``exclude_labels``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="exclude_labels" type="xs:string" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">List of labels to be excluded from consideration for the ``number_of_objects`` and ``mean_object_size`` assertions, separated by a comma. The primary usage of this attribute is to exclude the background of a label image.</xs:documentation>
|
||||
<xs:documentation xml:lang="en">List of labels to be excluded from consideration, separated by a comma. The primary usage of this attribute is to exclude the background of a label image. Cannot be used in combination with ``labels``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attributeGroup ref="AssertAttributeNegate"/>
|
||||
</xs:complexType>
|
||||
<xs:complexType name="AssertHasImageMeanObjectSize">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en"><![CDATA[
|
||||
Asserts the output is an image with labeled objects which have the specified mean size (number of pixels, e.g.,
|
||||
``<has_image_mean_object_size value="111.87" exclude_labels="0" />``). The labels must be unique.
|
||||
|
||||
$attribute_list::5
|
||||
]]>
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:attribute name="value" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The required mean size of the uniquely labeled objects.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="delta" type="xs:float" use="optional" default="0.01">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">The absolute tolerance to be used for ``value`` (defaults to ``0.01``). The observed mean size of the uniquely labeled objects has to be in the range ``value +- delta``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="min" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">A lower bound of the required mean size of the uniquely labeled objects.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="max" type="xs:float" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">An upper bound of the required mean size of the uniquely labeled objects.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="channel" type="xs:integer" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">Restricts the assertion to a specific channel of the image (where ``0`` corresponds to the first image channel). Must be used with multi-channel imags.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="labels" type="xs:string" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">List of labels, separated by a comma. Labels *not* on this list will be excluded from consideration. Cannot be used in combination with ``exclude_labels``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute name="exclude_labels" type="xs:string" use="optional">
|
||||
<xs:annotation>
|
||||
<xs:documentation xml:lang="en">List of labels to be excluded from consideration, separated by a comma. The primary usage of this attribute is to exclude the background of a label image. Cannot be used in combination with ``labels``.</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
<param name="input" value="im1_uint8.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_metadata width="32" height="32" channels="1" />
|
||||
<image_has_intensities center_of_mass="15.61, 15.48" />
|
||||
<has_image_width value="32" />
|
||||
<has_image_height value="32" />
|
||||
<has_image_channels value="1" />
|
||||
<has_image_center_of_mass point="15.61, 15.48" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -23,11 +25,15 @@
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_metadata width="32" height="32" channels="3" />
|
||||
<image_has_intensities channel="0" mean_intensity="0.25" center_of_mass="7.5, 7.5" />
|
||||
<image_has_intensities channel="1" mean_intensity="0.0" />
|
||||
<image_has_intensities channel="2" mean_intensity="0" />
|
||||
<image_has_intensities mean_intensity="0.08333333333" center_of_mass="7.5, 7.5" />
|
||||
<has_image_width value="32" />
|
||||
<has_image_height value="32" />
|
||||
<has_image_channels value="3" />
|
||||
<has_image_center_of_mass channel="0" point="7.5, 7.5" />
|
||||
<has_image_mean_intensity channel="0" value="0.25" />
|
||||
<has_image_mean_intensity channel="1" value="0.0" />
|
||||
<has_image_mean_intensity channel="2" value="0" />
|
||||
<has_image_center_of_mass point="7.5, 7.5" />
|
||||
<has_image_mean_intensity value="0.08333333333" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -35,7 +41,7 @@
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_intensities channel="0" mean_intensity="0.24" />
|
||||
<has_image_mean_intensity channel="0" value="0.24" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -43,7 +49,7 @@
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_intensities channel="0" mean_intensity="0.24" eps="0.0100000001" />
|
||||
<has_image_mean_intensity channel="0" value="0.24" delta="0.0100000001" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -51,7 +57,7 @@
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_intensities channel="0" mean_intensity_min="0.24" mean_intensity_max="0.26" />
|
||||
<has_image_mean_intensity channel="0" min="0.24" max="0.26" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -59,7 +65,7 @@
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_intensities channel="0" mean_intensity_max="0.24" />
|
||||
<has_image_mean_intensity channel="0" max="0.24" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -67,7 +73,7 @@
|
||||
<param name="input" value="im3_b.tif" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_intensities channel="0" mean_intensity_min="0.26" />
|
||||
<has_image_mean_intensity channel="0" min="0.26" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -76,8 +82,11 @@
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_metadata width="32" height="32" channels="1" />
|
||||
<image_has_labels number_of_objects="1" mean_object_size="256" exclude_labels="0" />
|
||||
<has_image_width value="32" />
|
||||
<has_image_height value="32" />
|
||||
<has_image_channels value="1" />
|
||||
<has_image_labels value="1" exclude_labels="0" />
|
||||
<has_image_mean_object_size value="256" exclude_labels="0" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -85,16 +94,11 @@
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_metadata width="32" height="32" channels="1" />
|
||||
<image_has_labels number_of_objects="2" mean_object_size="512" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_test_failure="true">
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_labels mean_object_size="511" eps="0.9" />
|
||||
<has_image_width value="32" />
|
||||
<has_image_height value="32" />
|
||||
<has_image_channels value="1" />
|
||||
<has_image_labels value="2" />
|
||||
<has_image_mean_object_size value="512" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -102,8 +106,7 @@
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_metadata width="32" height="32" channels="1" />
|
||||
<image_has_labels number_of_objects="2" mean_object_size="511" eps="1.0" />
|
||||
<has_image_mean_object_size labels="0" value="768" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -111,7 +114,7 @@
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_labels mean_object_size_min="511" mean_object_size_max="513" />
|
||||
<has_image_mean_object_size labels="0, 1" value="512" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -119,7 +122,27 @@
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_labels mean_object_size_max="511" />
|
||||
<has_image_mean_object_size value="511" delta="0.9" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test>
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<has_image_width value="32" />
|
||||
<has_image_height value="32" />
|
||||
<has_image_channels value="1" />
|
||||
<has_image_labels value="2" />
|
||||
<has_image_mean_object_size value="511" delta="1.0" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test>
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<has_image_mean_object_size min="511" max="513" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
@@ -127,7 +150,15 @@
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<image_has_labels mean_object_size_min="513" />
|
||||
<has_image_mean_object_size max="511" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
<test expect_test_failure="true">
|
||||
<param name="input" value="im2_b.png" />
|
||||
<output name="output">
|
||||
<assert_contents>
|
||||
<has_image_mean_object_size min="513" />
|
||||
</assert_contents>
|
||||
</output>
|
||||
</test>
|
||||
|
||||
Reference in New Issue
Block a user