sparkocr.utils#
Functions
|
Compare two version strings using the packaging module. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Display table. |
|
|
|
Ensure a list of packages (or a single package) is installed. |
|
Return mapping of old and new dicom identifiers. |
|
|
|
|
|
|
|
Helper function to generate final bbox coordinates and mask for rotated/non-rotated angles. |
|
Remove objects greater than the specified size. |
|
Helper function to rotate boxes from ImageTextDetector and ImageTextDetectorV2. |
|
|
|
Runs the Singh thresholding algorithm |
|
3 Requires item to be sliceable (with __getitem__ defined) |
|
|
|
|
|
|
|
Runs the Wolf's thresholding algorithm. Reference: C. Wolf, J-M. Jolion, “Extraction and Recognition of Artificial Text in Multimedia Documents”, Pattern Analysis and Applications, 6(4):309-326, (2003). Modifications: Using integral images to compute the local mean and the standard deviation @param img: The input image @type img: ndarray @param w_size: The size of the local window to compute each pixel threshold. Should be and odd value @type w_size: int @param k: Controls the value of the local threshold. @type k: float. |
Classes
|
- compare_versions(version1: str, version2: str) int#
Compare two version strings using the packaging module.
- Parameters:
version1 – First version string (e.g. “3.2.1”)
version2 – Second version string (e.g. “3.3.0”)
- Returns:
-1 if version1 is older, 1 if version1 is newer, 0 if both versions are equal
- display_tables(df, table_col='table', table_index_col=None, empty_val='Empty')#
Display table.
Keyword arguments: table_col – name of column with table data table_index_col – name of column with table index on that page
- ensure_packages_installed(packages)#
Ensure a list of packages (or a single package) is installed.
- generate_dicom_mapping(df, original_col, final_col)#
Return mapping of old and new dicom identifiers.
:param df : Dataframe containing original and cleaned metadata :param original_col : Dataframe column containing original metadata :param final_col : Dataframe column containing cleaned metadata :return {“uid_mapping” : {old_uid:new_uid}, “patient_mapping” : {old_patid:new_patid}
- polygon_mask(shape, polygon)#
Helper function to generate final bbox coordinates and mask for rotated/non-rotated angles. Applied in DicomDrawRegions after rotate_boxes() function.
- remove_large_objects(ar, max_size=64, connectivity=1, in_place=False)#
Remove objects greater than the specified size.
Expects ar to be an array with labeled objects, and removes objects largest than max_size. If ar is bool, the image is first labeled. This leads to potentially different behavior for bool and 0-and-1 arrays.
- Parameters:
ar (ndarray (arbitrary shape, int or bool type)) – The array containing the objects of interest. If the array type is int, the ints must be non-negative.
max_size (int, optional (default: 64)) – The largest allowable object size.
connectivity (int, {1, 2, ..., ar.ndim}, optional (default: 1)) – The connectivity defining the neighborhood of a pixel. Used during labelling if ar is bool.
in_place (bool, optional (default: False)) – If
True, remove the objects in the input array itself. Otherwise, make a copy.
- Returns:
out – The input array with small connected components removed.
- Return type:
ndarray, same shape and type as input ar
- rotate_boxes(cx, cy, width, height, angle)#
Helper function to rotate boxes from ImageTextDetector and ImageTextDetectorV2.
- singh_threshold(img, w_size=15, k=0.85)#
Runs the Singh thresholding algorithm
Reference: Singh, O. I., Sinam, T., James, O., & Singh, T. R. (2012). Local contrast and mean based thresholding technique in image binarization. International Journal of Computer Applications, 51, 5-10. Modifications: Using integral images to compute local mean
and standard deviation
@param img: The input image @type img: ndarray @param w_size: The size of the local window to compute
each pixel threshold. Should be and odd value
@type w_size: int @param k: Controls the value of the local threshold. It lies in the
interval [0, 1]
@type k: float @return: The estimated local threshold for each pixel @rtype: ndarray
- split_bylen(item, maxlen)#
3 Requires item to be sliceable (with __getitem__ defined)
- wolf_threshold(img, w_size=15, k=0.5)#
Runs the Wolf’s thresholding algorithm. Reference: C. Wolf, J-M. Jolion, “Extraction and Recognition of Artificial Text in Multimedia Documents”, Pattern Analysis and Applications, 6(4):309-326, (2003). Modifications: Using integral images to compute the local mean and the standard deviation @param img: The input image @type img: ndarray @param w_size: The size of the local window to compute
each pixel threshold. Should be and odd value
@type w_size: int @param k: Controls the value of the local threshold. @type k: float
@return: The estimated local threshold for each pixel @rtype: ndarray