CrackDetectionTWLI

class CrackDetectionTWLI(theta=0, frequency=0.1, bandwidth=1, sigma_x=None, sigma_y=None, n_stds=3, min_size=5, threshold='yen', sensitivity=0)[source]

The basic method from Glud et al. for crack detection without preprocessing.

This is the basis for a crack detection with this method. Each object from this class can be used to detect cracks from images. The workflow of objects from this class is quite easy.

  1. Object instantiation. Create an object from with the input parameter for the crack detection.

  2. Call the method detect_cracks() with an image as input. This method will call all sub-functions of the crack detection.

    1. apply the gabor filter

    2. apply otsu´s threshold to split the image into foreground and background.

    3. skeletonize the foreground

    4. find the cracks in the skeletonized image.

Shift detection, normalization, and other preprocessing procedures are not performed! It is assumed that all the necessary preprocessing is already done for the input image. For preprocessing please use the stack_operations or other means.

Parameters
theta: float

Angle of the cracks in respect to a horizontal line in degrees

frequency: float, optional

Frequency of the gabor filter. Default: 0.1

bandwidth: float, optional

The bandwidth of the gabor filter, Default: 1

sigma_x: float, optional

Standard deviation of the gabor kernel in x-direction. This applies to the kernel before rotation. The kernel is then rotated theta degrees.

sigma_y: float, optional

Standard deviation of the gabor kernel in y-direction. This applies to the kernel before rotation. The kernel is then rotated theta degrees.

n_stds: int, optional

The size of the gabor kernel in standard deviations. A smaller kernel is faster but also less accurate. Default: 3

min_size: int, optional

The minimal number of pixels a crack can be. Cracks under this size will not get counted. Default: 1

threshold: str

Method of determining the threshold between foreground and background. Choose between ‘otsu’ or ‘yen’. Generally, yen is not as sensitive as otsu. For blurry images with lots of noise yen is nearly always better than otsu.

sensitivity: float, optional

Adds or subtracts x percent of the input image range to the threshold. E.g. sensitivity=-10 will lower the threshold to determine foreground by 10 percent of the input image range. For crack detection with bad image quality or lots of artefacts it can be helpful to lower the sensitivity to avoid too much false detections.

Methods

__call__(image, **kwargs)

Call self as a function.

detect_cracks(image[, out_intermediate_images])

Compute all steps of the crack detection

foreground_pattern(image[, method, sensitivity])

Apply the threshold to an image do determine foreground and background of the image.

detect_cracks(image, out_intermediate_images=False)[source]

Compute all steps of the crack detection

Parameters
image: np.ndarray
out_intermediate_images: bool, optional

If True the result of the gabor filter, the foreground pattern as a result of the otsu´s threshold and the skeletonized image are also included in the output. As this are three full sized images the default is False.

Returns
crack_density: float
cracks: np.ndarray

Array with the coordinates of the crack with the following structure: ([[x0, y0],[x1,y1], […]]) where x0 and y0 are the starting coordinates and x1, y1 the end of one crack. Each crack is represented by a 2x2 array stacked into a bigger array (x,2,2).

threshold_density: float

A measure how much of the area of the input image is detected as foreground. If the gabor filter can not distinguish between cracks with very little space in between the crack detection will break down and lead to false results. If this value is high but the crack density is low, this is an indicator that the crack detection does not work with the given input parameters and the input image.

gabor: np.ndarray, optional

The result of the Gabor filter.

pattern: np.ndarray, optional

A bool image the crack detection detects as cracked area.

skel_image: np.ndarray, optional

The skeletonized pattern as bool image.

static foreground_pattern(image, method='yen', sensitivity=0)[source]

Apply the threshold to an image do determine foreground and background of the image.

The result is a bool array with where True is foreground and False background of the image. The image can be split with image[pattern] into foreground and image[~pattern] into background.

Parameters
image: array-like
method: str

Method of determining the threshold between foreground and background. Choose between ‘otsu’ or ‘yen’.

sensitivity: float, optional

Adds or subtracts x percent of the input image range to the threshold. E.g. sensitivity=-10 will lower the threshold to determine foreground by 10 percent of the input image range.

Returns
——-
pattern: numpy.ndarray

Bool image with True as foreground.