Geometric API#

class serket.image.HorizontalFlip2D(*a, **k)[source]#

Flip channels left to right.

../_images/horizontalflip2d.png

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:
__call__(image)[source]#

Call self as a function.

Parameters:

image (Array)

Return type:

Array

class serket.image.HorizontalShear2D(angle)[source]#

Shear an image horizontally

../_images/horizontalshear2d.png
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]]]
__call__(image)[source]#

Call self as a function.

Parameters:

image (Array)

Return type:

Array

class serket.image.HorizontalTranslate2D(shift, spatial_ndim=2)[source]#

Translate an image horizontally by a pixel value.

../_images/horizontaltranslate2d.png
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'>)

__call__(image)[source]#

Call self as a function.

Parameters:

image (Array)

Return type:

Array

class serket.image.RandomHorizontalFlip2D(rate, spatial_ndim=2)[source]#

Flip channels left to right with a probability of rate.

../_images/horizontalflip2d.png
Parameters:

rate (float) – The probability of flipping the image.

Note

use tree_eval() to replace this layer with Identity during

Example

>>> 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)

__call__(image, *, key=None)[source]#

Call self as a function.

Parameters:
  • image (Array)

  • key (Optional[Array])

Return type:

Array

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 with Identity during 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]]]
__call__(image, *, key=None)[source]#

Call self as a function.

Parameters:
  • image (Array)

  • key (Optional[Array])

Return type:

Array

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 with Identity during 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)

__call__(image, *, key=None)[source]#

Call self as a function.

Parameters:
  • image (Array)

  • key (Optional[Array])

Return type:

Array

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 with Identity during 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]]]
__call__(image, *, key)[source]#

Call self as a function.

Parameters:
  • image (Array)

  • key (Array)

Return type:

Array

class serket.image.RandomVerticalFlip2D(rate, spatial_ndim=2)[source]#

Flip channels up to down with a probability of rate.

../_images/verticalflip2d.png
Parameters:

rate (float) – The probability of flipping the image.

Note

use tree_eval() to replace this layer with Identity during

Example

>>> 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)

__call__(image, *, key=None)[source]#

Call self as a function.

Parameters:
  • image (Array)

  • key (Optional[Array])

Return type:

Array

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 with Identity during 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]]]
__call__(image, *, key=None)[source]#

Call self as a function.

Parameters:
  • image (Array)

  • key (Optional[Array])

Return type:

Array

class serket.image.RandomVerticalTranslate2D(*a, **k)[source]#

Translate an image vertically by a random pixel value.

Note

  • Use tree_eval() to replace this layer with Identity during 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]]]
__call__(image, *, key=None)[source]#

Call self as a function.

Parameters:
  • image (Array)

  • key (Optional[Array])

Return type:

Array

class serket.image.Rotate2D(angle)[source]#

Rotate_2d a 2D image by an angle in dgrees in CCW direction

../_images/rotate2d.png
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]]]
__call__(image)[source]#

Call self as a function.

Parameters:

image (Array)

Return type:

Array

class serket.image.VerticalFlip2D(*a, **k)[source]#

Flip channels up to down.

../_images/verticalflip2d.png

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:
__call__(image)[source]#

Call self as a function.

Parameters:

image (Array)

Return type:

Array

class serket.image.VerticalShear2D(angle)[source]#

Shear an image vertically

../_images/verticalshear2d.png
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]]]
__call__(image)[source]#

Call self as a function.

Parameters:

image (Array)

Return type:

Array

class serket.image.VerticalTranslate2D(shift, spatial_ndim=2)[source]#

Translate an image vertically by a pixel value.

../_images/verticaltranslate2d.png
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'>)

__call__(image)[source]#

Call self as a function.

Parameters:

image (Array)

Return type:

Array

serket.image.horizontal_flip_2d(image)[source]#
Parameters:

image (Array)

Return type:

Array

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

serket.image.rotate_2d(image, angle)[source]#

rotate an image by an angle in degrees in CCW direction.

Parameters:
  • image (Array)

  • angle (float)

Return type:

Array

serket.image.vertical_flip_2d(image)[source]#
Parameters:

image (Array)

Return type:

Array

serket.image.vertical_shear_2d(image, angle)[source]#

shear cols by an angle in degrees

Parameters:
  • image (Array)

  • angle (float)

Return type:

Array