Feature Generator

Aydin use a set of well-engineered feature generators to implement image translators internally. Aydin also provides a public API on feature generators to enable developers who might want to use same feature:

StandardFeatureGenerator
ExtensibleFeatureGenerator

ExtensibleFeatureGenerator()

Extensible Feature Generator class

ExtensibleFeatureGenerator.add_feature_group(...)

Adds a feature to this feature generator.

ExtensibleFeatureGenerator.compute(image[, ...])

Computes the features given an image.

ExtensibleFeatureGenerator.create_feature_array(...)

Creates a feature array of the right size and possibly in a 'lazy' way using memory mapping.

ExtensibleFeatureGenerator.clear_features()

Clears the features group list

ExtensibleFeatureGenerator.get_num_features(ndim)

Returns the number of features when considering translations

ExtensibleFeatureGenerator.get_receptive_field_radius()

Returns the receptive field radius in pixels

ExtensibleFeatureGenerator.load(path)

Returns a 'all-batteries-inlcuded' feature generator from a given path (folder)

ExtensibleFeatureGenerator.save(path)

Saves a 'all-batteries-included' feature generator at a given path (folder)

FeatureGeneratorBase

FeatureGeneratorBase()

Feature Generator base class

FeatureGeneratorBase.compute(image[, ...])

Computes the features given an image.

FeatureGeneratorBase.create_feature_array(...)

Creates a feature array of the right size and possibly in a 'lazy' way using memory mapping.

FeatureGeneratorBase.get_receptive_field_radius()

Returns the receptive field radius in pixels

FeatureGeneratorBase.load(path)

Returns a 'all-batteries-inlcuded' feature generator from a given path (folder)

FeatureGeneratorBase.save(path)

Saves a 'all-batteries-included' feature generator at a given path (folder)

StandardFeatureGenerator

ExtensibleFeatureGenerator

class aydin.features.extensible_features.ExtensibleFeatureGenerator[source]

Extensible Feature Generator class

add_feature_group(feature_group: aydin.features.groups.base.FeatureGroupBase, *args, **kwargs)[source]

Adds a feature to this feature generator.

Parameters
feature_groupFeatureGroupBase

feature group

args

additional arguments for function

kwargs

additional keyword arguments for function

clear_features()[source]

Clears the features group list

compute(image, exclude_center_feature: bool = False, exclude_center_value: bool = False, features: Optional[numpy.ndarray] = None, feature_last_dim: bool = True, passthrough_channels: Optional[Tuple[bool]] = None, num_reserved_features: int = 0, excluded_voxels: Optional[List[Tuple[int]]] = None, spatial_feature_offset: Optional[Tuple[float, ...]] = None, spatial_feature_scale: Optional[Tuple[float, ...]] = None)[source]

Computes the features given an image. If the input image is of shape (d,h,w), resulting features are of shape (n,d,h,w) where n is the number of features.

Parameters
imagenumpy.ndarray

image for which features are computed

exclude_center_featurebool

If true, features that use the image patch’s center pixel are entirely excluded from teh set of computed features.

exclude_center_valuebool

If true, the center pixel is never used to compute any feature, different feature generation algorithms can take different approaches to achieve that.

featuresndarray

If None the feature array is allocated internally, if not None the provided array is used to store the features.

feature_last_dimbool

If True the last dimension of the feature array is the feature dimension, if False then it is the first dimension.

passthrough_channelsOptional[Tuple[bool]]

Optional tuple of booleans that specify which channels are ‘pass-through’ channels, i.e. channels that are not featurised and directly used as features.

num_reserved_featuresint

Number of features to be left as blank, useful when adding features separately.

excluded_voxelsOptional[List[Tuple[int]]]

List of pixel coordinates – expressed as tuple of ints relative to the central pixel – that will be excluded from any computed features. This is used for implementing ‘extended blind-spot’ N2S denoising approaches.

spatial_feature_offset: Optional[Tuple[float, …]]

Offset vector to be applied (added) to the spatial features (if used).

spatial_feature_scale: Optional[Tuple[float, …]]

Scale vector to be applied (multiplied) to the spatial features (if used).

Returns
feature arraynumpy.ndarray
create_feature_array(image, nb_features)

Creates a feature array of the right size and possibly in a ‘lazy’ way using memory mapping.

Parameters
imagenumpy.ndarray

image for which features are created

nb_featuresint
Returns
feature arraynumpy.ndarray
get_num_features(ndim: int) int[source]

Returns the number of features when considering translations

Parameters
ndimint

number of dimensions

Returns
nb_featuresint
get_receptive_field_radius() int[source]

Returns the receptive field radius in pixels

Returns
resultint

receptive field radius in pixels

static load(path: str)

Returns a ‘all-batteries-inlcuded’ feature generator from a given path (folder)

Parameters
pathstr

path to load from

Returns
thawed
save(path: str)

Saves a ‘all-batteries-included’ feature generator at a given path (folder)

Parameters
pathstr

path to save to

Returns
frozen

FeatureGeneratorBase

class aydin.features.base.FeatureGeneratorBase[source]

Feature Generator base class

abstract compute(image, exclude_center_feature: bool = False, exclude_center_value: bool = False, features: Optional[numpy.ndarray] = None, feature_last_dim: bool = True, passthrough_channels: Optional[Tuple[bool]] = None, num_reserved_features: int = 0, excluded_voxels: Optional[List[Tuple[int]]] = None, spatial_feature_offset: Optional[Tuple[float, ...]] = None, spatial_feature_scale: Optional[Tuple[float, ...]] = None)[source]

Computes the features given an image. If the input image is of shape (d,h,w), resulting features are of shape (n,d,h,w) where n is the number of features.

Parameters
imagenumpy.ndarray

image for which features are computed

exclude_center_featurebool

If true, features that use the image patch’s center pixel are entirely excluded from teh set of computed features.

exclude_center_valuebool

If true, the center pixel is never used to compute any feature, different feature generation algorithms can take different approaches to acheive that.

featuresndarray

If None the feature array is allocated internally, if not None the provided array is used to store the features.

feature_last_dimbool

If True the last dimension of the feature array is the feature dimension, if False then it is the first dimension.

passthrough_channelsOptional[Tuple[bool]]

Optional tuple of booleans that specify which channels are ‘pass-through’ channels, i.e. channels that are not featurised and directly used as features.

num_reserved_featuresint

Number of features to be left as blank, useful when adding features separately.

excluded_voxelsOptional[List[Tuple[int]]]

List of pixel coordinates – expressed as tuple of ints relative to the central pixel – that will be excluded from any computed features. This is used for implementing ‘extended blind-spot’ N2S denoising approaches.

spatial_feature_offset: Optional[Tuple[float, …]]

Offset vector to be applied (added) to the spatial features (if used).

spatial_feature_scale: Optional[Tuple[float, …]]

Scale vector to be applied (multiplied) to the spatial features (if used).

Returns
feature arraynumpy.ndarray
create_feature_array(image, nb_features)[source]

Creates a feature array of the right size and possibly in a ‘lazy’ way using memory mapping.

Parameters
imagenumpy.ndarray

image for which features are created

nb_featuresint
Returns
feature arraynumpy.ndarray
abstract get_receptive_field_radius()[source]

Returns the receptive field radius in pixels

static load(path: str)[source]

Returns a ‘all-batteries-inlcuded’ feature generator from a given path (folder)

Parameters
pathstr

path to load from

Returns
thawed
save(path: str)[source]

Saves a ‘all-batteries-included’ feature generator at a given path (folder)

Parameters
pathstr

path to save to

Returns
frozen