4.4.1. discorpy.post.postprocessing

Module of post-processing methods:

  • Correct distortion for a line of dots or an image.

  • Generate unwarped slices of a 3D dataset.

  • Calculate the residual of undistorted dots.

Functions:

unwarp_line_forward(list_lines, xcenter, ...)

Unwarp lines of dot-centroids using a forward model.

unwarp_line_backward(list_lines, xcenter, ...)

Unwarp lines of dot-centroids using a backward model.

unwarp_image_backward(mat, xcenter, ycenter, ...)

Unwarp an image using a backward model.

unwarp_image_forward(mat, xcenter, ycenter, ...)

Unwarp an image using a forward model.

unwarp_slice_backward(mat3D, xcenter, ...)

Generate an unwarped slice [:,index.:] of a 3D dataset, i.e. one unwarped sinogram of a 3D tomographic data.

unwarp_chunk_slices_backward(mat3D, xcenter, ...)

Generate a chunk of unwarped slices [:,start_index: stop_index, :] used for tomographic data.

calc_residual_hor(list_ulines, xcenter, ycenter)

Calculate the distances of unwarped dots (on each horizontal line) to each fitted straight line which is used to assess the straightness of unwarped lines.

calc_residual_ver(list_ulines, xcenter, ycenter)

Calculate the distances of unwarped dots (on each vertical line) to each fitted straight line which is used to assess the straightness of unwarped lines.

check_distortion(list_data)

Check if the distortion is significant or not.

correct_perspective_line(list_lines, list_coef)

Apply perspective correction to lines.

correct_perspective_image(mat, list_coef[, ...])

Parameters:
  • mat (array_like) -- 2D array. Image for correction.

discorpy.post.postprocessing.unwarp_line_forward(list_lines, xcenter, ycenter, list_fact)[source]

Unwarp lines of dot-centroids using a forward model.

Parameters:
  • list_lines (list of 2D arrays) – List of the coordinates of dot-centroids on each line.

  • list_fact (list of floats) – Polynomial coefficients of the forward model.

Returns:

list_ulines (list of 2D arrays) – List of the unwarped coordinates of dot-centroids on each line.

discorpy.post.postprocessing.unwarp_line_backward(list_lines, xcenter, ycenter, list_fact)[source]

Unwarp lines of dot-centroids using a backward model. The method finds the coordinates of undistorted points from the coordinates of distorted points using numerical optimzation.

Parameters:
  • list_lines (list of 2D arrays) – List of the coordinates of dot-centroids on each line.

  • list_fact (list of floats) – Polynomial coefficients of the backward model.

Returns:

list_ulines (list of 2D arrays) – List of the unwarped coordinates of dot-centroids on each line.

discorpy.post.postprocessing.unwarp_image_backward(mat, xcenter, ycenter, list_fact, order=1, mode='reflect')[source]

Unwarp an image using a backward model.

Parameters:
  • mat (array_like) – 2D array.

  • xcenter (float) – Center of distortion in x-direction.

  • ycenter (float) – Center of distortion in y-direction.

  • list_fact (list of float) – Polynomial coefficients of the backward model.

  • order (int, optional.) – The order of the spline interpolation.

  • mode ({‘reflect’, ‘grid-mirror’, ‘constant’, ‘grid-constant’, ‘nearest’,) – ‘mirror’, ‘grid-wrap’, ‘wrap’}, optional To determine how to handle image boundaries.

Returns:

array_like – 2D array. Distortion-corrected image.

discorpy.post.postprocessing.unwarp_image_forward(mat, xcenter, ycenter, list_fact)[source]

Unwarp an image using a forward model. Should be used only for assessment due to the problem of vacant pixels.

Parameters:
  • mat (float) – 2D array.

  • xcenter (float) – Center of distortion in x-direction.

  • ycenter (float) – Center of distortion in y-direction.

  • list_fact (list of floats) – Polynomial coefficients of the forward model.

Returns:

array_like – 2D array. Distortion-corrected image.

