Skip to content

Options

Interpolation specific options are handled via an instance of InterpolationPolicy. Default options can be obtained via

from static_interpolation.config import InterpolationPolicy
policy = InterpolationPolicy()
Currently selected options are stored as lower case attributes, e.g.
policy.method
The possible values of an option are accessible via uppercase attributes, e.g.
policy.Method.linear
policy.Method.cubic
policy.Method.area
# or equivalently
InterpolationPolicy.Method.linear
InterpolationPolicy.Method.cubic
InterpolationPolicy.Method.area

Method

Defines the interpolation type.

  • Methond.linear: Bilinear interpolation
  • Methond.cubic: (default) Bicubic (Catmull-Rom) interpolation with \(\alpha = 0.5\)
  • Methond.area: New pixels are quads overlaying the original pixel grid. The value in each quad is the area weighted average of all original pixels that overlay this quad.
Image 1 Image 2
Image 3
Shows the data points or pixel areas used to compute the value at the orange dot (or orange quadrilateral for area remapping). Used pixels or areas are shaded blue, and their centers are marked with black dots.

Boundary

All sampling points that lie outside of the underlying data range(pixel grid) are ignored.
Sampling points which lie inside the data range but whose kernel contains points outside of it are affected by the following options.

Image 1

Example of a sampling point whose kernel crosses the data boundary. Read shaded areas lie outside of the data range (pixel grid) but are needed to interpolate the orange sample.
  • Boundary.reject: Do not interpolate samples for which data points outside the data range is needed.
  • Boundary.extrapolate_nearest: Data values outside of the data range are are filled by the value of the nearest pixel.
  • Boundary.extrapolate_linear: (default) Data values outside of the data range are are filled by linear extrapolation from the nearest points in the data range.

Masking

This option specifies how masked data points(pixels) should be treated.

  • Masking.Strict(): (default) A Sampling point is considered masked if any of the data points needed for its interpolation is masked. E.g. for cubic(linear) interpolation this means that an output sample point is masked, if any of its nearest 4x4 (2x2) pixel values on the detector is masked.
  • Masking.Renormalize(max_masked_area:float): Compute the value of a sampling point by renormalizing the weights using only unmasked pixels, provided that the masked fraction of used pixel does notexceed max_masked_area (0 = nothing masked; 1 = entirely masked). For linear and cubic interpolation, the fraction is calculated over their respective stencils: 4 pixels for linear and 16 for cubic interpolation. For the area method the exactly computed relative areas of overlapping pixels are used.
    max_masked_area: is a float in the intervall [0,1) (default=1/3), specifying the maximal allowed relative masked output pixel area.

  • Masking.MeanFill(max_masked:int,mask_nearest:bool): Try to fill in masked data values by taking the mean of the 8 surrounding pixels.
    max_masked: is an integer in 1,…,7 (default=3), specifying how many surrounding pixels are at most allowed to be masked.
    mask_nearest: is a boolean flag (default=True). If it is set, then sampling points whose nearest data point is masked (before trying to fill their values) are always masked as well.

Image 1

Consider the center red pixel to be masked. MeanFill tries to fill the masked value by taking the mean of its 8 surrounding pixels (blue area). It only does so if less or equal to max_masked of the blue pixels are masked as well.

OverlapMode

If there are n image panels e.g.
layout = ImageLayout(n_panels=n,num_x=6,num_y=4)
then each sampling point has to be defined in pixel coordinates of each of the n panels. E.g. consider m sampling points, then the sampling grid shape has to be (n,m,2).

It can happen that one of the m sampling points lies in the data range of more than one of the n panels. This is a problem since then there is no unique association between the underlying data and this sampling point, which means that there is more than one possible interpolation result.

This option specifies what to do in such a case.

  • OverlapMode.error: (default) Raises a ValueException if SamplingGrid contains points that lie in the data range of more than one panel.
  • OverlapMode.first: Use the "first" data panel (by panel id) in whose data range a given sample point lies.