sparkocr.utils#

Functions

compare_versions(version1, version2)

Compare two version strings using the packaging module.

display_dicom(df[, fields, limit, width, ...])

display_image(image[, width, show_meta, id])

display_images(df[, field, limit, width, ...])

display_images_horizontal(df[, fields, ...])

display_markup(df)

display_pdf(df[, field, limit, width, show_meta])

display_table(table_col, chunks[, empty_val])

display_tables(df[, table_col, ...])

Display table.

display_xmls(df[, table_col, ...])

ensure_packages_installed(packages)

Ensure a list of packages (or a single package) is installed.

generate_dicom_mapping(df, original_col, ...)

Return mapping of old and new dicom identifiers.

get_name(path[, keep_subfolder_level])

get_packbits_func()

get_pixel_handler_func()

get_read_dicom_func()

get_vocabulary_dict(filename, delimeter)

get_xml(df[, table_col, table_index_col, ...])

polygon_mask(shape, polygon)

Helper function to generate final bbox coordinates and mask for rotated/non-rotated angles.

remove_dependency_from_traceback(...)

remove_large_objects(ar[, max_size, ...])

Remove objects greater than the specified size.

rotate_boxes(cx, cy, width, height, angle)

Helper function to rotate boxes from ImageTextDetector and ImageTextDetectorV2.

save_table_to_csv(df, fname)

save_tables_to_csv(df)

singh_threshold(img[, w_size, k])

Runs the Singh thresholding algorithm

split_bylen(item, maxlen)

3 Requires item to be sliceable (with __getitem__ defined)

to_opencv_image(image)

to_pil_image(image, mode)

to_xml(chunks[, empty_val])

wolf_threshold(img[, w_size, k])

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

display_pdf_file(pdf[, size])

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