Geometric API#
- class serket.image.HorizontalFlip2D(*a, **k)[source]#
Flip channels left to right.
Examples
>>> import jax.numpy as jnp >>> import serket as sk >>> x = jnp.arange(1,10).reshape(1,3, 3) >>> print(x) [[[1 2 3] [4 5 6] [7 8 9]]]
>>> print(sk.image.HorizontalFlip2D()(x)) [[[3 2 1] [6 5 4] [9 8 7]]]
- Reference:
- class serket.image.HorizontalShear2D(angle)[source]#
Shear an image horizontally
- Parameters:
angle (
float) â angle to rotate_2d in degrees counter-clockwise direction.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.HorizontalShear2D(45)(x)) [[[ 0 0 1 2 3] [ 0 6 7 8 9] [11 12 13 14 15] [17 18 19 20 0] [23 24 25 0 0]]]
- class serket.image.HorizontalTranslate2D(shift, spatial_ndim=2)[source]#
Translate an image horizontally by a pixel value.
- Parameters:
shift (
int) â The number of pixels to shift the image by.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.HorizontalTranslate2D(2)(x)) [[[ 0 0 1 2 3] [ 0 0 6 7 8] [ 0 0 11 12 13] [ 0 0 16 17 18] [ 0 0 21 22 23]]]
- Parameters:
spatial_ndim (
int)
-
shift:
int# - Field Information:
Name:
shift- Callbacks:
On setting attribute:
IsInstance(klass=<class 'int'>)
- class serket.image.RandomHorizontalFlip2D(rate, spatial_ndim=2)[source]#
Flip channels left to right with a probability of rate.
- Parameters:
rate (
float) â The probability of flipping the image.
Note
use
tree_eval()to replace this layer withIdentityduringExample
>>> import jax >>> import jax.numpy as jnp >>> import serket as sk >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> key = jax.random.key(0) >>> print(sk.image.RandomHorizontalFlip2D(rate=1.0)(x, key=key)) [[[ 5 4 3 2 1] [10 9 8 7 6] [15 14 13 12 11] [20 19 18 17 16] [25 24 23 22 21]]]
- Parameters:
spatial_ndim (
int)
-
rate:
float# - Field Information:
Name:
rate- Callbacks:
On setting attribute:
IsInstance(klass=<class 'float'>)Range(min_val=0.0, max_val=1.0, min_inclusive=True, max_inclusive=True)
- class serket.image.RandomHorizontalShear2D(range=(0.0, 90.0))[source]#
Shear an image horizontally with random angle choice.
- Parameters:
range (
tuple[float,float]) â a tuple of min angle and max angle to randdomly choose from.
Note
Use
tree_eval()to replace this layer withIdentityduring evaluation.
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 17).reshape(1, 4, 4) >>> layer = sk.image.RandomHorizontalShear2D((45, 45)) >>> eval_layer = sk.tree_eval(layer) >>> print(eval_layer(x)) [[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12] [13 14 15 16]]]
Example
>>> import serket as sk >>> import jax >>> import jax.numpy as jnp >>> import jax.random as jr >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.RandomHorizontalShear2D((45, 45))(x, key=jr.key(0))) [[[ 0 0 1 2 3] [ 0 6 7 8 9] [11 12 13 14 15] [17 18 19 20 0] [23 24 25 0 0]]]
- class serket.image.RandomHorizontalTranslate2D(spatial_ndim=2)[source]#
Translate an image horizontally by a random pixel value.
Note
Use
tree_eval()to replace this layer withIdentityduring evaluation.
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 17).reshape(1, 4, 4) >>> layer = sk.image.RandomHorizontalTranslate2D() >>> eval_layer = sk.tree_eval(layer) >>> print(eval_layer(x)) [[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12] [13 14 15 16]]]
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.RandomHorizontalTranslate2D()(x, key=jr.key(0))) [[[ 4 5 0 0 0] [ 9 10 0 0 0] [14 15 0 0 0] [19 20 0 0 0] [24 25 0 0 0]]]
- Parameters:
spatial_ndim (
int)
- class serket.image.RandomRotate2D(range=(0.0, 360.0))[source]#
Rotate_2d a 2D image by an angle in dgrees in CCW direction
- Parameters:
range (
tuple[float,float]) â a tuple of min angle and max angle to randdomly choose from.
Note
Use
tree_eval()to replace this layer withIdentityduring evaluation.
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 17).reshape(1, 4, 4) >>> layer = sk.image.RandomRotate2D((10, 30)) >>> eval_layer = sk.tree_eval(layer) >>> print(eval_layer(x)) [[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12] [13 14 15 16]]]
Example
>>> import serket as sk >>> import jax >>> import jax.numpy as jnp >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.RandomRotate2D((10, 30))(x, key=jax.random.key(0))) [[[ 1 2 4 7 4] [ 4 6 9 11 11] [ 8 10 13 16 18] [10 15 17 20 22] [ 8 19 22 18 11]]]
- class serket.image.RandomVerticalFlip2D(rate, spatial_ndim=2)[source]#
Flip channels up to down with a probability of rate.
- Parameters:
rate (
float) â The probability of flipping the image.
Note
use
tree_eval()to replace this layer withIdentityduringExample
>>> import jax >>> import jax.numpy as jnp >>> import serket as sk >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> key = jax.random.key(0) >>> print(sk.image.RandomVerticalFlip2D(rate=1.0)(x, key=key)) [[[21 22 23 24 25] [16 17 18 19 20] [11 12 13 14 15] [ 6 7 8 9 10] [ 1 2 3 4 5]]]
- Parameters:
spatial_ndim (
int)
-
rate:
float# - Field Information:
Name:
rate- Callbacks:
On setting attribute:
IsInstance(klass=<class 'float'>)Range(min_val=0.0, max_val=1.0, min_inclusive=True, max_inclusive=True)
- class serket.image.RandomVerticalShear2D(range=(0.0, 90.0))[source]#
Shear an image vertically with random angle choice.
- Parameters:
range (
tuple[float,float]) â a tuple of min angle and max angle to randdomly choose from.
Note
Use
tree_eval()to replace this layer withIdentityduring evaluation.
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 17).reshape(1, 4, 4) >>> layer = sk.image.RandomVerticalShear2D((45, 45)) >>> eval_layer = sk.tree_eval(layer) >>> print(eval_layer(x)) [[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12] [13 14 15 16]]]
Example
>>> import serket as sk >>> import jax >>> import jax.numpy as jnp >>> import jax.random as jr >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.RandomVerticalShear2D((45, 45))(x, key=jr.key(0))) [[[ 0 0 3 9 15] [ 0 2 8 14 20] [ 1 7 13 19 25] [ 6 12 18 24 0] [11 17 23 0 0]]]
- class serket.image.RandomVerticalTranslate2D(*a, **k)[source]#
Translate an image vertically by a random pixel value.
Note
Use
tree_eval()to replace this layer withIdentityduring evaluation.
>>> import serket as sk >>> import jax.numpy as jnp >>> import jax.random as jr >>> x = jnp.arange(1, 17).reshape(1, 4, 4) >>> layer = sk.image.RandomVerticalTranslate2D() >>> eval_layer = sk.tree_eval(layer) >>> print(eval_layer(x)) [[[ 1 2 3 4] [ 5 6 7 8] [ 9 10 11 12] [13 14 15 16]]]
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> import jax.random as jr >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.RandomVerticalTranslate2D()(x, key=jr.key(0))) [[[16 17 18 19 20] [21 22 23 24 25] [ 0 0 0 0 0] [ 0 0 0 0 0] [ 0 0 0 0 0]]]
- class serket.image.Rotate2D(angle)[source]#
Rotate_2d a 2D image by an angle in dgrees in CCW direction
- Parameters:
angle (
float) â angle to rotate_2d in degrees counter-clockwise direction.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.Rotate2D(90)(x)) [[[ 5 10 15 20 25] [ 4 9 14 19 24] [ 3 8 13 18 23] [ 2 7 12 17 22] [ 1 6 11 16 21]]]
- class serket.image.VerticalFlip2D(*a, **k)[source]#
Flip channels up to down.
Examples
>>> import jax.numpy as jnp >>> import serket as sk >>> x = jnp.arange(1,10).reshape(1,3, 3) >>> print(x) [[[1 2 3] [4 5 6] [7 8 9]]]
>>> print(sk.image.VerticalFlip2D()(x)) [[[7 8 9] [4 5 6] [1 2 3]]]
- Reference:
- class serket.image.VerticalShear2D(angle)[source]#
Shear an image vertically
- Parameters:
angle (
float) â angle to rotate_2d in degrees counter-clockwise direction.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.VerticalShear2D(45)(x)) [[[ 0 0 3 9 15] [ 0 2 8 14 20] [ 1 7 13 19 25] [ 6 12 18 24 0] [11 17 23 0 0]]]
- class serket.image.VerticalTranslate2D(shift, spatial_ndim=2)[source]#
Translate an image vertically by a pixel value.
- Parameters:
shift (
int) â The number of pixels to shift the image by.
Example
>>> import serket as sk >>> import jax.numpy as jnp >>> x = jnp.arange(1, 26).reshape(1, 5, 5) >>> print(sk.image.VerticalTranslate2D(2)(x)) [[[ 0 0 0 0 0] [ 0 0 0 0 0] [ 1 2 3 4 5] [ 6 7 8 9 10] [11 12 13 14 15]]]
- Parameters:
spatial_ndim (
int)
-
shift:
int# - Field Information:
Name:
shift- Callbacks:
On setting attribute:
IsInstance(klass=<class 'int'>)
- serket.image.horizontal_shear_2d(image, angle)[source]#
shear rows by an angle in degrees
- Parameters:
image (
Array)angle (
float)
- Return type:
Array
- serket.image.horizontal_translate_2d(image, shift)[source]#
Translate an image horizontally by a pixel value.
- Parameters:
image (
Array)shift (
int)
- Return type:
Array
- serket.image.random_horizontal_flip_2d(key, image, rate)[source]#
- Parameters:
key (
Array)image (
Array)rate (
float)
- Return type:
Array
- serket.image.random_horizontal_shear_2d(key, image, range)[source]#
shear rows by an angle in degrees
- Parameters:
key (
Array)image (
Array)range (
tuple[float,float])
- Return type:
Array
- serket.image.random_horizontal_translate_2d(key, image)[source]#
- Parameters:
key (
Array)image (
Array)
- Return type:
Array
- serket.image.random_rotate_2d(key, image, range)[source]#
- Parameters:
key (
Array)image (
Array)range (
tuple[float,float])
- Return type:
Array
- serket.image.random_vertical_flip_2d(key, image, rate)[source]#
- Parameters:
key (
Array)image (
Array)rate (
float)
- Return type:
Array
- serket.image.random_vertical_shear_2d(key, image, range)[source]#
shear cols by an angle in degrees
- Parameters:
key (
Array)image (
Array)range (
tuple[float,float])
- Return type:
Array
- serket.image.random_vertical_translate_2d(key, image)[source]#
- Parameters:
key (
Array)image (
Array)
- Return type:
Array