Single image analysis (darsia.single_image_analysis)#

Post-processing tools for physical data.

Submodules#

darsia.single_image_analysis.contouranalysis module#

Module containing analysis tools for segmented images.

This includes measuring lengths of contours, weighted sums (generalized mass analysis).

class ContourAnalysis(verbosity=False, contour_smoother=None, reduce_to_main_contour=False)[source]#

Bases: object

Contour analysis object.

contours()[source]#

Determine contour of loaded labeled image.

Returns:

list of contours, where each contour is given as an

array of pixels.

Return type:

list[np.ndarray]

length()[source]#

Determine length of loaded labeled image.

Returns:

length of the interface between values of interest and others.

Output in metric units.

Return type:

float

load(img, mask, roi=None, fill_holes=False)[source]#

Read labeled image and restrict to values of interest.

Parameters:
  • img (Image) – labeled image.

  • roi (array, optional) – set of points defining a box.

  • values_of_interest (int, list of int, optional) – label values of interest.

  • fill_holes (bool) – flag controlling whether holes in labels are filles.

local_extrema(direction=array([0., -1.]), contours=None)[source]#

Determine local extrema of the contour, where the extremality is defined by a direction.

Parameters:
  • contours (np.ndarray | None) – contours to analyze. If None, contours are determined from the mask; default is None.

  • direction (np.ndarray) – direction vector with orientation

  • input (# TODO do not allow for contours as)

  • Provide (make Contour analysis.)

  • way. (# possiblility to use contour as input in a different)

Returns:

pixels of peaks. array: pixels of valleys.

Return type:

array

number_peaks()[source]#

Determine number of peaks.

Returns:

number of peaks.

Return type:

int

number_valleys()[source]#

Determine number of valleys.

Returns:

number of valleys.

Return type:

int

plot_peaks(img, peaks_pixels, roi=None, contours=None, path=None, show=True, dpi=1000, **kwargs)[source]#

Plot peaks on top of the provided image.

Parameters:
  • img (darsia.Image) – image to plot on.

  • peaks_pixels (np.ndarray) – pixels of peaks.

  • contours (list[np.ndarray], optional) – contours to plot; if None, no contours are plotted; default is None.

  • roi (darsia.CoordinateArray | None) – region of interest. If provided, peaks are translated to the top left corner of the ROI; default is None.

  • path (Path, optional) – path to save the plot; if None, no saving is performed.

  • show (bool) – flag controlling whether the plot is shown; default is True.

  • dpi (int) – dots per inch for the saved plot; default is 1000.

  • **kwargs – additional keyword arguments for plotting. - color (str): color for the peaks; default is “r”. - size (int): size for the peaks; default is 20.

plot_valleys(img, valleys_pixels, roi=None, contours=None, path=None, show=True, dpi=1000, **kwargs)[source]#

Plot valleys on top of the provided image.

Parameters:
  • img (darsia.Image) – image to plot on.

  • valleys_pixels (np.ndarray) – pixels of valleys.

  • contours (list[np.ndarray], optional) – contours to plot; if None, no contours are plotted; default is None.

  • roi (darsia.CoordinateArray | None) – region of interest. If provided, valleys are translated to the top left corner of the ROI; default is None.

  • path (Path, optional) – path to save the plot; if None, no saving is performed.

  • show (bool) – flag controlling whether the plot is shown; default is True.

  • dpi (int) – dots per inch for the saved plot; default is 1000.

  • **kwargs – additional keyword arguments for plotting. - valley_color (str): color for valley lines; default is “c”. - valley_linewidth (float): line width for valley lines; default is 1. - y_min (float): lower y-limit for valley lines; default is top of ROI. - y_max (float): upper y-limit for valley lines; default is bottom of ROI. - plot_valley_dots (bool): if True, valley dots are added; default is False. - valley_dot_color (str): color for valley dots; default is valley_color. - valley_dot_size (float): dot size for valley dots; default is 20.

contour_smoother#

Optional contour smoother for the contours determined from the mask.

reduce_to_main_contour#

Whether to reduce to main contour.

verbosity#

Vebosity flag.

contour_length(img, roi=None, values_of_interest=None, fill_holes=False, verbosity=False)[source]#

Calculation of the contour length of a segmented region.

Parameters:
  • img (darsia.Image) – segmented image with boolean or integer values.

  • roi (np.ndarray) – set of points, for which a bounding box defines a ROI.

  • values_of_interest (int or list of int) – only active if integer-valued image provided; defines the values of interest, i.e., which part of the image is treated as active.

  • fill_holes (bool) – flag controlling whether holes in the determined mask are filled before the contour length is computed; if not, holes are treated as contour; default is True.

  • verbosity (bool) – flag controlling whether intermediate results are plotted; default is False.

Returns:

contour length in metric units based on the coordinate system of the

input image.

Return type:

float