discorpy.post.postprocessing.unwarp_slice_backward(mat3D, xcenter, ycenter, list_fact, index)[source]

Generate an unwarped slice [:,index.:] of a 3D dataset, i.e. one unwarped sinogram of a 3D tomographic data.

Parameters:
  • mat3D (array_like) – 3D array. Correction is applied along axis 1.

  • xcenter (float) – Center of distortion in x-direction.

  • ycenter (float) – Center of distortion in y-direction.

  • list_fact (list of floats) – Polynomial coefficients of a backward model.

  • index (int) – Index of the slice

Returns:

array_like – 2D array. Distortion-corrected slice.

discorpy.post.postprocessing.unwarp_chunk_slices_backward(mat3D, xcenter, ycenter, list_fact, start_index, stop_index)[source]

Generate a chunk of unwarped slices [:,start_index: stop_index, :] used for tomographic data.

Parameters:
  • mat3D (array_like) – 3D array. Correction is applied along axis 1.

  • xcenter (float) – Center of distortion in x-direction.

  • ycenter (float) – Center of distortion in y-direction.

  • list_fact (list of floats) – Polynomial coefficients of a backward model.

  • start_index (int) – Starting index of slices.

  • stop_index (int) – Stopping index of slices.

Returns:

array_like – 3D array. Distortion-corrected slices.

discorpy.post.postprocessing.calc_residual_hor(list_ulines, xcenter, ycenter)[source]

Calculate the distances of unwarped dots (on each horizontal line) to each fitted straight line which is used to assess the straightness of unwarped lines.

Parameters:
  • list_ulines (list of 2D arrays) – List of the coordinates of dot-centroids on each unwarped horizontal line.

  • xcenter (float) – Center of distortion in x-direction.

  • ycenter (float) – Center of distortion in y-direction.

Returns:

array_like – 2D array. Each element has two values: 1) Distance of a dot to the center of distortion; 2) Distance of this dot to the nearest fitted straight line.

discorpy.post.postprocessing.calc_residual_ver(list_ulines, xcenter, ycenter)[source]

Calculate the distances of unwarped dots (on each vertical line) to each fitted straight line which is used to assess the straightness of unwarped lines.

Parameters:
  • list_ulines (list of 2D arrays) – List of the coordinates of dot-centroids on each unwarped vertical line.

  • xcenter (float) – Center of distortion in x-direction.

  • ycenter (float) – Center of distortion in y-direction.

Returns:

array_like – 2D array. Each element has two values: 1) Distance of a dot to the center of distortion; 2) Distance of this dot to the nearest fitted straight line.

discorpy.post.postprocessing.check_distortion(list_data)[source]

Check if the distortion is significant or not. If the number of dots having the residual greater than 1 pixel is greater than 15% of the total number of dots, there’s distortion.

Parameters:

list_data (array_like) – List of [radius, residual] of each dot.

Returns:

bool

discorpy.post.postprocessing.correct_perspective_line(list_lines, list_coef)[source]

Apply perspective correction to lines.

Parameters:
  • list_lines (list of 2D-arrays) – List of the (y,x)-coordinates of points on each line.

  • list_coef (list of floats) – Coefficients of the forward-mapping matrix.

Returns:

list_clines (list of 2D arrays) – List of the corrected (y,x)-coordinates of points on each line.

discorpy.post.postprocessing.correct_perspective_image(mat, list_coef, order=1, mode='reflect', map_index=None)[source]
Parameters:
  • mat (array_like) – 2D array. Image for correction.

  • list_coef (list of floats) – Coefficients of the backward-mapping matrix.

  • order (int, optional.) – The order of the spline interpolation.

  • mode ({‘reflect’, ‘grid-mirror’, ‘constant’, ‘grid-constant’, ‘nearest’,) – ‘mirror’, ‘grid-wrap’, ‘wrap’}, optional To determine how to handle image boundaries.

  • map_index (array_like) – Indices for mapping. Generated if None is given.

Returns:

array_like – Corrected image.