2.3. distoptica.DistortionModel
- class DistortionModel(coord_transform_params=None, sampling_grid_dims_in_pixels=(512, 512), device_name=None, least_squares_alg_params=None, skip_validation_and_conversion=False)[source]
Bases:
PreSerializableAndUpdatable
An optical distortion model.
To begin our discussion on optical distortion models, let us consider two thought experiments. First, let \(E_{\square}\) denote an imaging experiment of a sample wherein the imaging aparatus is operating at a fixed set of target parameters, and all the optical elements used in the imaging aparatus are idealized in the sense that they do not introduce any optical distortions. Secondly, let \(E_{⌑}\) denote an imaging experiment that is identical to \(E_{\square}\) except that the optical elements used in the imaging aparatus possess imperfections in the sense that they introduce a particular set of optical distortions. We will refer to the set of images resulting from the imaging experiment \(E_{\square}\) as the set of undistorted images, and the set of images resulting from the imaging experiment \(E_{⌑}\) as the set of distorted images.
We assume that the images resulting from both imaging experiments are formed at a common image plane, that each experiment yields the same number of images \(N_{\mathcal{I}}\), that all images have the same number of channels \(N_{\mathcal{I};C}\), and that all images are of the same spatial dimensions, i.e. they have the same dimensions in pixels with the same pixel sizes. Let \(N_{\mathcal{I};x}\) and \(N_{\mathcal{I};y}\) be the number of pixels in either image from left to right and top to bottom respectively.
For simplicity, we describe positions within images using fractional coordinates. First, let \(u_{x}\) and \(u_{y}\) be the fractional horizontal and vertical coordinates, respectively, of a point in an undistorted image, where \(\left(u_{x},u_{y}\right)=\left(0,0\right)\) is the bottom left corner of the image. Secondly, let \(q_{x}\) and \(q_{y}\) be the fractional horizontal and vertical coordinates, respectively, of a point in a distorted image, where \(\left(q_{x},q_{y}\right)=\left(0,0\right)\) is the bottom left corner of the image.
The optical distortions introduced by experiment \(E_{⌑}\) can be described by a coordinate transformation, which maps a given coordinate pair \(\left(u_{x},u_{y}\right)\) to a corresponding coordinate pair \(\left(q_{x},q_{y}\right)\). Let \(T_{⌑;x}\left(u_{x},u_{y}\right)\) be the component of the coordinate transformation that maps \(\left(u_{x},u_{y}\right)\) to its corresponding \(q_{x}\), and let \(T_{⌑;y}\left(u_{x},u_{y}\right)\) be the component of the coordinate transformation that maps \(\left(u_{x},u_{y}\right)\) to its corresponding \(q_{y}\). See the documentation for the class
distoptica.CoordTransformParams
for a mathematical description of \(T_{⌑;x}\left(u_{x},u_{y}\right)\) and \(T_{⌑;y}\left(u_{x},u_{y}\right)\).We assume that there exists a right inverse to the coordinate transformation, i.e. that there are functions \(T_{\square;x}\left(q_{x},q_{y}\right)\) and \(T_{\square;y}\left(q_{x},q_{y}\right)\) satisfying:
(2.3.1)\[T_{⌑;x}\left(u_{x}=T_{\square;x}\left(q_{x},q_{y}\right),u_{y}= T_{\square;y}\left(q_{x},q_{y}\right)\right)\equiv q_{x},\](2.3.2)\[T_{⌑;y}\left(u_{x}=T_{\square;x}\left(q_{x},q_{y}\right),u_{y}= T_{\square;y}\left(q_{x},q_{y}\right)\right)\equiv q_{y},\]In other words, \(T_{\square;x}\left(q_{x},q_{y}\right)\) maps \(\left(q_{x},q_{y}\right)\) to its corresponding \(u_{x}\), and \(T_{\square;y}\left(q_{x},q_{y}\right)\) maps \(\left(q_{x},q_{y}\right)\) to its corresponding \(u_{y}\), when \(\left(T_{\square;x}\left(q_{x},q_{y}\right), T_{\square;y}\left(q_{x},q_{y}\right)\right)\) is well-defined at \(\left(q_{x},q_{y}\right)\). See the documentation for the class
distoptica.LeastSquaresAlgParams
for a discussion on how \(T_{\square;x}\left(q_{x},q_{y}\right)\) and \(T_{\square;y}\left(q_{x},q_{y}\right)\) are calculated.One of the primary purposes of the class
distoptica.DistortionModel
is to distort undistorted images or to undistort distorted images, given a coordinate transformation \(\left(T_{⌑;x}\left(u_{x},u_{y}\right), T_{⌑;x}\left(u_{x},u_{y}\right)\right)\), and then subsequently resample the transformed images. To describe howdistoptica.DistortionModel
approximates the aforementioned images transformations and resampling, it is worth introducing several mathematical objects. First, let \(\mathcal{I}_{\square;l,k,n,m}\) be the value of the pixel centered at \(\left(u_{x},u_{y}\right)= \left(u_{\mathcal{I};x;m},u_{\mathcal{I};y;n}\right)\) in the \(k^{\text{th}}\) channel of the \(l^{\text{th}}\) undistorted image, where(2.3.3)\[l\in\left\{ l^{\prime}\right\} _{l^{\prime}=0}^{N_{\mathcal{I}}-1},\](2.3.4)\[k\in\left\{ k^{\prime}\right\} _{k^{\prime}=0}^{N_{\mathcal{I};C}-1},\](2.3.5)\[m\in\left\{ m^{\prime}\right\} _{m^{\prime}=0}^{N_{\mathcal{I};x}-1},\](2.3.6)\[n\in\left\{ n^{\prime}\right\} _{n^{\prime}=0}^{N_{\mathcal{I};y}-1},\](2.3.7)\[u_{\mathcal{I};x;m}=\left(m+\frac{1}{2}\right)\Delta u_{\mathcal{I};x},\](2.3.8)\[u_{\mathcal{I};y;n}=1-\left(n+\frac{1}{2}\right) \Delta u_{\mathcal{I};y},\](2.3.9)\[\Delta u_{\mathcal{I};x}=\frac{1}{N_{\mathcal{I};x}},\](2.3.10)\[\Delta u_{\mathcal{I};y}=\frac{1}{N_{\mathcal{I};y}},\]Next, let \(\mathcal{I}_{⌑;l,k,n,m}\) be the value of the pixel centered at \(\left(q_{x},q_{y}\right)= \left(q_{\mathcal{I};x;m},q_{\mathcal{I};y;n}\right)\) in the \(k^{\text{th}}\) channel of the \(l^{\text{th}}\) distorted image, where
(2.3.11)\[q_{\mathcal{I};x;m}=\left(m+\frac{1}{2}\right)\Delta q_{\mathcal{I};x},\](2.3.12)\[q_{\mathcal{I};y;n}= 1-\left(n+\frac{1}{2}\right)\Delta q_{\mathcal{I};y},\](2.3.13)\[\Delta q_{\mathcal{I};x}=\frac{1}{N_{\mathcal{I};x}},\](2.3.14)\[\Delta q_{\mathcal{I};y}=\frac{1}{N_{\mathcal{I};y}}.\]Next, let \(\check{\mathcal{I}}_{\square;l,k}\left(u_{x},u_{y}\right)\) be the interpolation of the \(k^{\text{th}}\) channel of the \(l^{\text{th}}\) undistorted image at \(\left(u_{x},u_{y}\right)\). Next, let \(\check{\mathcal{I}}_{⌑;l,k}\left(q_{x},q_{y}\right)\) be the interpolation of the \(k^{\text{th}}\) channel of the \(l^{\text{th}}\) distorted image at \(\left(q_{x},q_{y}\right)\). Next, let \(\mathring{\mathcal{I}}_{\square;l,k,i,j}\) be the value of the pixel centered at \(\left(u_{x},u_{y}\right)= \left(u_{\mathring{\mathcal{I}};x;j},u_{\mathring{\mathcal{I}};y;i}\right)\) in the \(k^{\text{th}}\) channel of the \(l^{\text{th}}\) resampled undistorted image, where
(2.3.15)\[j\in\left\{ j^{\prime}\right\}_{j^{\prime}=0}^{ N_{\mathcal{\mathring{I}};x}-1},\](2.3.16)\[i\in\left\{ i^{\prime}\right\}_{i^{\prime}=0}^{ N_{\mathcal{\mathring{I}};y}-1},\](2.3.17)\[u_{\mathcal{\mathring{I}};x;j}=\left(j+\frac{1}{2}\right) \Delta u_{\mathcal{\mathring{I}};x},\](2.3.18)\[u_{\mathcal{\mathring{I}};y;i}=1-\left(i+\frac{1}{2}\right) \Delta u_{\mathcal{\mathring{I}};y},\](2.3.19)\[\Delta u_{\mathcal{\mathring{I}};x}= \frac{1}{N_{\mathcal{\mathring{I}};x}},\](2.3.20)\[\Delta u_{\mathcal{\mathring{I}};y}= \frac{1}{N_{\mathcal{\mathring{I}};y}},\]and \(N_{\mathcal{\mathring{I}};x}\) and \(N_{\mathcal{\mathring{I}};y}\) are the number of pixels in the sampling grid from left to right and top to bottom respectively. Next, let \(\mathring{\mathcal{I}}_{⌑;l,k,i,j}\) be the value of the pixel centered at \(\left(q_{x},q_{y}\right)= \left(q_{\mathring{\mathcal{I}};x;j},q_{\mathring{\mathcal{I}};y;i}\right)\) in the \(k^{\text{th}}\) channel of the \(l^{\text{th}}\) resampled distorted image, where
(2.3.21)\[q_{\mathcal{\mathring{I}};x;j}=\left(j+\frac{1}{2}\right) \Delta q_{\mathcal{\mathring{I}};x},\](2.3.22)\[q_{\mathcal{\mathring{I}};y;i}=1-\left(i+\frac{1}{2}\right) \Delta q_{\mathcal{\mathring{I}};y},\](2.3.23)\[\Delta q_{\mathcal{\mathring{I}};x}= \frac{1}{N_{\mathcal{\mathring{I}};x}},\](2.3.24)\[\Delta q_{\mathcal{\mathring{I}};y}= \frac{1}{N_{\mathcal{\mathring{I}};y}}.\]Next, let \(\mathbf{J}_{⌑}\left(u_{x},u_{y}\right)\) be the Jacobian of \(\left(T_{⌑;x}\left(u_{x},u_{y}\right), T_{⌑;x}\left(u_{x},u_{y}\right)\right)\):
(2.3.25)\[\begin{split}\mathbf{J}_{⌑}\left(u_{x},u_{y}\right)= \begin{pmatrix}\frac{\partial T_{⌑;x}}{\partial u_{x}} & \frac{\partial T_{⌑;x}}{\partial u_{y}}\\ \frac{\partial T_{⌑;y}}{\partial u_{x}} & \frac{\partial T_{⌑;y}}{\partial u_{y}} \end{pmatrix}.\end{split}\]Lastly, let \(\mathbf{J}_{\square}\left(q_{x},q_{y}\right)\) be the Jacobian of \(\left(T_{\square;x}\left(q_{x},q_{y}\right), T_{\square;x}\left(q_{x},q_{y}\right)\right)\):
(2.3.26)\[\begin{split}\mathbf{J}_{\square}\left(q_{x},q_{y}\right)= \begin{pmatrix}\frac{\partial T_{\square;x}}{\partial q_{x}} & \frac{\partial T_{\square;x}}{\partial q_{y}}\\ \frac{\partial T_{\square;y}}{\partial q_{x}} & \frac{\partial T_{\square;y}}{\partial q_{y}} \end{pmatrix}.\end{split}\]The same class, via the method
undistort_then_resample_images()
, approximates undistorting then resampling images by:(2.3.27)\[\begin{split}\mathring{\mathcal{I}}_{\square;l,k,i,j}&\approx \frac{N_{\mathcal{I};x}N_{\mathcal{I};y}}{N_{\mathring{\mathcal{I}};x} N_{\mathring{\mathcal{I}};y}} \left|\text{det}\left(\mathbf{J}_{⌑}\left(u_{\mathring{\mathcal{I}}; x;j},u_{\mathring{\mathcal{I}};y;i}\right)\right)\right|\\ &\hphantom{\approx}\quad\times\check{\mathcal{I}}_{⌑;l,k}\left( T_{⌑;x}\left(u_{\mathring{\mathcal{I}};x;j}, u_{\mathring{\mathcal{I}};y;i}\right),T_{⌑;y}\left( u_{\mathring{\mathcal{I}};x;j}, u_{\mathring{\mathcal{I}};y;i}\right)\right),\end{split}\]where \(\mathbf{J}_{⌑}\left(u_{\mathring{\mathcal{I}};x;j}, u_{\mathring{\mathcal{I}};y;i}\right)\) is calculated via Eq. (2.3.25), with the derivatives being calculated analytically.
The class
distoptica.DistortionModel
, via the methoddistort_then_resample_images()
, approximates distorting then resampling images by:(2.3.28)\[\begin{split}\mathring{\mathcal{I}}_{⌑;l,k,i,j}&\approx \frac{N_{\mathcal{I};x}N_{\mathcal{I};y}}{ N_{\mathring{\mathcal{I}};x}N_{\mathring{\mathcal{I}};y}}\left| \text{det}\left(\mathbf{J}_{\square}\left( q_{\mathring{\mathcal{I}};x;j}, q_{\mathring{\mathcal{I}};y;i}\right)\right)\right|\\ &\hphantom{\approx}\quad\times\check{\mathcal{I}}_{\square;l,k}\left( T_{\square;x}\left(q_{\mathring{\mathcal{I}};x;j}, q_{\mathring{\mathcal{I}};y;i}\right),T_{\square;y}\left( q_{\mathring{\mathcal{I}};x;j}, q_{\mathring{\mathcal{I}};y;i}\right)\right),\end{split}\]where \(\mathbf{J}_{\square}\left(q_{\mathring{\mathcal{I}};x;j}, q_{\mathring{\mathcal{I}};y;i}\right)\) is calculated via Eq. (2.3.26), with the derivatives being calculated numerically using the second-order accurate central differences method.
- Parameters:
- coord_transform_params
distoptica.CoordTransformParams
| None, optional If
coord_transform_params
is set toNone
, then the coordinate transformation \(\left(T_{⌑;x}\left(u_{x},u_{y}\right), T_{⌑;y}\left(u_{x},u_{y}\right)\right)\) to be used is the identity transformation. Otherwise,coord_transform_params
specifies the parameters of the coordinate transformation to be used.- sampling_grid_dims_in_pixelsarray_like (int, shape=(2,)), optional
The dimensions of the sampling grid, in units of pixels:
sampling_grid_dims_in_pixels[0]
andsampling_grid_dims_in_pixels[1]
are \(N_{\mathring{\mathcal{I}};x}\) and \(N_{\mathring{\mathcal{I}};y}\) respectively.- device_namestr | None, optional
This parameter specifies the device to be used to perform computationally intensive calls to PyTorch functions and where to store attributes of the type
torch.Tensor
. Ifdevice_name
is a string, then it is the name of the device to be used, e.g.”cuda”
or”cpu”
. Ifdevice_name
is set toNone
and a GPU device is available, then a GPU device is to be used. Otherwise, the CPU is used.- least_squares_alg_params
distoptica.LeastSquaresAlgParams
| None, optional If
least_squares_alg_params
is set toNone
, then the parameters of the least-squares algorithm to be used to calculate \(\left(T_{\square;x}\left(q_{x},q_{y}\right), T_{\square;y}\left(q_{x},q_{y}\right)\right)\) are those specified bydistoptica.LeastSquaresAlgParams()
. Otherwise,least_squares_alg_params
specifies the parameters of the least-squares algorithm to be used.- skip_validation_and_conversionbool, optional
Let
validation_and_conversion_funcs
andcore_attrs
denote the attributesvalidation_and_conversion_funcs
andcore_attrs
respectively, both of which being dict objects.Let
params_to_be_mapped_to_core_attrs
denote the dict representation of the constructor parameters excluding the parameterskip_validation_and_conversion
, where each dict keykey
is a different constructor parameter name, excluding the name"skip_validation_and_conversion"
, andparams_to_be_mapped_to_core_attrs[key]
would yield the value of the constructor parameter with the name given bykey
.If
skip_validation_and_conversion
is set toFalse
, then for each keykey
inparams_to_be_mapped_to_core_attrs
,core_attrs[key]
is set tovalidation_and_conversion_funcs[key] (params_to_be_mapped_to_core_attrs)
.Otherwise, if
skip_validation_and_conversion
is set toTrue
, thencore_attrs
is set toparams_to_be_mapped_to_core_attrs.copy()
. This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofparams_to_be_mapped_to_core_attrs
, as it is guaranteed that no copies or conversions are made in this case.
- coord_transform_params
- Attributes:
convergence_map_of_distorted_then_resampled_images
torch.Tensor: The convergence map of the iterative algorithm used
core_attrs
dict: The “core attributes”.
de_pre_serialization_funcs
dict: The de-pre-serialization functions.
device
torch.device: The device on which computationally intensive
flow_field_of_coord_transform
array_like: The flow field of the coordinate transformation
flow_field_of_coord_transform_right_inverse
array_like: The flow field of the right-inverse of the coordinate
is_azimuthally_symmetric
bool: A boolean variable indicating whether the distortion model
is_standard
bool: A boolean variable indicating whether the distortion model
is_trivial
bool: A boolean variable indicating whether the distortion model
mask_frame_of_distorted_then_resampled_images
array_like: The minimum frame to mask all boolean values of
out_of_bounds_map_of_distorted_then_resampled_images
torch.Tensor: The out-of-bounds map of distorted then resampled
out_of_bounds_map_of_undistorted_then_resampled_images
torch.Tensor: The out-of-bounds map of undistorted then resampled
pre_serialization_funcs
dict: The pre-serialization functions.
sampling_grid
array_like: The fractional coordinates of the sampling grid.
validation_and_conversion_funcs
dict: The validation and conversion functions.
Methods
de_pre_serialize
([serializable_rep, ...])Construct an instance from a serializable representation.
distort_then_resample_images
([...])Distort then resample a 1D stack of undistorted images.
dump
([filename, overwrite])Serialize instance and save the result in a JSON file.
dumps
()Serialize instance.
Execute the sequence of actions that follows immediately after updating the core attributes.
get_convergence_map_of_distorted_then_resampled_images
([...])Return the convergence map of the iterative algorithm used to distort then resample images.
get_core_attrs
([deep_copy])Return the core attributes.
Return the de-pre-serialization functions.
get_flow_field_of_coord_transform
([deep_copy])Return the flow field of the coordinate transformation corresponding to the distortion model.
Return the flow field of the right-inverse of the coordinate transformation corresponding to the distortion model.
get_out_of_bounds_map_of_distorted_then_resampled_images
([...])Return the out-of-bounds map of distorted then resampled images.
get_out_of_bounds_map_of_undistorted_then_resampled_images
([...])Return the out-of-bounds map of undistorted then resampled images.
Return the pre-serialization functions.
get_sampling_grid
([deep_copy])Return the fractional coordinates of the sampling grid.
Return the validation and conversion functions.
load
([filename, skip_validation_and_conversion])Construct an instance from a serialized representation that is stored in a JSON file.
loads
([serialized_rep, ...])Construct an instance from a serialized representation.
Pre-serialize instance.
Undistort and resample a 1D stack of distorted images.
update
(new_core_attr_subset_candidate[, ...])Update a subset of the core attributes.
Methods
Construct an instance from a serializable representation.
Distort then resample a 1D stack of undistorted images.
Serialize instance and save the result in a JSON file.
Serialize instance.
Execute the sequence of actions that follows immediately after updating the core attributes.
Return the convergence map of the iterative algorithm used to distort then resample images.
Return the core attributes.
Return the de-pre-serialization functions.
Return the flow field of the coordinate transformation corresponding to the distortion model.
Return the flow field of the right-inverse of the coordinate transformation corresponding to the distortion model.
Return the out-of-bounds map of distorted then resampled images.
Return the out-of-bounds map of undistorted then resampled images.
Return the pre-serialization functions.
Return the fractional coordinates of the sampling grid.
Return the validation and conversion functions.
Construct an instance from a serialized representation that is stored in a JSON file.
Construct an instance from a serialized representation.
Pre-serialize instance.
Undistort and resample a 1D stack of distorted images.
Update a subset of the core attributes.
Attributes
torch.Tensor: The convergence map of the iterative algorithm used to distort then resample images.
dict: The "core attributes".
dict: The de-pre-serialization functions.
torch.device: The device on which computationally intensive PyTorch operations are performed and attributes of the type
torch.Tensor
are stored.array_like: The flow field of the coordinate transformation corresponding to the distortion model.
array_like: The flow field of the right-inverse of the coordinate transformation corresponding to the distortion model.
bool: A boolean variable indicating whether the distortion model is azimuthally symmetric.
bool: A boolean variable indicating whether the distortion model is standard.
bool: A boolean variable indicating whether the distortion model is trivial.
array_like: The minimum frame to mask all boolean values of
False
in the attributedistoptica.DistortionModel.convergence_map_of_distorted_then_resampled_images
.torch.Tensor: The out-of-bounds map of distorted then resampled images.
torch.Tensor: The out-of-bounds map of undistorted then resampled images.
dict: The pre-serialization functions.
array_like: The fractional coordinates of the sampling grid.
dict: The validation and conversion functions.
- property convergence_map_of_distorted_then_resampled_images
torch.Tensor: The convergence map of the iterative algorithm used to distort then resample images.
See the documentation for the method
distoptica.DistortionModel.distort_then_resample_images()
for additional context.convergence_map_of_distorted_then_resampled_images
is a PyTorch tensor having a shape equal to \(\left(N_{\mathring{\mathcal{I}};y}, N_{\mathring{\mathcal{I}};x}\right)\), where \(N_{\mathring{\mathcal{I}};x}\) and \(N_{\mathring{\mathcal{I}};y}\) being the number of pixels in the sampling grid from left to right and top to bottom respectively.Let
distorted_then_resampled_images
denote the output of a call to the methoddistoptica.DistortionModel.distort_then_resample_images()
.For every row index
i
and column indexj
,convergence_map_of_distorted_then_resampled_images[i, j]
evaluates toFalse
if the iterative algorithm used to calculatedistorted_images
does not converge within the error tolerance for elementsdistorted_images[:, :, i, j]
, and evaluates toTrue
otherwise.Note that
convergence_map_of_distorted_then_resampled_images
should be considered read-only.
- property core_attrs
dict: The “core attributes”.
The keys of
core_attrs
are the same as the attributevalidation_and_conversion_funcs
, which is also a dict object.Note that
core_attrs
should be considered read-only.
- property de_pre_serialization_funcs
dict: The de-pre-serialization functions.
de_pre_serialization_funcs
has the same keys as the attributevalidation_and_conversion_funcs
, which is also a dict object.Let
validation_and_conversion_funcs
andpre_serialization_funcs
denote the attributesvalidation_and_conversion_funcs
pre_serialization_funcs
respectively, the last of which being a dict object as well.Let
core_attrs_candidate_1
be any dict object that has the same keys asvalidation_and_conversion_funcs
, where for each dict keykey
incore_attrs_candidate_1
,validation_and_conversion_funcs[key](core_attrs_candidate_1)
does not raise an exception.Let
serializable_rep
be a dict object that has the same keys ascore_attrs_candidate_1
, where for each dict keykey
incore_attrs_candidate_1
,serializable_rep[key]
is set topre_serialization_funcs[key](core_attrs_candidate_1[key])
.The items of
de_pre_serialization_funcs
are expected to be set to callable objects that would lead tode_pre_serialization_funcs[key](serializable_rep[key])
not raising an exception for each dict keykey
inserializable_rep
.Let
core_attrs_candidate_2
be a dict object that has the same keys asserializable_rep
, where for each dict keykey
invalidation_and_conversion_funcs
,core_attrs_candidate_2[key]
is set tode_pre_serialization_funcs[key](serializable_rep[key])
.The items of
de_pre_serialization_funcs
are also expected to be set to callable objects that would lead tovalidation_and_conversion_funcs[key](core_attrs_candidate_2)
not raising an exception for each dict keykey
incore_attrs_candidate_2
.Note that
de_pre_serialization_funcs
should be considered read-only.
- classmethod de_pre_serialize(serializable_rep={}, skip_validation_and_conversion=False)
Construct an instance from a serializable representation.
- Parameters:
- serializable_repdict, optional
A dict object that has the same keys as the attribute
validation_and_conversion_funcs
, which is also a dict object.Let
validation_and_conversion_funcs
andde_pre_serialization_funcs
denote the attributesvalidation_and_conversion_funcs
de_pre_serialization_funcs
respectively, the last of which being a dict object as well.The items of
serializable_rep
are expected to be objects that would lead tode_pre_serialization_funcs[key](serializable_rep[key])
not raising an exception for each dict keykey
inserializable_rep
.Let
core_attrs_candidate
be a dict object that has the same keys asserializable_rep
, where for each dict keykey
inserializable_rep
,core_attrs_candidate[key]
is set to de_pre_serialization_funcs[key](serializable_rep[key])``.The items of
serializable_rep
are also expected to be set to objects that would lead tovalidation_and_conversion_funcs[key](core_attrs_candidate)
not raising an exception for each dict keykey
inserializable_rep
.- skip_validation_and_conversionbool, optional
Let
core_attrs
denote the attributecore_attrs
, which is a dict object.If
skip_validation_and_conversion
is set toFalse
, then for each keykey
inserializable_rep
,core_attrs[key]
is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate)
, withvalidation_and_conversion_funcs
andcore_attrs_candidate_1
being introduced in the above description ofserializable_rep
.Otherwise, if
skip_validation_and_conversion
is set toTrue
, thencore_attrs
is set tocore_attrs_candidate.copy()
. This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofcore_attrs_candidate
, as it is guaranteed that no copies or conversions are made in this case.
- Returns:
- instance_of_current_clsCurrent class
An instance constructed from the serializable representation
serializable_rep
.
- property device
torch.device: The device on which computationally intensive PyTorch operations are performed and attributes of the type
torch.Tensor
are stored.Note that
device
should be considered read-only.
- distort_then_resample_images(undistorted_images=((0.0,),))[source]
Distort then resample a 1D stack of undistorted images.
See the summary documentation of the class
distoptica.DistortionModel
for additional context.Each undistorted image is distorted and subsequently resampled according to Eq. (2.3.28).
- Parameters:
- undistorted_imagesarray_like (float, ndim=2) | array_like (float, ndim=3) | array_like (float, ndim=4), optional
The undistorted images to be distorted and resampled. If
len(undistorted_images.shape)==4
, then for every quadruplet of nonnegative integers(l, k, n, m)
that does not raise anIndexError
exception upon callingundistorted_images[l, k, n, m]
,undistorted_images[l, k, n, m]
is interpreted to be the quantity \(\mathcal{I}_{\square;l,k,n,m}\), introduced in the summary documentation of the classdistoptica.DistortionModel
, with the integers \(l\), \(k\), \(n\), and \(m\) being equal to the values ofl
,k
,n
, andm
respectively, and the quadruplet of integers \(\left(N_{\mathcal{I}},N_{\mathcal{I};C},N_{\mathcal{I};y}, N_{\mathcal{I};x}\right)\), introduced in the summary documentation of the classdistoptica.DistortionModel
, being equal to the shape ofundistorted_images
. Iflen(undistorted_images.shape)==3
, then for every quadruplet of nonnegative integers(k, n, m)
that does not raise anIndexError
exception upon callingundistorted_images[k, n, m]
,undistorted_images[k, n, m]
is interpreted to be the quantity \(\mathcal{I}_{\square;0,k,n,m}\), with the integers \(k\), \(n\), and \(m\) being equal to the values ofk
,n
, andm
respectively, the triplet of integers \(\left(N_{\mathcal{I};C},N_{\mathcal{I};y}, N_{\mathcal{I};x}\right)\) being equal to the shape ofundistorted_images
, and \(N_{\mathcal{I}}\) being equal to unity. Otherwise, iflen(undistorted_images.shape)==2
, then for every pair of nonnegative integers(n, m)
that does not raise anIndexError
exception upon callingundistorted_images[n, m]
,undistorted_images[n, m]
is interpreted to be the quantity \(\mathcal{I}_{\square;0,0,n,m}\), with the integers \(n\) and \(m\) being equal to the values ofn
, andm
respectively, the pair of integers \(\left(N_{\mathcal{I};y},N_{\mathcal{I};x}\right)\) being equal to the shape ofundistorted_images
, and both \(N_{\mathcal{I}}\) and \(N_{\mathcal{I};C}\) being equal to unity.
- Returns:
- distorted_then_resampled_imagestorch.Tensor (float, ndim=4)
The images resulting from distorting then resampling the input image set. For every quadruplet of nonnegative integers
(l, k, i, j)
that does not raise anIndexError
exception upon callingdistorted_then_resampled_images[l, k, i, j]
,distorted_then_resampled_images[l, k, i, j]
is interpreted to be the quantity \(\mathring{\mathcal{I}}_{⌑;l,k,i,j}\), introduced in the summary documentation of the classdistoptica.DistortionModel
, with the integers \(l\), \(k\), \(i\), and \(j\) being equal to the values ofl
,k
,i
, andj
respectively, with the quadruplet of integers \(\left(N_{\mathcal{I}},N_{\mathcal{I};C}, N_{\mathring{\mathcal{I}};y},N_{\mathring{\mathcal{I}};x}\right)\), introduced in the summary documentation of the classdistoptica.DistortionModel
, being equal to the shape ofdistorted_then_resampled_images
.
- dump(filename='serialized_rep_of_fancytype.json', overwrite=False)
Serialize instance and save the result in a JSON file.
- Parameters:
- filenamestr, optional
The relative or absolute path to the JSON file in which to store the serialized representation of an instance.
- overwritebool, optional
If
overwrite
is set toFalse
and a file exists at the pathfilename
, then the serialized instance is not written to that file and an exception is raised. Otherwise, the serialized instance will be written to that file barring no other issues occur.
- Returns:
- dumps()
Serialize instance.
- Returns:
- serialized_repdict
A serialized representation of an instance.
- execute_post_core_attrs_update_actions()[source]
Execute the sequence of actions that follows immediately after updating the core attributes.
- property flow_field_of_coord_transform
array_like: The flow field of the coordinate transformation corresponding to the distortion model.
See the summary documentation of the class
distoptica.DistortionModel
for additional context.flow_field_of_coord_transform
is a 2-element tuple, whereflow_field_of_coord_transform[0]
andflow_field_of_coord_transform[1]
are PyTorch tensors, each having a shape equal to \(\left(N_{\mathring{\mathcal{I}};y}, N_{\mathring{\mathcal{I}};x}\right)\), with \(N_{\mathring{\mathcal{I}};x}\) and \(N_{\mathring{\mathcal{I}};y}\) being the number of pixels in the sampling grid from left to right and top to bottom respectively.For every pair of nonnegative integers
(i, j)
that does not raise anIndexError
exception upon callingflow_field_of_coord_transform[0, i, j]
,flow_field_of_coord_transform[0, i, j]
andflow_field_of_coord_transform[1, i, j]
are equal to the quantities(2.3.29)\[\Delta T_{⌑;x;i,j}= T_{⌑;x}\left(u_{\mathring{\mathcal{I}};x;j}, u_{\mathring{\mathcal{I}};y;i}\right) -u_{\mathring{\mathcal{I}};x;j},\]and
(2.3.30)\[\Delta T_{⌑;y;i,j}= T_{⌑;y}\left(u_{\mathring{\mathcal{I}};x;j}, u_{\mathring{\mathcal{I}};y;i}\right) -u_{\mathring{\mathcal{I}};y;j},\]respectively, with the integers \(i\) and \(j\) being equal to the values of
i
andj
respectively, \(u_{\mathcal{\mathring{I}};x;j}\) and \(u_{\mathcal{\mathring{I}};y;i}\) being given by Eqs. (2.3.17) and (2.3.18) respectively, and \(\left(T_{⌑;x}\left(u_{x},u_{y}\right), T_{⌑;x}\left(u_{x},u_{y}\right)\right)\) being the coordinate transformation corresponding to the distortion model.Note that
flow_field_of_coord_transform
should be considered read-only.
- property flow_field_of_coord_transform_right_inverse
array_like: The flow field of the right-inverse of the coordinate transformation corresponding to the distortion model.
flow_field_of_coord_transform_right_inverse
is a 2-element tuple, whereflow_field_of_coord_transform_right_inverse[0]
andflow_field_of_coord_transform_right_inverse[1]
are PyTorch tensors, each having a shape equal to \(\left(N_{\mathring{\mathcal{I}};y}, N_{\mathring{\mathcal{I}};x}\right)\), with \(N_{\mathring{\mathcal{I}};x}\) and \(N_{\mathring{\mathcal{I}};y}\) being the number of pixels in the sampling grid from left to right and top to bottom respectively.For every pair of nonnegative integers
(i, j)
that does not raise anIndexError
exception upon callingflow_field_of_coord_transform_right_inverse[0, i, j]
,flow_field_of_coord_transform_right_inverse[0, i, j]
andflow_field_of_coord_transform_right_inverse[1, i, j]
are equal to the quantities(2.3.31)\[\Delta T_{\square;x;i,j}= T_{\square;x}\left(q_{\mathring{\mathcal{I}};x;j}, q_{\mathring{\mathcal{I}};y;i}\right) -q_{\mathring{\mathcal{I}};x;j},\]and
(2.3.32)\[\Delta T_{\square;y;i,j}= T_{\square;y}\left(q_{\mathring{\mathcal{I}};x;j}, q_{\mathring{\mathcal{I}};y;i}\right) -q_{\mathring{\mathcal{I}};y;j},\]respectively, with the integers \(i\) and \(j\) being equal to the values of
i
andj
respectively, \(q_{\mathcal{\mathring{I}};x;j}\) and \(q_{\mathcal{\mathring{I}};y;i}\) being given by Eqs. (2.3.21) and (2.3.22) respectively, and \(\left(T_{\square;x}\left(q_{x},q_{y}\right), T_{\square;x}\left(q_{x},q_{y}\right)\right)\) being the right inverse of the coordinate transformation corresponding to the distortion model.Note that
flow_field_of_coord_transform_right_inverse
should be considered read-only.
- get_convergence_map_of_distorted_then_resampled_images(deep_copy=True)[source]
Return the convergence map of the iterative algorithm used to distort then resample images.
- Parameters:
- deep_copybool, optional
Let
convergence_map_of_distorted_then_resampled_images
denote the attributedistoptica.DistortionModel.convergence_map_of_distorted_then_resampled_images
.If
deep_copy
is set toTrue
, then a deep copy ofconvergence_map_of_distorted_then_resampled_images
is returned. Otherwise, a reference toconvergence_map_of_distorted_then_resampled_images
is returned.
- Returns:
- convergence_map_of_distorted_then_resampled_imagestorch.Tensor (bool, ndim=2)
The attribute
distoptica.DistortionModel.convergence_map_of_distorted_then_resampled_images
.
- get_core_attrs(deep_copy=True)
Return the core attributes.
- Parameters:
- deep_copybool, optional
Let
core_attrs
denote the attributecore_attrs
, which is a dict object.If
deep_copy
is set toTrue
, then a deep copy ofcore_attrs
is returned. Otherwise, a shallow copy ofcore_attrs
is returned.
- Returns:
- core_attrsdict
The attribute
core_attrs
.
- classmethod get_de_pre_serialization_funcs()[source]
Return the de-pre-serialization functions.
- Returns:
- de_pre_serialization_funcsdict
The attribute
de_pre_serialization_funcs
.
- get_flow_field_of_coord_transform(deep_copy=True)[source]
Return the flow field of the coordinate transformation corresponding to the distortion model.
- Parameters:
- deep_copybool, optional
Let
flow_field_of_coord_transform
denote the attributedistoptica.DistortionModel.flow_field_of_coord_transform
.If
deep_copy
is set toTrue
, then a deep copy offlow_field_of_coord_transform
is returned. Otherwise, a reference toflow_field_of_coord_transform
is returned.
- Returns:
- flow_field_of_coord_transformarray_like (torch.Tensor (float, ndim=2), shape=(2,))
The attribute
distoptica.DistortionModel.flow_field_of_coord_transform
.
- get_flow_field_of_coord_transform_right_inverse(deep_copy=True)[source]
Return the flow field of the right-inverse of the coordinate transformation corresponding to the distortion model.
- Parameters:
- deep_copybool, optional
Let
flow_field_of_coord_transform_right_inverse
denote the attributedistoptica.DistortionModel.flow_field_of_coord_transform_right_inverse
.If
deep_copy
is set toTrue
, then a deep copy offlow_field_of_coord_transform_right_inverse
is returned. Otherwise, a reference toflow_field_of_coord_transform_right_inverse
is returned.
- Returns:
- flow_field_of_coord_transform_right_inversearray_like (torch.Tensor (float, ndim=2), shape=(2,))
The attribute
distoptica.DistortionModel.flow_field_of_coord_transform_right_inverse
.
- get_out_of_bounds_map_of_distorted_then_resampled_images(deep_copy=True)[source]
Return the out-of-bounds map of distorted then resampled images.
- Parameters:
- deep_copybool, optional
Let
out_of_bounds_map_of_distorted_then_resampled_images
denote the attributedistoptica.DistortionModel.out_of_bounds_map_of_distorted_then_resampled_images
.If
deep_copy
is set toTrue
, then a deep copy ofout_of_bounds_map_of_distorted_then_resampled_images
is returned. Otherwise, a reference toout_of_bounds_map_of_distorted_then_resampled_images
is returned.
- Returns:
- out_of_bounds_map_of_distorted_then_resampled_imagestorch.Tensor (bool, ndim=2)
The attribute
distoptica.DistortionModel.out_of_bounds_map_of_distorted_then_resampled_images
.
- get_out_of_bounds_map_of_undistorted_then_resampled_images(deep_copy=True)[source]
Return the out-of-bounds map of undistorted then resampled images.
- Parameters:
- deep_copybool, optional
Let
out_of_bounds_map_of_undistorted_then_resampled_images
denote the attributedistoptica.DistortionModel.out_of_bounds_map_of_undistorted_then_resampled_images
.If
deep_copy
is set toTrue
, then a deep copy ofout_of_bounds_map_of_undistorted_then_resampled_images
is returned. Otherwise, a reference toout_of_bounds_map_of_undistorted_then_resampled_images
is returned.
- Returns:
- out_of_bounds_map_of_undistorted_then_resampled_imagestorch.Tensor (bool, ndim=2)
The attribute
distoptica.DistortionModel.out_of_bounds_map_of_undistorted_then_resampled_images
.
- classmethod get_pre_serialization_funcs()[source]
Return the pre-serialization functions.
- Returns:
- pre_serialization_funcsdict
The attribute
pre_serialization_funcs
.
- get_sampling_grid(deep_copy=True)[source]
Return the fractional coordinates of the sampling grid.
- Parameters:
- deep_copybool, optional
Let
sampling_grid
denote the attributedistoptica.DistortionModel.sampling_grid
.If
deep_copy
is set toTrue
, then a deep copy ofsampling_grid
is returned. Otherwise, a reference tosampling_grid
is returned.
- Returns:
- sampling_gridarray_like (torch.Tensor (float, ndim=2), shape=(2,))
The attribute
distoptica.DistortionModel.sampling_grid
.
- classmethod get_validation_and_conversion_funcs()[source]
Return the validation and conversion functions.
- Returns:
- validation_and_conversion_funcsdict
The attribute
validation_and_conversion_funcs
.
- property is_azimuthally_symmetric
bool: A boolean variable indicating whether the distortion model is azimuthally symmetric.
If
is_azimuthally_symmetric
is set toTrue
, then the distortion model is azimuthally symmetric. Otherwise, the distortion model is not azimuthally symmetric.Note that
is_azimuthally_symmetric
should be considered read-only.
- property is_standard
bool: A boolean variable indicating whether the distortion model is standard.
See the documentation for the class
distoptica.StandardCoordTransformParams
for a definition of a standard distortion model.- If
is_standard
is set toTrue
, then the distortion model is standard. Otherwise, the distortion model is not standard.
Note that
is_standard
should be considered read-only.- If
- property is_trivial
bool: A boolean variable indicating whether the distortion model is trivial.
We define a trivial distortion model to be one with a corresponding coordinate transformation that is equivalent to the identity transformation.
If
is_trivial
is set toTrue
, then the distortion model is trivial. Otherwise, the distortion model is not trivial.Note that
is_trivial
should be considered read-only.
- classmethod load(filename='serialized_rep_of_fancytype.json', skip_validation_and_conversion=False)
Construct an instance from a serialized representation that is stored in a JSON file.
Users can save serialized representations to JSON files using the method
fancytypes.PreSerializable.dump()
.- Parameters:
- filenamestr, optional
The relative or absolute path to the JSON file that is storing the serialized representation of an instance.
filename
is expected to be such thatjson.load(open(filename, "r"))
does not raise an exception.Let
serializable_rep=json.load(open(filename, "r"))
.Let
validation_and_conversion_funcs
andde_pre_serialization_funcs
denote the attributesvalidation_and_conversion_funcs
de_pre_serialization_funcs
respectively, both of which being dict objects as well.filename
is also expected to be such thatde_pre_serialization_funcs[key](serializable_rep[key])
does not raise an exception for each dict keykey
inde_pre_serialization_funcs
.Let
core_attrs_candidate
be a dict object that has the same keys asde_pre_serialization_funcs
, where for each dict keykey
inserializable_rep
,core_attrs_candidate[key]
is set to de_pre_serialization_funcs[key](serializable_rep[key])``.filename
is also expected to be such thatvalidation_and_conversion_funcs[key](core_attrs_candidate)
does not raise an exception for each dict keykey
inserializable_rep
.- skip_validation_and_conversionbool, optional
Let
core_attrs
denote the attributecore_attrs
, which is a dict object.Let
core_attrs_candidate
be as defined in the above description offilename
.If
skip_validation_and_conversion
is set toFalse
, then for each keykey
incore_attrs_candidate
,core_attrs[key]
is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate)
, , withvalidation_and_conversion_funcs
andcore_attrs_candidate
being introduced in the above description offilename
.Otherwise, if
skip_validation_and_conversion
is set toTrue
, thencore_attrs
is set tocore_attrs_candidate.copy()
. This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofcore_attrs_candidate
, as it is guaranteed that no copies or conversions are made in this case.
- Returns:
- instance_of_current_clsCurrent class
An instance constructed from the serialized representation stored in the JSON file.
- classmethod loads(serialized_rep='{}', skip_validation_and_conversion=False)
Construct an instance from a serialized representation.
Users can generate serialized representations using the method
dumps()
.- Parameters:
- serialized_repstr | bytes | bytearray, optional
The serialized representation.
serialized_rep
is expected to be such thatjson.loads(serialized_rep)
does not raise an exception.Let
serializable_rep=json.loads(serialized_rep)
.Let
validation_and_conversion_funcs
andde_pre_serialization_funcs
denote the attributesvalidation_and_conversion_funcs
de_pre_serialization_funcs
respectively, both of which being dict objects as well.serialized_rep
is also expected to be such thatde_pre_serialization_funcs[key](serializable_rep[key])
does not raise an exception for each dict keykey
inde_pre_serialization_funcs
.Let
core_attrs_candidate
be a dict object that has the same keys asserializable_rep
, where for each dict keykey
inde_pre_serialization_funcs
,core_attrs_candidate[key]
is set to de_pre_serialization_funcs[key](serializable_rep[key])``.serialized_rep
is also expected to be such thatvalidation_and_conversion_funcs[key](core_attrs_candidate)
does not raise an exception for each dict keykey
inserializable_rep
.- skip_validation_and_conversionbool, optional
Let
core_attrs
denote the attributecore_attrs
, which is a dict object.If
skip_validation_and_conversion
is set toFalse
, then for each keykey
incore_attrs_candidate
,core_attrs[key]
is set tovalidation_and_conversion_funcs[key] (core_attrs_candidate)
, withvalidation_and_conversion_funcs
andcore_attrs_candidate_1
being introduced in the above description ofserialized_rep
.Otherwise, if
skip_validation_and_conversion
is set toTrue
, thencore_attrs
is set tocore_attrs_candidate.copy()
. This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofcore_attrs_candidate
, as it is guaranteed that no copies or conversions are made in this case.
- Returns:
- instance_of_current_clsCurrent class
An instance constructed from the serialized representation.
- property mask_frame_of_distorted_then_resampled_images
array_like: The minimum frame to mask all boolean values of
False
in the attributedistoptica.DistortionModel.convergence_map_of_distorted_then_resampled_images
.See the documentation for the attribute
distoptica.DistortionModel.convergence_map_of_distorted_then_resampled_images
for additional context.mask_frame_of_distorted_then_resampled_images
is a 4-element tuple wheremask_frame_of_distorted_then_resampled_images[0]
,mask_frame_of_distorted_then_resampled_images[1]
,mask_frame_of_distorted_then_resampled_images[2]
, andmask_frame_of_distorted_then_resampled_images[3]
are the widths, in units of pixels, of the left, right, bottom, and top sides of the mask frame respectively. If all elements ofmask_frame_of_distorted_then_resampled_images
are equal to zero, then every element ofdistoptica.DistortionModel.convergence_map_of_distorted_then_resampled_images
evaluates toTrue
.Note that
mask_frame_of_distorted_then_resampled_images
should be considered read-only.
- property out_of_bounds_map_of_distorted_then_resampled_images
torch.Tensor: The out-of-bounds map of distorted then resampled images.
See the summary documentation of the class
distoptica.DistortionModel
for additional context.out_of_bounds_map_of_distorted_then_resampled_images
is a PyTorch tensor having a shape equal to \(\left(N_{\mathring{\mathcal{I}};y}, N_{\mathring{\mathcal{I}};x}\right)\), where \(N_{\mathring{\mathcal{I}};x}\) and \(N_{\mathring{\mathcal{I}};y}\) being the number of pixels in the sampling grid from left to right and top to bottom respectively.Let
sampling_grid
andflow_field_of_coord_transform_right_inverse
denote the attributesdistoptica.DistortionModel.sampling_grid
anddistoptica.DistortionModel.flow_field_of_coord_transform_right_inverse
respectively. Furthermore, letu_x = sampling_grid[0]+flow_field_of_coord_transform_right_inverse[0]
andu_y = sampling_grid[1]+flow_field_of_coord_transform_right_inverse[1]
.out_of_bounds_map_of_distorted_then_resampled_images
is equal to(u_x*u_x.shape[1]<=0.5) | (u_x.shape[1]-0.5<=u_x*u_x.shape[1]) | (u_y*u_y.shape[0]<=0.5) | (u_y.shape[0]-0.5<=u_y*u_y.shape[0])
.Note that
out_of_bounds_map_of_coord_transform
should be considered read-only.
- property out_of_bounds_map_of_undistorted_then_resampled_images
torch.Tensor: The out-of-bounds map of undistorted then resampled images.
See the summary documentation of the class
distoptica.DistortionModel
for additional context.out_of_bounds_map_of_undistorted_then_resampled_images
is a PyTorch tensor having a shape equal to \(\left(N_{\mathring{\mathcal{I}};y}, N_{\mathring{\mathcal{I}};x}\right)\), where \(N_{\mathring{\mathcal{I}};x}\) and \(N_{\mathring{\mathcal{I}};y}\) being the number of pixels in the sampling grid from left to right and top to bottom respectively.Let
sampling_grid
andflow_field_of_coord_transform
denote the attributesdistoptica.DistortionModel.sampling_grid
anddistoptica.DistortionModel.flow_field_of_coord_transform
respectively. Furthermore, letq_x = sampling_grid[0]+flow_field_of_coord_transform[0]
andq_y = sampling_grid[1]+flow_field_of_coord_transform[1]
.out_of_bounds_map_of_undistorted_then_resampled_images
is equal to(q_x*q_x.shape[1]<=0.5) | (q_x.shape[1]-0.5<=q_x*q_x.shape[1]) | (q_y*q_y.shape[0]<=0.5) | (q_y.shape[0]-0.5<=q_y*q_y.shape[0])
.Note that
out_of_bounds_map_of_coord_transform
should be considered read-only.
- property pre_serialization_funcs
dict: The pre-serialization functions.
pre_serialization_funcs
has the same keys as the attributevalidation_and_conversion_funcs
, which is also a dict object.Let
validation_and_conversion_funcs
andcore_attrs
denote the attributesvalidation_and_conversion_funcs
andcore_attrs
respectively, the last of which being a dict object as well.For each dict key
key
incore_attrs
,pre_serialization_funcs[key](core_attrs[key])
is expected to yield a serializable object, i.e. it should yield an object that can be passed into the functionjson.dumps
without raising an exception.Note that
pre_serialization_funcs
should be considered read-only.
- pre_serialize()
Pre-serialize instance.
- Returns:
- serializable_repdict
A serializable representation of an instance.
- property sampling_grid
array_like: The fractional coordinates of the sampling grid.
See the summary documentation of the class
distoptica.DistortionModel
for additional context.sampling_grid
is a 2-element tuple, wheresampling_grid[0]
andsampling_grid[1]
are PyTorch tensors, each having a shape equal to \(\left(N_{\mathring{\mathcal{I}};y}, N_{\mathring{\mathcal{I}};x}\right)\), with \(N_{\mathring{\mathcal{I}};x}\) and \(N_{\mathring{\mathcal{I}};y}\) being the number of pixels in the sampling grid from left to right and top to bottom respectively.For every pair of nonnegative integers
(i, j)
that does not raise anIndexError
exception upon callingsampling_grid[0, i, j]
,sampling_grid[0, i, j]
andsampling_grid[1, i, j]
are equal to the quantities \(u_{\mathcal{\mathring{I}};x;j}\) and \(u_{\mathcal{\mathring{I}};y;i}\) respectively, with the integers \(i\) and \(j\) being equal to the values ofi
andj
respectively, and \(u_{\mathcal{\mathring{I}};x;j}\) and \(u_{\mathcal{\mathring{I}};y;i}\) being given by Eqs. (2.3.17) and (2.3.18) respectively.Note that
sampling_grid
should be considered read-only.
- undistort_then_resample_images(distorted_images=((0.0,),))[source]
Undistort and resample a 1D stack of distorted images.
Each distorted image is undistorted and subsequently resampled according to Eq. (2.3.27).
- Parameters:
- distorted_imagesarray_like (float, ndim=2) | array_like (float, ndim=3) | array_like (float, ndim=4), optional
The distorted images to be undistorted and resampled. If
len(distorted_images.shape)==4
, then for every quadruplet of nonnegative integers(l, k, n, m)
that does not raise anIndexError
exception upon callingdistorted_images[l, k, n, m]
,distorted_images[l, k, n, m]
is interpreted to be the quantity \(\mathcal{I}_{⌑;l,k,n,m}\), introduced in the summary documentation of the classdistoptica.DistortionModel
, with the integers \(l\), \(k\), \(n\), and \(m\) being equal to the values ofl
,k
,n
, andm
respectively, and the quadruplet of integers \(\left(N_{\mathcal{I}},N_{\mathcal{I};C},N_{\mathcal{I};y}, N_{\mathcal{I};x}\right)\), introduced in the summary documentation of the classdistoptica.DistortionModel
, being equal to the shape ofdistorted_images
. Iflen(distorted_images.shape)==3
, then for every quadruplet of nonnegative integers(k, n, m)
that does not raise anIndexError
exception upon callingdistorted_images[k, n, m]
,distorted_images[k, n, m]
is interpreted to be the quantity \(\mathcal{I}_{⌑;0,k,n,m}\), with the integers \(k\), \(n\), and \(m\) being equal to the values ofc
,n
, andm
respectively, the triplet of integers \(\left(N_{\mathcal{I};C},N_{\mathcal{I};y}, N_{\mathcal{I};x}\right)\) being equal to the shape ofdistorted_images
, and \(N_{\mathcal{I}}\) being equal to unity. Otherwise, iflen(distorted_images.shape)==2
, then for every pair of nonnegative integers(n, m)
that does not raise anIndexError
exception upon callingdistorted_images[n, m]
,distorted_images[n, m]
is interpreted to be the quantity \(\mathcal{I}_{⌑;0,0,n,m}\), with the integers \(n\) and \(m\) being equal to the values ofn
, andm
respectively, the pair of integers \(\left(N_{\mathcal{I};y},N_{\mathcal{I};x}\right)\) being equal to the shape ofdistorted_images
, and both \(N_{\mathcal{I}}\) and \(N_{\mathcal{I};C}\) being equal to unity.
- Returns:
- undistorted_then_resampled_imagestorch.Tensor (float, ndim=4)
The images resulting from undistorting then resampling the input image set. For every quadruplet of nonnegative integers
(l, k, i, j)
that does not raise anIndexError
exception upon callingundistorted_then_resampled_images[l, k, i, j]
,undistorted_then_resampled_images[l, k, i, j]
is interpreted to be the quantity \(\mathring{\mathcal{I}}_{\square;l,k,i,j}\), introduced in the summary documentation of the classdistoptica.DistortionModel
, with the integers \(l\), \(k\), \(i\), and \(j\) being equal to the values ofl
,k
,i
, andj
respectively, with the quadruplet of integers \(\left(N_{\mathcal{I}},N_{\mathcal{I};C}, N_{\mathring{\mathcal{I}};y},N_{\mathring{\mathcal{I}};x}\right)\), introduced in the summary documentation of the classdistoptica.DistortionModel
, being equal to the shape ofundistorted_then_resampled_images
.
- update(new_core_attr_subset_candidate, skip_validation_and_conversion=False)[source]
Update a subset of the core attributes.
- Parameters:
- new_core_attr_subset_candidatedict, optional
A dict object.
- skip_validation_and_conversionbool, optional
Let
validation_and_conversion_funcs
andcore_attrs
denote the attributesvalidation_and_conversion_funcs
andcore_attrs
respectively, both of which being dict objects.If
skip_validation_and_conversion
is set toFalse
, then for each keykey
incore_attrs
that is also innew_core_attr_subset_candidate
,core_attrs[key]
is set tovalidation_and_conversion_funcs[key] (new_core_attr_subset_candidate)
.Otherwise, if
skip_validation_and_conversion
is set toTrue
, then for each keykey
incore_attrs
that is also innew_core_attr_subset_candidate
,core_attrs[key]
is set tonew_core_attr_subset_candidate[key]
. This option is desired primarily when the user wants to avoid potentially expensive deep copies and/or conversions of the dict values ofnew_core_attr_subset_candidate
, as it is guaranteed that no copies or conversions are made in this case.
- property validation_and_conversion_funcs
dict: The validation and conversion functions.
The keys of
validation_and_conversion_funcs
are the names of the constructor parameters, excludingskip_validation_and_conversion
if it exists as a construction parameter.Let
core_attrs
denote the attributecore_attrs
, which is also a dict object.For each dict key
key
incore_attrs
,validation_and_conversion_funcs[key](core_attrs)
is expected to not raise an exception.Note that
validation_and_conversion_funcs
should be considered read-only.