darsia.CurvatureCorrection#
- class CurvatureCorrection(config=None, **kwargs)[source]#
Bases:
BaseCorrectionPolynomial curvature correction.
Contains routines for setting up the curvature correction, as well as applying it to images.
- Attributes:
- config
dict Config dictionary for curvture correction.
Circumstantial attributes: reference_image (np.ndarray): image matrix of the reference image. current_image (np.ndarray): image matrix of the updated reference image. width (float): physical width of reference image. height (float): physical height of reference image. in_meters (bool): True if width/height is in meters. Ny (int): number of pixels in vertical direction in reference image. Nx (int): number of pixels in horizontal direction in reference image.
- config
Set up the curvature correction.
Normally initialised from a config file that controls the correction routine. Initialising from an image path (not a
darsia.Image) is only meant for building the config file interactively.- Parameters:
- **kwargs
Either
configorimagemust be given:config (dict | str | Path) config dictionary (default None) image (Path | np.ndarray) image source, as a path or an array width (float) physical image width (image mode) height (float) physical image height (image mode) in_meters (bool) whether width/height are in metres (image mode)
Methods
bulge_correction([left, right, top, bottom])Bulge correction
compute_bulge([img])Compute the bulge parameters depending on the maximum number of pixels that the image has been displaced on each side.
compute_stretch([img])Compute the stretch parameters depending on the stretch center, and a known translation.
correct_array(img)Call method of the curvature correction.
correct_metadata([metadata])Extract metadata from the config file.
load(path)Load the curvature correction from a file.
pre_bulge_correction(**kwargs)Force all straight lines to curve inwards rather than outwards.
read_config_from_file(path)Reads a json-file to the config disctionary.
Returns the current image as a darsia image width provided width and height.
save(path)Save the curvature correction to a file.
setup_config([config])Shows the current image using matplotlib.pyplot
simple_curvature_correction(img, **kwargs)General routine for applying stretch and bulge transforms.
stretch_correction(point_source, ...)Stretch the image from the displacement of a single point.
write_config_to_file(path)Writes the config dictionary to a json-file.
Attributes
temporary_image- bulge_correction(left=0, right=0, top=0, bottom=0)[source]#
Bulge correction
Corrects bulging of image, depending on the amount of pixels that the image is bulged inwards on each side.
- compute_bulge(img=None, **kwargs)[source]#
Compute the bulge parameters depending on the maximum number of pixels that the image has been displaced on each side.
- Parameters:
- img
np.ndarray,optional Image array, basis for the computation.
- **kwargs
optionalkeywordarguments “left” (int): the maximum number of pixels that the image has been displaced on the left side “right” (int): the maximum number of pixels that the image has been displaced on the right side “top” (int): the maximum number of pixels that the image has been displaced on the top “bottom” (int): the maximum number of pixels that the image has been displaced on the bottom.
- img
- compute_stretch(img=None, **kwargs)[source]#
Compute the stretch parameters depending on the stretch center, and a known translation.
- Parameters:
- img
np.ndarray,optional Image array, basis for the computation.
- **kwargs
optionalkeywordarguments “point_source” (list): point that has been translated. “point_destination” (list): the ought to be position. “stretch_center” (list): the stretch center.
- img
- correct_array(img)[source]#
Call method of the curvature correction.
Applies the curvature correction to a provided image, and returns the corrected image as an array. If set in the constructor, the image will be resized in the first step.
- Parameters:
- img
np.ndarray Image array.
- img
- Returns:
np.ndarrayCurvature corrected image.
- load(path)[source]#
Load the curvature correction from a file.
- Parameters:
- path
Path Path to the file.
- path
- pre_bulge_correction(**kwargs)[source]#
Force all straight lines to curve inwards rather than outwards.
- Parameters:
- **kwargs
Curvature parameters:
horizontal_bulge (float) horizontal bulge horizontal_center_offset (int) x offset of the image centre from the numerical centre, px vertical_bulge (float) vertical bulge vertical_center_offset (int) y offset of the image centre from the numerical centre, px
- read_config_from_file(path)[source]#
Reads a json-file to the config disctionary.
- Parameters:
- path
Path Path to the json-file.
- path
- return_image()[source]#
Returns the current image as a darsia image width provided width and height.
- simple_curvature_correction(img, **kwargs)[source]#
General routine for applying stretch and bulge transforms. This routine in contrast to __call__ does always use the keyword arguments and constructs the transformation instead of using cached values.
- Parameters:
- img
np.ndarray Image array.
- **kwargs
optionalkeywordarguments See _transform_coordinates for more details.
- img
- Returns:
np.ndarrayCorrected image.