5.2.2. discorpy.prep.linepattern
Module of pre-processing methods for handling line-pattern images and chessboard images:
Determine the slopes and distances between lines in horizontal and vertical directions.
Convert a chessboard image to a line-pattern image.
Extract line profiles across an image.
Get points belonging to a line by locating local extrema.
Get points belonging to the edges of a chessboard image by converting a line profile into a list of slopes, calculated using a linear fit of neighboring points.
Select good points using Gaussian peak fitting.
Functions:
|
Locate the extremum point of a 1D array with subpixel accuracy. |
|
Select good peaks from the input data based on Gaussian fitting and tolerance criteria. |
|
Compute the absolute slopes of a linear fit within a sliding window across the input data, normalized by the mean slope if norm is True. |
|
Get a list of local extremum points from a 1D array. |
|
Calculate the representative distance between horizontal lines and the representative slope of these lines using the ROI around the middle of a line-pattern image or a chessboard image. |
|
Calculate the representative distance between vertical lines and the representative slope of these lines using the ROI around the middle of a line-pattern image or a chessboard image. |
|
Get the intensity-profile along a tilted line across an image. |
|
Convert a chessboard image to a line-pattern image. |
|
Get points on horizontal lines of a line-pattern image, or a chessboard image, by intersecting with a list of generated vertical-lines. |
|
Get points on vertical lines of a line-pattern image, or a chessboard image, by intersecting with a list of generated horizontal-lines. |
- discorpy.prep.linepattern.locate_subpixel_point(list_point, option='min')[source]
Locate the extremum point of a 1D array with subpixel accuracy.
- Parameters:
list_point (array_like) – 1D array.
option ({“min”, “max”}) – To locate the minimum point or the maximum point.
- Returns:
float – Subpixel position of the extremum point.
- discorpy.prep.linepattern.select_good_peaks(list_data, peaks, tol=0.2, radius=11, sigma=0, use_offset=True)[source]
Select good peaks from the input data based on Gaussian fitting and tolerance criteria.
- Parameters:
list_data (array_like) – 1d-array.
peaks (list of int) – Indices of candidate peaks in the data.
tol (float, optional) – Tolerance for peak fitting accuracy.
radius (int, optional) – Radius around each peak to consider for fitting.
sigma (float, optional) – Standard deviation for Gaussian smoothing.
use_offset (bool, optional) – Use fitted offset value for judging if True.
- Returns:
list of int – Indices of the selected good peaks.
- discorpy.prep.linepattern.sliding_window_slope(list_data, size=3, norm=True)[source]
Compute the absolute slopes of a linear fit within a sliding window across the input data, normalized by the mean slope if norm is True.
- Parameters:
list_data (array-like) – 1d-array.
size (int, optional) – Size of the sliding window for the linear fit.
norm (bool, optional) – Normalize the result by the mean slope if True.
- Returns:
array_like – Normalized absolute slopes for each data point.
- discorpy.prep.linepattern.get_local_extrema_points(list_data, option='min', radius=7, sensitive=0.1, denoise=True, norm=True, subpixel=True, select_peaks=False, **kwargs)[source]
Get a list of local extremum points from a 1D array.
- Parameters:
list_data (array_like) – 1D array.
option ({“min”, “max”}) – To get minimum points or maximum points
radius (int) – Search radius. Used to locate extremum points.
sensitive (float) – To detect extremum points against random noise. Smaller is more sensitive.
denoise (bool, optional) – Applying a smoothing filter if True.
norm (bool, optional) – Apply background normalization to the array.
subpixel (bool, optional) – Locate points with subpixel accuracy.
select_peaks (bool, optional) – To select good points based on Gaussian fitting.
**kwargs (optional) – Additional parameters for the method ‘select_good_peaks’
- Returns:
array_like – 1D array. Positions of local extremum points.
- discorpy.prep.linepattern.calc_slope_distance_hor_lines(mat, ratio=0.3, search_range=30.0, radius=9, sensitive=0.1, bgr='bright', denoise=True, norm=True, subpixel=True, chessboard=False, select_peaks=False, **kwargs)[source]
Calculate the representative distance between horizontal lines and the representative slope of these lines using the ROI around the middle of a line-pattern image or a chessboard image.
- Parameters:
mat (array_like) – 2D array.
ratio (float) – Used to select the ROI around the middle of an image.
search_range (float) – Search range in Degree to determine the slope of lines.
radius (int) – Search radius. Used to locate lines.
sensitive (float) – To detect lines against random noise. Smaller is more sensitive.
bgr ({“bright”, “dark”}) – Specify the brightness of the background against the lines.
denoise (bool, optional) – Apply a smoothing filter if True.
norm (bool, optional) – Apply background normalization to the array.
subpixel (bool, optional) – Locate points with subpixel accuracy.
chessboard (bool, optional) – If True, converts the input chessboard image to a line-pattern image.
select_peaks (bool, optional) – To select good points based on Gaussian fitting.
**kwargs (optional) – Additional parameters for the method ‘select_good_peaks’
- Returns:
slope (float) – Slope of horizontal lines in Radian.
distance (float) – Distance between horizontal lines.
- discorpy.prep.linepattern.calc_slope_distance_ver_lines(mat, ratio=0.3, search_range=30.0, radius=9, sensitive=0.1, bgr='bright', denoise=True, norm=True, subpixel=True, chessboard=False, select_peaks=False, **kwargs)[source]
Calculate the representative distance between vertical lines and the representative slope of these lines using the ROI around the middle of a line-pattern image or a chessboard image.
- Parameters:
mat (array_like) – 2D array.
ratio (float) – Used to select the ROI around the middle of an image.
search_range (float) – Search range in Degree to determine the slope of lines.
radius (int) – Search radius. Used to locate lines.
sensitive (float) – To detect lines against random noise. Smaller is more sensitive.
bgr ({“bright”, “dark”}) – Specify the brightness of the background against the lines.
denoise (bool, optional) – Applying a smoothing filter if True.
subpixel (bool, optional) – Locate points with subpixel accuracy.
chessboard (bool, optional) – If True, converts the input chessboard image to a line-pattern image.
select_peaks (bool, optional) – To select good points based on Gaussian fitting.
**kwargs (optional) – Additional parameters for the method ‘select_good_peaks’
- Returns:
slope (float) – Slope of vertical lines in Radian.
distance (float) – Distance between vertical lines.
- discorpy.prep.linepattern.get_tilted_profile(mat, index, angle_deg, direction)[source]
Get the intensity-profile along a tilted line across an image. Positive angle is counterclockwise.
- Parameters:
mat (array_like) – 2D array.
index (int) – Index of the line.
angle_deg (float) – Tilted angle in Degree.
direction ({“horizontal”, “vertical”}) – Direction of line-profile.
- Returns:
xlist (array_like) – 1D array. x-positions of points on the line.
ylist (array_like) – 1D array. y-positions of points on the line.
profile (array_like) – 1D array. Intensities of points on the line.
- discorpy.prep.linepattern.convert_chessboard_to_linepattern(mat, smooth=True, bgr='bright', sigma=3)[source]
Convert a chessboard image to a line-pattern image.
- Parameters:
mat (array_like) – 2D array.
smooth (bool, optional) – Apply a gaussian smoothing filter if True.
bgr ({‘bright’, ‘dark’}) – Select the background of the output image.
sigma (int) – Sigma of the Gaussian window, if smooth is True.
- Returns:
array_like – Line-pattern image.
- discorpy.prep.linepattern.get_cross_points_hor_lines(mat, slope_ver, dist_ver, ratio=0.3, norm=True, offset=0, bgr='bright', radius=11, sensitive=0.1, denoise=True, subpixel=True, chessboard=False, select_peaks=False, **kwargs)[source]
Get points on horizontal lines of a line-pattern image, or a chessboard image, by intersecting with a list of generated vertical-lines.
- Parameters:
mat (array_like) – 2D array.
slope_ver (float) – Representative slope of vertical lines, can be calculated by using the ‘calc_slope_distance_ver_lines’ method.
dist_ver (float) – Representative distance between vertical lines, can be calculated by using the ‘calc_slope_distance_ver_lines’ method.
ratio (float) – To adjust the distance (=ratio * dist_ver) between generated lines to create more or fewer lines.
norm (bool, optional) – Apply background normalization to the array.
offset (int) – Starting index of generated lines.
bgr ({“bright”, “dark”}) – Specify the brightness of the background relative to the lines.
radius (int) – Search radius. Used to locate extremum points.
sensitive (float) – To detect extremum points against random noise. Smaller is more sensitive.
denoise (bool, optional) – Applying a smoothing filter if True.
subpixel (bool, optional) – Locate points with subpixel accuracy.
chessboard (bool, optional) – If True, cross points are located by finding local maxima of slopes of local linear fits of the generated lines.
select_peaks (bool, optional) – To select good points based on Gaussian fitting.
**kwargs (optional) – Additional parameters for the method ‘select_good_peaks’
- Returns:
array_like – List of (y,x)-coordinates of points.
- discorpy.prep.linepattern.get_cross_points_ver_lines(mat, slope_hor, dist_hor, ratio=0.3, norm=True, offset=0, bgr='bright', radius=11, sensitive=0.1, denoise=True, subpixel=True, chessboard=False, select_peaks=False, **kwargs)[source]
Get points on vertical lines of a line-pattern image, or a chessboard image, by intersecting with a list of generated horizontal-lines.
- Parameters:
mat (array_like) – 2D array.
slope_hor (float) – Representative slope of horizontal lines, can be calculated by using the ‘calc_slope_distance_hor_lines’ method.
dist_hor (float) – Representative distance between horizontal lines, can be calculated by using the ‘calc_slope_distance_hor_lines’ method.
ratio (float) – To adjust the distance (=ratio * dist_hor) between generated lines to create more or fewer lines.
norm (bool, optional) – Apply background normalization to the array.
offset (int) – Starting index of generated lines.
bgr ({“bright”, “dark”}) – Specify the brightness of the background against the lines.
radius (int) – Search radius. Used to locate extremum points.
sensitive (float) – To detect extremum points against random noise. Smaller is more sensitive.
denoise (bool, optional) – Applying a smoothing filter if True.
subpixel (bool, optional) – Locate points with subpixel accuracy.
chessboard (bool, optional) – If True, cross points are located by finding local maxima of slopes of local linear fits of the generated lines.
select_peaks (bool, optional) – To select good points based on Gaussian fitting.
**kwargs (optional) – Additional parameters for the method ‘select_good_peaks’
- Returns:
array_like – List of (y,x)-coordinates of points.