zea.data.augmentations¶
Augmentation layers for ultrasound data.
Classes
|
Adds a circular inclusion to the image, optionally at random locations. |
- class zea.data.augmentations.RandomCircleInclusion(radius, fill_value=1.0, circle_axes=(1, 2), with_batch_dim=True, return_centers=False, recovery_threshold=0.1, randomize_location_across_batch=True, seed=None, width_range=None, height_range=None, **kwargs)[source]¶
Bases:
LayerAdds a circular inclusion to the image, optionally at random locations.
Since this can accept N-dimensional inputs, you’ll need to specify your
circle_axes– these are the axes onto which a circle will be drawn. This circle will then be broadcast along the remaining dimensions.You can then optionally specify whether there is a batch dim, and whether the circles should be located randomly across that batch.
For example, if you have a batch of videos, e.g. of shape [batch, frame, height, width], then you might want to specify
circle_axes=(2, 3), andrandomize_location_across_batch=True. This would result in a circle that is located in the same place per video, but different locations for different videos.Once your method has recovered the circles, you can evaluate them using the
evaluate_recovered_circle_accuracy()method, which will expect an input shape matching your inputs tocall().Initialize RandomCircleInclusion.
- Parameters:
radius (
int|tuple[int,int]) – Radius of the circle/ellipse to include.fill_value (
float) – Value to fill inside the circle.circle_axes (
tuple[int,int]) – Axes along which to draw the circle (height, width).with_batch_dim (bool) – Whether input has a batch dimension.
return_centers (bool) – Whether to return circle centers along with images.
recovery_threshold (float) – Threshold for considering a pixel as recovered.
randomize_location_across_batch (bool) – If True (and with_batch_dim=True), each batch element gets a different random center. If False, all batch elements share the same center.
seed (Any) – Optional random seed for reproducibility.
width_range (
tuple[int,int]) – Range (min, max) for circle center x (width axis).height_range (
tuple[int,int]) – Range (min, max) for circle center y (height axis).**kwargs – Additional keyword arguments for the parent Layer.
Example
>>> from zea.data.augmentations import RandomCircleInclusion >>> from keras import ops >>> layer = RandomCircleInclusion( ... radius=5, ... circle_axes=(1, 2), ... with_batch_dim=True, ... ) >>> image = ops.zeros((1, 28, 28), dtype="float32") >>> out = layer(image)
- build(input_shape)[source]¶
Build the layer and compute static shape and permutation info.
- Parameters:
input_shape (tuple) – Shape of the input tensor.
- call(x, seed=None)[source]¶
Apply the random circle inclusion augmentation.
- Parameters:
x (Tensor) – Input tensor.
seed (Any, optional) – Optional random seed for reproducibility.
- Returns:
- Augmented images, and optionally the circle
centers if return_centers is True.
- Return type:
Tensor or tuple
- compute_output_shape(input_shape)[source]¶
Compute output shape for the layer.
- Parameters:
input_shape (tuple) – Shape of the input tensor.
- Returns:
The output shape (same as input).
- Return type:
tuple
- evaluate_recovered_circle_accuracy(images, centers, recovery_threshold, fill_value=None)[source]¶
Evaluate the percentage of the true circle that has been recovered in the images, and return a mask of the detected part of the circle.
- Parameters:
images (Tensor) – Tensor of images (any shape, with circle axes as specified).
centers (Tensor) – Tensor of circle centers (matching batch size).
recovery_threshold (float) – Threshold for considering a pixel as recovered.
fill_value (float, optional) – Optionally override fill_value for cases where image range has changed.