LSDetector#
- class cbclib.LSDetector(data, frames, num_threads, parent, lsd_obj={'ang_th': 45.0, 'density_th': 0.5, 'log_eps': 0.0, 'scale': 0.8999999761581421, 'sigma_scale': 0.8999999761581421, 'quant': 0.019999999552965164}, streaks=<factory>, patterns=None)[source]#
A streak detector class. A class wrapper for streak detection based on Line Segment Detector [LSD] algorithm. Provides an interface to generate an indexing tabular data.
- Parameters
data (
ndarray) – Background corrected detector data.frames (
ndarray) – Frame indices of the detector images.num_threads (
int) – Number of threads used in the calculations.parent (
ReferenceType[CrystData]) – A reference to the parentcbclib.CrystDatacontainer.lsd_obj (
LSD) – a Line Segment Detector object.streaks (
Dict[int,Streaks]) – A dictionary of detectedcbclib.Streaksstreaks.patterns (
Optional[ndarray]) – Normalized diffraction patterns.
- contents()#
Return a list of the attributes stored in the container that are initialised.
- detect(cutoff, filter_threshold=0.0, group_threshold=1.0, dilation=0.0, profile='linear')[source]#
Perform the streak detection. The streak detection comprises three steps: an initial LSD detection of lines, a grouping of the detected lines and merging, if the normalized cross-correlation value if higher than the
group_threshold, discarding the lines with a 0-order image moment lower thanfilter_threshold.- Parameters
cutoff (
float) – Distance cut-off value for lines grouping in pixels.filter_threshold (
float) – Filtering threshold. A line is discarded if the 0-order image moment is lower thanfilter_threshold.group_threshold (
float) – Grouping threshold. The lines are merged if the cross-correlation value of a pair of lines is higher thangroup_threshold.dilation (
float) – Line mask dilation value in pixels.profile (
str) –Line width profiles. The following keyword values are allowed:
tophat : Top-hat (rectangular) function profile.
linear : Linear (triangular) function profile.
quad : Quadratic (parabola) function profile.
gauss : Gaussian function profile.
- Raises
ValueError – If there is no
patternsinside the container.- Return type
LSDetectorFull- Returns
A new
LSDetectorcontainer withstreaksupdated.
- draw(max_val=1, dilation=0.0, profile='tophat')#
Draw a pattern mask by using the detected streaks
streaks.- Parameters
max_val (
int) – Maximal mask valuedilation (
float) – Line mask dilation in pixels.profile (
str) –Line width profiles. The following keyword values are allowed:
tophat : Top-hat (rectangular) function profile.
linear : Linear (triangular) function profile.
quad : Quadratic (parabola) function profile.
gauss : Gaussian function profile.
- Raises
ValueError – If there is no
streaksinside the container.- Return type
- Returns
A pattern mask.
- export_streaks()#
Export
streak_maskto the parentcbclib.CrystDatadata container.- Raises
ValueError – If there is no
streaksinside the container.ValueError – If there is no
streak_maskinside the container.
- export_table(dilation=0.0, concatenate=True)#
Export normalised pattern into a
pandas.DataFrametable.- Parameters
- Raises
ValueError – If there is no
streaksinside the container.- Return type
- Returns
List of
pandas.DataFrametables for each frame inframesifconcatenateis False, a singlepandas.DataFrameotherwise. Table contains the following information:frames : Frame index.
x, y : Pixel coordinates.
p : Normalised pattern values.
rp : Reflection profiles.
I_raw : Measured intensity.
bgd : Background values.
- generate_patterns(vmin, vmax, size=(1, 3, 3))[source]#
Generate a set of normalised diffraction patterns
patternsbased on taking a 2D median filter of background corrected detector imagesdataand clipping the values to a (vmin,vmax) interval.- Parameters
- Raises
ValueError – If
vmaxis less thanvmin.- Return type
- Returns
A new
cbclib.LSDetectorcontainer withpatternsupdated.
- get(attr, value=None)#
Retrieve a dataset, return
valueif the attribute is not found.
- items()#
Return (key, value) pairs of the datasets stored in the container.
- Return type
- Returns
(key, value) pairs of the datasets stored in the container.
- keys()#
Return a list of the attributes available in the container.
- mask_frames(idxs)#
Choose a subset of frames stored in the container and return a new detector object.
- refine_streaks(dilation=0.0)#
Refine detected diffraction streaks by fitting a Gaussian across the line.
- replace(**kwargs)#
Return a new container object with a set of attributes replaced.
- to_dataframe(concatenate=True)#
Export detected streak lines
streaksto apandas.DataFrametable.- Parameters
concatenate (
bool) – Concatenate sets of streaks for each frame into a single table if True.- Raises
ValueError – If there is no
streaksinside the container.- Return type
- Returns
List of
pandas.DataFrametables for each frame inframesifconcatenateis False, a singlepandas.DataFrameotherwise. Table contains the following information:frames : Frame index.
streaks : Line index.
x0, y0, x1, y1 : Line point coordinates in pixels.
width : Line width.
length : Line length.
- update_lsd(scale=0.9, sigma_scale=0.9, log_eps=0.0, ang_th=45.0, density_th=0.5, quant=0.02)[source]#
Return a new
LSDetectorobject with updatedcbclib.bin.LSDdetector.- Parameters
scale (
float) – When different from 1.0, LSD will scale the input image by ‘scale’ factor by Gaussian filtering, before detecting line segments.sigma_scale (
float) – Whenscaleis different from 1.0, the sigma of the Gaussian filter issigma = sigma_scale / scale, if scale is less than 1.0, andsigma = sigma_scaleotherwise.log_eps (
float) – Detection threshold, accept if -log10(NFA) > log_eps. The larger the value, the more strict the detector is, and will result in less detections. The value -log10(NFA) is equivalent but more intuitive than NFA: * -1.0 gives an average of 10 false detections on noise. * 0.0 gives an average of 1 false detections on noise. * 1.0 gives an average of 0.1 false detections on nose. * 2.0 gives an average of 0.01 false detections on noise.ang_th (
float) – Gradient angle tolerance in the region growing algorithm, in degrees.density_th (
float) – Minimal proportion of ‘supporting’ points in a rectangle.quant (
float) – Bound to the quantization error on the gradient norm. Example: if gray levels are quantized to integer steps, the gradient (computed by finite differences) error due to quantization will be bounded by 2.0, as the worst case is when the error are 1 and -1, that gives an error of 2.0.
- Return type
- Returns
A new
LSDetectorwith the updatedlsd_obj.
- update_patterns(dilations=(1.0, 3.0, 7.0))#
Return a new detector object with updated normalised CBC patterns. The image is segmented into two region around each reflection to calculate the local background and local peak intensity. The estimated values are used to normalise each diffraction streak separately.
- Parameters
dilations (
Tuple[float,float,float]) –A tuple of three dilations (d0, d1, d2) in pixels of the streak mask that is used to define the inner and outer streak zones:
The inner zone is based on the mask dilated by d0.
The outer zone is based on the difference between a mask dilated by d2 and by d1.
- Return type
- Returns
A new detector object with updated
patterns.
- values()#
Return the attributes’ data stored in the container.
- Return type
- Returns
List of data stored in the container.