darsia.ContourAnalysis#

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

Bases: object

Contour analysis object.

Constructor.

Parameters:
verbositybool

Verbosity flag.

Methods

contours()

Determine contour of loaded labeled image.

length()

Determine length of loaded labeled image.

load(img, mask[, roi, fill_holes])

Read labeled image and restrict to values of interest.

local_extrema([direction, contours])

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

number_peaks()

Determine number of peaks.

number_valleys()

Determine number of valleys.

plot_peaks(img, peaks_pixels[, roi, ...])

Plot peaks on top of the provided image.

plot_valleys(img, valleys_pixels[, roi, ...])

Plot valleys on top of the provided image.

Attributes

verbosity

Vebosity flag.

contour_smoother

Optional contour smoother for the contours determined from the mask.

reduce_to_main_contour

Whether to reduce to main contour.

contours()[source]#

Determine contour of loaded labeled image.

Returns:
list[np.ndarray]

List of contours, where each contour is given as an array of pixels.

length()[source]#

Determine length of loaded labeled image.

Returns:
float

Length of the interface between values of interest and others. Output in metric units.

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

Read labeled image and restrict to values of interest.

Parameters:
imgImage

Labeled image.

maskImage

Boolean mask covering the values of interest.

roiarray, optional

Set of points defining a box.

fill_holesbool

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:
directionnp.ndarray

Direction vector with orientation. # TODO do not allow for contours as input, make Contour analysis. Provide # possiblility to use contour as input in a different way.

contoursnp.ndarray | None

Contours to analyze. If None, contours are determined from the mask; default is None.

Returns:
array

Pixels of peaks.

array

Pixels of valleys.

number_peaks()[source]#

Determine number of peaks.

Returns:
int

Number of peaks.

number_valleys()[source]#

Determine number of valleys.

Returns:
int

Number of valleys.

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:
imgdarsia.Image

Image to plot on.

peaks_pixelsnp.ndarray

Pixels of peaks.

roidarsia.CoordinateArray | None

Region of interest. If provided, peaks are translated to the top left corner of the ROI; default is None.

contourslist[np.ndarray], optional

Contours to plot; if None, no contours are plotted; default is None.

pathPath, optional

Path to save the plot; if None, no saving is performed.

showbool

Flag controlling whether the plot is shown; default is True.

dpiint

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:
imgdarsia.Image

Image to plot on.

valleys_pixelsnp.ndarray

Pixels of valleys.

roidarsia.CoordinateArray | None

Region of interest. If provided, valleys are translated to the top left corner of the ROI; default is None.

contourslist[np.ndarray], optional

Contours to plot; if None, no contours are plotted; default is None.

pathPath, optional

Path to save the plot; if None, no saving is performed.

showbool

Flag controlling whether the plot is shown; default is True.

dpiint

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.