darsia.TranslationAnalysis#

class TranslationAnalysis(base, N_patches, rel_overlap, translation_estimator, mask=None)[source]#

Bases: object

Class for translation analysis.

Constructor for TranslationAnalysis.

It allows to determine the translation of any image to a given baseline image in order to provide a best-possible match, based on feature detection.

Parameters:
baseimage

Baseline image; it serves as fixed point in the analysis, which is relevant if a series of translations is analyzed. Furthermore, the baseline image provides all reference values as the coordinate system, e.g.

N_patcheslist of two int

Number of patches in x and y direction.

rel_overlapfloat

Relative overal related to patch size in each direction.

Methods

add_translation_analysis(translation_analysis)

Add another translation analysis to the existing one.

bc_x(units)

Prescribed (boundary) conditions for the displacement in x direction.

bc_y(units)

Prescribed (boundary) conditions for the displacement in y direction.

deduct_translation_analysis(translation_analysis)

Overwrite translation analysis by deducting from external one.

find_translation([units])

Find translation map as translation from image to baseline image such that these match as best as possible, measure on features.

load_image(img[, mask])

Load an image to be inspected in futher analysis.

plot_translation([reverse, scaling, mask])

Translate centers of the test image and plot in terms of displacement arrows.

return_patch_translation([reverse, units])

Translate patch centers of the test image.

translate_image([reverse])

Apply translation to an entire image by using piecwise perspective transformation.

update_base(base)

Update baseline image.

update_base_patches()

Update patches of baseline.

update_params([N_patches, rel_overlap])

Routine allowing to update parameters for creating patches.

Attributes

N_patches

Number of patches in matrix indexing.

rel_overlap

Relative overlap.

translation_estimator

Translation estimator.

translation

Cache of current translation.

have_translation

Mask of flags storing success of finding translations for patches.

mask_base

Mask.

add_translation_analysis(translation_analysis)[source]#

Add another translation analysis to the existing one. Modifies the interpolation object by redefinition.

Parameters:
translation_analysisdarsia.TranslationAnalysis

Translation analysis holding an interpolation object.

bc_x(units)[source]#

Prescribed (boundary) conditions for the displacement in x direction.

Can be overwritten. Here, tailored to FluidFlower scenarios, fix the displacement in x-direction at the vertical boundaries of the image.

Parameters:
unitslist of str

“metric” or “pixel”.

Returns:
list of np.ndarray

Coordinates.

list of float

Translation in x direction.

bc_y(units)[source]#

Prescribed (boundary) conditions for the displacement in y direction.

Parameters:
unitslist of str

“metric” or “pixel”.

Returns:
list of np.ndarray

Coordinates.

list of float

Translation in y direction.

Can be overwritten. Here, tailored to FluidFlower scenarios, fix
the displacement in y-direction at the horizontal boundaries of the
image.
deduct_translation_analysis(translation_analysis)[source]#

Overwrite translation analysis by deducting from external one. (Re)defines the interpolation object.

Parameters:
translation_analysisdarsia.TranslationAnalysis

Translation analysis holding an interpolation object.

find_translation(units=['pixel', 'pixel'])[source]#

Find translation map as translation from image to baseline image such that these match as best as possible, measure on features.

The final translation map will be stored as callable function. And it allows various input and output spaces (metric vs. pixel).

Parameters:
unitslist of str

Units for input (first entry) and output (second entry) ranges of the resulting translation map; accepts either “metric” or “pixel”.

Returns:
Callable

Translation map defined as interpolator.

bool

Flag indicating on which patches the routine has been successful.

load_image(img, mask=None)[source]#

Load an image to be inspected in futher analysis.

Parameters:
imgImage

Test image.

maskImage

Mask to be considered in the analysis.

plot_translation(reverse=True, scaling=1.0, mask=None)[source]#

Translate centers of the test image and plot in terms of displacement arrows.

Parameters:
reversebool

Flag whether the translation is understood as from the test image to the baseline image, or reversed. The default is the former latter.

scalingfloat

Scaling factor for visual comfort.

maskImage

Mask of interest for arrows.

return_patch_translation(reverse=True, units='metric')[source]#

Translate patch centers of the test image.

Parameters:
reversebool

Flag whether the translation is understood as from the test image to the baseline image, or reversed. The default is the former latter.

unitslist of str

“metric” or “pixel”.

Returns:
np.ndarray

Deformation in patch centers.

translate_image(reverse=True)[source]#

Apply translation to an entire image by using piecwise perspective transformation.

Parameters:
reversebool

Flag whether the translation is understood as from the test image to the baseline image, or reversed. The default is the latter.

Returns:
darsia.Image

Translated image.

update_base(base)[source]#

Update baseline image.

Parameters:
basedarsia.Image

Baseline image.

update_base_patches()[source]#

Update patches of baseline.

update_params(N_patches=None, rel_overlap=None)[source]#

Routine allowing to update parameters for creating patches.

If any of the parameters is changed, a new patch of the base image is created.

Parameters:
N_patcheslist of two int

Number of patches in x and y direction.

rel_overlapfloat

Relative overal related to patch size in each direction.

N_patches#

Number of patches in matrix indexing.

have_translation#

Mask of flags storing success of finding translations for patches.

mask_base#

Mask.

rel_overlap#

Relative overlap.

translation#

Cache of current translation.

translation_estimator#

Translation estimator.