thermography.detection package

This package contains the implementation of various sub-steps of thermography for module detection.

Submodules

thermography.detection.edge_detection module

class EdgeDetectorParams[source]

Bases: object

Parameters used by the EdgeDetector.

Initializes the edge detector parameters to their default value.

Variables:
  • hysteresis_min_thresh – Canny candidate edges whose weight is smaller than this threshold are ignored.
  • hysteresis_max_thresh – Canny candidate edges whose weights is larger than this threshold are considered as edges without hysteresis.
  • kernel – Kernel shape to use when performing dilation and erosion of binary edge image.
  • dilation_steps – Number of dilation steps to take before skeletonization.
class EdgeDetector(input_image: numpy.ndarray, params: thermography.detection.edge_detection.EdgeDetectorParams = <thermography.detection.edge_detection.EdgeDetectorParams object>)[source]

Bases: object

Class responsible for detecting edges in greyscale images. The approach taken to detect edges in the input greyscale image is the following:

  1. Perform a canny edge detection on the input image.
  2. Dilate the resulting binary image for a parametrized number of steps in order to connect short edges and smooth out the edge shape.
  3. Erode the dilated edge image in order to obtain a 1-pixel wide skeletonization of the edges in the input image.
Parameters:
  • input_image – Input greyscale image where edges must be detected.
  • params – Parameters used for edge detection.
detect() → None[source]

Detects the edges in the image passed to the constructor using the parameters passed to the constructor.

thermography.detection.intersection_detection module

class IntersectionDetector(input_segments: list, params: thermography.detection.intersection_detection.IntersectionDetectorParams = <thermography.detection.intersection_detection.IntersectionDetectorParams object>)[source]

Bases: object

Class responsible for detecting intersections between segments.

Initializes the intersection detector object.

Intersections are computed between all segments s_i of cluster i, against all segments s_j of cluster j.

Parameters:
  • input_segments – List of segment clusters. Each element cluster_i of this list is a numpy array of shape [num_segments_i, 4]
  • params – Parameters to be used for intersection detection.
detect()[source]

Detects the intersections between the segments passed to the constructor using the parameters passed to the constructor.

Note

The intersections are only computed between segments belonging to different clusters, and never between segments of the same cluster.

class IntersectionDetectorParams[source]

Bases: object

Parameters used by the IntersectionDetector.

Initializes the intersection detector parameters to their default value.

Variables:angle_threshold – Only intersections between segments which deviate less than this parameter from the canonical 90° angle are accepted.

thermography.detection.motion_detection module

class MotionDetector(scaling: float = 1.0)[source]

Bases: object

Class responsible for estimating the motion between two consecutive frames.

Initializes the motion detector object.

Parameters:scaling – Scaling to apply to each image frame passed to the motion estimate. This allows faster estimations of motion over the entire image when scaled down.
motion_estimate(frame: numpy.ndarray) → numpy.ndarray[source]

Estimates the motion between the frame passed as parameter and the one stored in self.last_frame.

Parameters:frame – New frame of the sequence.
Returns:The estimation of the mean motion between self.last_frame and the frame passed as argument. The motion estimate is expressed in pixel units.

thermography.detection.preprocessing module

class PreprocessingParams[source]

Bases: object

Parameters used by the FramePreprocessor.

Initializes the preprocessing parameters to their default value.

Variables:
  • gaussian_blur – Radius of the gaussian blur to apply to the input image.
  • image_scaling – Scaling factor to apply to the input image.
  • image_rotation – Angle expressed in radiants used to rotate the input image.
  • red_threshold – Temperature threshold used to discard cold unimportant areas in the image.
  • min_area – Minimal surface of retained important areas of the image. Warm regions whose surface is smaller than this threshold are discarded.
class FramePreprocessor(input_image: numpy.ndarray, params: thermography.detection.preprocessing.PreprocessingParams = <thermography.detection.preprocessing.PreprocessingParams object>)[source]

Bases: object

Class responsible for preprocessing an image frame.

Initializes the frame preprocessor with the input image and the preprocessor parameters.

Parameters:
  • input_image – RGB or greyscale input image to be preprocessed.
  • params – Preprocessing parameters.
channels

Returns the number of channels of the self.input_image image.

gray_scale

Returns a boolean indicating wheter self.input_image is a greyscale image (or an RGB image where all channels are identical).

preprocess() → None[source]

Preprocesses the self.input_image following this steps:

  1. The image is scaled using the self.params.image_scaling parameter.

  2. The image is rotated using the self.params.image_rotation parameter.

  3. Attention detection.

    1. If the image is RGB, the self.params.red_threshold parameter is used to determine the attention areas of the image.
    2. Otherwise the entire image is kept as attention.

thermography.detection.rectangle_detection module

class RectangleDetector(input_intersections: dict, params: thermography.detection.rectangle_detection.RectangleDetectorParams = <thermography.detection.rectangle_detection.RectangleDetectorParams object>)[source]

Bases: object

