Validator¶
-
class
imgreg.models.validator.solver.
Validator
(img: Optional[numpy.ndarray] = None, ref_img: Optional[numpy.ndarray] = None)[source]¶ Implements a validator model for image comparison.
- Parameters
- imgnumpy.ndarray
The input image (one color channel only).
- ref_imgnumpy.ndarray
The reference image (one color channel only).
Notes
The model implements the following dependency graph to construct it’s Parameters.
The Parameters are documented in params.
Examples
We can visualize the internal ImageParameters of the model as follows:
import numpy as np import imgreg.data as data from imgreg.models.validator import Validator from imgreg.util.methods import ImageMethods ref_img = np.array(data.ref_img()) # modify the image using an affine transformation img = ImageMethods.compute_rts(ref_img, angle=2, translation=(6, 2)) # Create the model: val = Validator(img, ref_img) # The ImageParameters of the model have matplotlib support via the display function: val.display([val.ABSOLUTE_DIFFERENCE_IMG, val.SQUARED_DIFFERENCE_IMG]) # Increase the overlap to the reference image val.IMG.value = ImageMethods.compute_rts(ref_img, angle=1, translation=(1, 2)) # Note how the difference images show less pronounced differences with increased overlap val.display([val.ABSOLUTE_DIFFERENCE_IMG, val.SQUARED_DIFFERENCE_IMG])
If we simply want to create a model and access the recovered values we first setup a model:
>>> import numpy as np >>> import imgreg.data as data >>> from imgreg.models.validator import Validator >>> from imgreg.util.methods import ImageMethods >>> ref_img = np.array(data.ref_img()) >>> img = ImageMethods.compute_rts(ref_img, angle=2, translation=(6,2)) >>> val = Validator(img, ref_img)
Calculate the relative norm of difference between the images.
>>> val.NORM_REL_L2.value 0.4875079942792...
Note how this value approaches zero, as the image increase in their overlap:
>>> val.IMG.value = ImageMethods.compute_rts(ref_img, angle=1, translation=(1,2)) >>> val[ValidatorParams.NORM_REL_L2].value 0.3942652180108...
Methods
__init__
([img, ref_img])Initialize self.
display
(param_list[, title])Fancy plot functionality for registered ImageParameters.
dot_graph
([node_args_func])Return a dot graph representation of the solver model.