Skip to content

Commit 745dd4d

Browse files
authored
docs: Augmentations (#310)
* added elastic and affine example * import statements and examples. * absolute imports * typo in docstrings. * removed save as np array in example * Type hints: Image | np.ndarray * absolute imports. * last image type hint
1 parent ac276d7 commit 745dd4d

2 files changed

Lines changed: 41 additions & 40 deletions

File tree

deeptrack/augmentations.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
6464
- `CropTight`: Crops to remove empty space at start and end of a 3D array.
6565
66-
- `Pad`: Pads image.
66+
- `Pad`: Pads image with values.
6767
6868
- `PadMultiplesOf`: Pad images until height/width is a multiple of a value.
6969
@@ -104,10 +104,10 @@
104104
from scipy.ndimage import gaussian_filter
105105
from scipy.ndimage.interpolation import map_coordinates
106106

107-
from . import utils
108-
from .features import Feature
109-
from .image import Image
110-
from .types import ArrayLike, PropertyLike
107+
from deeptrack import utils
108+
from deeptrack.features import Feature
109+
from deeptrack.image import Image
110+
from deeptrack.types import ArrayLike, PropertyLike
111111

112112

113113
class Augmentation(Feature):
@@ -126,10 +126,10 @@ class Augmentation(Feature):
126126
127127
Methods
128128
-------
129-
`_image_wrapped_process_and_get(image_list: list[Image], time_consistent: PropertyLike[bool], **kwargs) -> list[list]`
129+
`_image_wrapped_process_and_get(image_list: list[Image] | list[np.ndarray], time_consistent: PropertyLike[bool], **kwargs) -> list[list]`
130130
Augments a list of images and returns a wrapped output.
131131
132-
`_no_wrap_process_and_get(image_list: list[Image], time_consistent: PropertyLike[bool], **kwargs) -> list[list]`
132+
`_no_wrap_process_and_get(image_list: list[Image] | list[np.ndarray], time_consistent: PropertyLike[bool], **kwargs) -> list[list]`
133133
Augments a list of images and returns the raw output.
134134
135135
`update_properties(*args, **kwargs)`
@@ -146,7 +146,7 @@ def __init__(
146146

147147
def _image_wrapped_process_and_get (
148148
self: Augmentation,
149-
image_list: list[Image],
149+
image_list: list[Image] | list[np.ndarray],
150150
time_consistent: PropertyLike[bool],
151151
**kwargs
152152
) -> list[list]:
@@ -192,7 +192,7 @@ def _image_wrapped_process_and_get (
192192

193193
def _no_wrap_process_and_get(
194194
self: Augmentation,
195-
image_list: list[Image],
195+
image_list: list[Image] | list[np.ndarray],
196196
time_consistent: PropertyLike[bool],
197197
**kwargs
198198
) -> list[list]:
@@ -266,7 +266,7 @@ class Reuse(Feature):
266266
267267
Methods
268268
-------
269-
`get(image: Image, uses: PropertyLike[int], storage: PropertyLike[int], **kwargs) -> list[Image]`
269+
`get(image: Image | np.ndarray, uses: PropertyLike[int], storage: PropertyLike[int], **kwargs) -> list[Image]`
270270
Abstract method which performs the `Reuse` augmentation.
271271
272272
"""
@@ -287,7 +287,7 @@ def __init__(
287287

288288
def get(
289289
self: Reuse,
290-
image: Image,
290+
image: Image | np.ndarray,
291291
uses: PropertyLike[int],
292292
storage: PropertyLike[int],
293293
**kwargs
@@ -340,10 +340,10 @@ class FlipLR(Augmentation):
340340
341341
Methods
342342
-------
343-
`get(image: Image, augment: PropertyLike[bool], **kwargs) -> Image`
343+
`get(image: Image | np.ndarray, augment: PropertyLike[bool], **kwargs) -> Image`
344344
Abstract method which performs the `FlipLR` augmentation.
345345
346-
`update_properties(image: Image, augment: PropertyLike[bool], **kwargs) -> None`
346+
`update_properties(image: Image | np.ndarray, augment: PropertyLike[bool], **kwargs) -> None`
347347
Abstract method to update the properties of the image.
348348
349349
"""
@@ -364,7 +364,7 @@ def __init__(
364364

365365
def get(
366366
self: FlipLR,
367-
image: Image,
367+
image: Image | np.ndarray,
368368
augment: PropertyLike[bool],
369369
**kwargs
370370
) -> Image:
@@ -378,7 +378,7 @@ def get(
378378

379379
def update_properties(
380380
self: FlipLR,
381-
image: Image,
381+
image: Image | np.ndarray,
382382
augment: PropertyLike[bool],
383383
**kwargs
384384
) -> None:
@@ -410,9 +410,9 @@ class FlipUD(Augmentation):
410410
411411
Methods
412412
-------
413-
`get(image: Image, augment: PropertyLike[bool], **kwargs) -> Image`
413+
`get(image: Image | np.ndarray, augment: PropertyLike[bool], **kwargs) -> Image`
414414
Abstract method which performs the `FlipUD` augmentation.
415-
`update_properties(image: Image, augment: PropertyLike[bool], **kwargs) -> None`
415+
`update_properties(image: Image | np.ndarray, augment: PropertyLike[bool], **kwargs) -> None`
416416
Abstract method to update the properties of the image.
417417
418418
"""
@@ -433,7 +433,7 @@ def __init__(
433433

434434
def get(
435435
self: FlipUD,
436-
image: Image,
436+
image: Image | np.ndarray,
437437
augment: PropertyLike[bool],
438438
**kwargs
439439
) -> Image:
@@ -447,7 +447,7 @@ def get(
447447

448448
def update_properties(
449449
self: FlipUD,
450-
image: Image,
450+
image: Image | np.ndarray,
451451
augment: PropertyLike[bool],
452452
**kwargs
453453
) -> None:
@@ -479,9 +479,9 @@ class FlipDiagonal(Augmentation):
479479
480480
Methods
481481
-------
482-
`get(image: Image, augment: PropertyLike[bool], **kwargs) -> Image`
482+
`get(image: Image | np.ndarray, augment: PropertyLike[bool], **kwargs) -> Image`
483483
Abstract method which performs the `FlipDiagonal` augmentation.
484-
`update_properties(image: Image, augment: PropertyLike[bool], **kwargs) -> None`
484+
`update_properties(image: Image | np.ndarray, augment: PropertyLike[bool], **kwargs) -> None`
485485
Abstract method to update the properties of the image.
486486
487487
"""
@@ -502,7 +502,7 @@ def __init__(
502502

503503
def get(
504504
self: FlipDiagonal,
505-
image: Image,
505+
image: Image | np.ndarray,
506506
augment: PropertyLike[bool],
507507
**kwargs
508508
) -> Image:
@@ -515,7 +515,7 @@ def get(
515515

516516
def update_properties(
517517
self: FlipDiagonal,
518-
image: Image,
518+
image: Image | np.ndarray,
519519
augment: PropertyLike[bool],
520520
**kwargs
521521
) -> None:
@@ -590,7 +590,7 @@ class Affine(Augmentation):
590590
-------
591591
`_process_properties(properties: dict) -> dict`
592592
Processes the properties of the image.
593-
`get(image: Image, scale: PropertyLike[float], translate: PropertyLike[float], rotate: PropertyLike[float], shear: PropertyLike[float], **kwargs) -> Image`
593+
`get(image: Image | np.ndarray, scale: PropertyLike[float], translate: PropertyLike[float], rotate: PropertyLike[float], shear: PropertyLike[float], **kwargs) -> Image`
594594
Abstract method which performs the `Affine` augmentation.
595595
596596
"""
@@ -648,7 +648,7 @@ def _process_properties(
648648

649649
def get(
650650
self: Affine,
651-
image: Image,
651+
image: Image | np.ndarray,
652652
scale: PropertyLike[float],
653653
translate: PropertyLike[float],
654654
rotate: PropertyLike[float],
@@ -802,7 +802,7 @@ class ElasticTransformation(Augmentation):
802802
803803
Methods
804804
-------
805-
`get(image: Image, sigma: PropertyLike[float], alpha: PropertyLike[float], ignore_last_dim: PropertyLike[bool], **kwargs) -> Image`
805+
`get(image: Image | np.ndarray, sigma: PropertyLike[float], alpha: PropertyLike[float], ignore_last_dim: PropertyLike[bool], **kwargs) -> Image`
806806
Abstract method which performs the `ElasticTransformation` augmentation.
807807
808808
"""
@@ -829,7 +829,7 @@ def __init__(
829829

830830
def get(
831831
self: ElasticTransformation,
832-
image: Image,
832+
image: Image | np.ndarray,
833833
sigma: PropertyLike[float],
834834
alpha: PropertyLike[float],
835835
ignore_last_dim: PropertyLike[bool],
@@ -914,7 +914,7 @@ class Crop(Augmentation):
914914
915915
Methods
916916
-------
917-
`get(image: Image, corner: PropertyLike[str], crop: PropertyLike[int], crop_mode: PropertyLike[str], **kwargs) -> Image`
917+
`get(image: Image | np.ndarray, corner: PropertyLike[str], crop: PropertyLike[int], crop_mode: PropertyLike[str], **kwargs) -> Image`
918918
Abstract method which performs the `Crop` augmentation.
919919
920920
"""
@@ -939,7 +939,7 @@ def __init__(
939939

940940
def get(
941941
self: Crop,
942-
image: Image,
942+
image: Image | np.ndarray,
943943
corner: PropertyLike[str],
944944
crop: int | list[int] | tuple[int],
945945
crop_mode: PropertyLike[str],
@@ -1042,7 +1042,7 @@ def __init__(
10421042
kwargs.pop("crop_mode", False)
10431043

10441044
def image_to_crop(
1045-
image: Image
1045+
image: Image | np.ndarray
10461046
) -> Image:
10471047

10481048
shape = image.shape
@@ -1083,7 +1083,7 @@ class CropTight(Feature):
10831083
10841084
Methods
10851085
-------
1086-
`get(image: Image, eps: PropertyLike[float], **kwargs) -> Image`
1086+
`get(image: Image | np.ndarray, eps: PropertyLike[float], **kwargs) -> Image`
10871087
Abstract method which performs the `CropTight` augmentation.
10881088
10891089
"""
@@ -1097,7 +1097,7 @@ def __init__(
10971097

10981098
def get(
10991099
self: CropTight,
1100-
image: Image,
1100+
image: Image | np.ndarray,
11011101
eps: PropertyLike[float],
11021102
**kwargs
11031103
) -> Image:
@@ -1136,9 +1136,9 @@ class Pad(Augmentation):
11361136
11371137
Methods
11381138
-------
1139-
`get(image: Image, px: PropertyLike[int], **kwargs) -> Image`
1139+
`get(image: Image | np.ndarray, px: PropertyLike[int], **kwargs) -> Image`
11401140
Abstract method which performs the `Pad` augmentation.
1141-
`_image_wrap_process_and_get(images: list[Image], **kwargs) -> list[Image]`
1141+
`_image_wrap_process_and_get(images: list[Image] | list[np.ndarray], **kwargs) -> list[Image]`
11421142
Simple method which wraps an `Image` in a `list`.
11431143
11441144
Returns
@@ -1159,7 +1159,7 @@ def __init__(
11591159

11601160
def get(
11611161
self: Pad,
1162-
image: Image,
1162+
image: Image | np.ndarray,
11631163
px: PropertyLike[int],
11641164
**kwargs
11651165
) -> Image:
@@ -1187,7 +1187,7 @@ def get(
11871187

11881188
def _image_wrap_process_and_get(
11891189
self: Pad,
1190-
images: list[Image],
1190+
images: list[Image] | list[np.ndarray],
11911191
**kwargs
11921192
) -> list[Image]:
11931193
"""Simple method which wraps an `Image` in a `list`.
@@ -1223,7 +1223,7 @@ def __init__(
12231223
) -> None:
12241224

12251225
def amount_to_pad(
1226-
image: Image
1226+
image: Image | np.ndarray
12271227
) -> list[int]:
12281228
"""Method to calculate number of pixels.
12291229

deeptrack/tests/test_augmentations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
import unittest
66

7-
from .. import augmentations, optics, scatterers
8-
9-
from ..features import Feature
107
import numpy as np
118

9+
from deeptrack import augmentations, optics, scatterers
10+
from deeptrack.features import Feature
11+
1212

1313
class TestAugmentations(unittest.TestCase):
1414
class DummyFeature(Feature):
@@ -73,6 +73,7 @@ def test_ElasticTransformation(self):
7373
import random
7474
random.seed(1000)
7575
# 3D input
76+
7677
im = np.zeros((10, 8, 2))
7778
transformer = augmentations.ElasticTransformation(
7879
alpha=20,

0 commit comments

Comments
 (0)