Class responsible for detecting rectangles given a structured intersection list.

Initializes the rectangle detector with the input intersections and the rectangle detection parameters.

detect() → None[source]

Detects the rectangles from the input intersections.

static fulfills_ratio(rectangle: numpy.ndarray, expected_ratio: float, deviation: float) → bool[source]

Computes wether a rectangle defined as a set of four coordinates fulfills a predefined aspect ratio within a maximal deviation.

Parameters:
  • rectangle – Rectangle to be tested defined as a set of four pixel coordinates as a numpy array of shape [4,2].
  • expected_ratio – Expected aspect ratio of the rectangle.
  • deviation – Maximal deviation between the query rectangle and the expected_ratio in order to accept or not the ratio test.
Returns:

A boolean set to True if the aspect relative deviation between its aspect ratio and the expected_ratio is smaller than the deviation threshold.

class RectangleDetectorParams[source]

Bases: object

Parameters used by the RectangleDetector.

Initializes the rectangle detector parameters to their default value.

Variables:
  • aspect_rato – Expected rectangle aspect ratio.
  • aspect_ratio_relative_deviation – Detected rectangles whose aspect ratio deviates from self.aspect_ratio more than this parameter are ignored.
  • min_area – Minimal surface of detected rectangles. Smaller rectangles are rejected.

thermography.detection.segment_clustering module

class SegmentClusterer(input_segments: numpy.ndarray, params: thermography.detection.segment_clustering.SegmentClustererParams = <thermography.detection.segment_clustering.SegmentClustererParams object>)[source]

Bases: object

Class responsible for clustering and cleaning the raw segments extracted by the SegmentDetector class.

Initializes the segment clusterer with the input segments and the semgment clusterer parameters.

clean_clusters(mean_angles, params: thermography.detection.segment_clustering.ClusterCleaningParams = <thermography.detection.segment_clustering.ClusterCleaningParams object>) → None[source]

Cleans the clusters by removing edges outliers (angle deviation from cluster mean is too high), and by merging almost collinear segments into a single segment.

Parameters:
  • mean_angles – List of mean angles computed for each cluster.
  • params – Parameters used to clean the clusters.
cluster_segments() → None[source]

Clusters the input segments self.raw_segments based on the parameters passed as argument.

compute_cluster_mean() → tuple[source]

Computes the mean values (coordinates and angles) for each one of the identified clusters. :return The mean angles, and mean coordinates of each cluster.

class SegmentClustererParams[source]

Bases: object

Parameters used by the SegmentClusterer related to segment clustering.

Initializes the segment clusterer parameters to their default value.

Variables:
  • num_init – Number of times the cluster detector should reinitialize the cluster search (only works if self.cluster_type is “knn”).
  • num_clusters – Number of clusters to be searched.
  • swipe_clusters – Boolean flag which indicates whether the cluster search should sweep over the possible number of clusters or not. (only works if self.cluster_type is “gmm”).
  • cluster_type – String specifying which algorithm to used for cluster detection (“knn” : K-nearest neighbors, “gmm” : Gaussian mixture model).
  • use_angles – Boolean flag indicating if the features to be used for clustering should include the segment angles.
  • use_centers – Boolean flag indicating if the features to be used for clustering should include the segment centers.
class ClusterCleaningParams[source]

Bases: object

Parameters used by the SegmentClusterer related to segment filtering.

Initializes the cluster cleaning parameters to their default value.

Variables:
  • max_angle_variation_mean – Segments whose angle with the mean cluster angle deviates more than this parameter, are rejected.
  • max_merging_angle – Candidate segment pairs for merging whose relative angle deviates more than this threshold are not merged.
  • max_endpoint_distance – Candidate segment pairs for merging whose sum of squared distances between endpoints is larger than the square of this parameter are not merged.

thermography.detection.segment_detection module

class SegmentDetector(input_image: numpy.ndarray, params=<thermography.detection.segment_detection.SegmentDetectorParams object>)[source]

Bases: object

Class responsible for detecting segments in the edge image generated by EdgeDetector.

Initializes the segment detector with the binary input image and the segment detector parameters.

Parameters:
  • input_image – Binary edge image (usually generated by EdgeDetector.
  • params – Segment detector parameters to be used for segment detection.
detect()[source]

Detects the segments in the input image using the parameters passed as argument using a probilistic Hough transform.

class SegmentDetectorParams[source]

Bases: object

Parameters used by the SegmentDetector.

Initializes the segment detector parameters to their default value.

Variables:
  • d_rho – Distance resolution in pixels of the Hough parameter space.
  • d_theta – Angle resolution in pixels of the Hough parameter space expressed in radiants.
  • min_number_votes – Minimum number of votes in the Hough space to accept a segment.
  • min_line_length – Minimum line length for segment acceptance expressed in pixel units.
  • max_line_gap – Different segments who present a gap smaller than this parameter are detected as a single segment.
  • extension_pixels – All the detected segments are extended by this amount of pixels on each side.