Legacy APIs

This page contains the legacy APIs working with OpenHIv1 system.

Image Compatibility

Image compatibility functions preserves interoperability between different versions of OpenHI.

OpenHI Imaging Legacy APIs

Legacy operations related to OpenHIv1.

openhi.img.legacy.get_original(annotator_id: int, slide_id: int, part: int) → numpy.ndarray

Get original image based on annotator, slide, and annotation part

Parameters
  • annotator_id (int) – The annotator ID in the OpenHI system.

  • slide_id (int) – The Slide ID in the OpenHI system.

  • part (int) – represent which part in the slide.

Returns

Original image extracted from WSI.

Return type

ndarray

Image result example
_images/original.png

Raw original image extracted from WSI file.

openhi.img.legacy.get_original_grid(annotator_id: int, slide_id: int, part: int) → numpy.ndarray

Get the original image with visible grid as the annotator sees in OpenHI system.

Parameters
  • annotator_id (int) – The annotator ID in the OpenHI system.

  • slide_id (int) – The Slide ID in the OpenHI system.

  • part (int) – represent which part in the slide.

Returns

Original image extracted from WSI.

Return type

ndarray

Image result example
_images/grid.png

Original image with grid seen by the annotator without annotation.

openhi.img.legacy.get_annotation(annotator_id: int, slide_id: int, part: int) → numpy.ndarray

Get the grading matrix with different grade on it.

Parameters
  • annotator_id (int) – The annotator ID in the OpenHI system.

  • slide_id (int) – The Slide ID in the OpenHI system.

  • part (int) – represent which part in the slide.

Returns

Original image extracted from WSI.

Return type

ndarray

openhi.img.legacy.get_annotation_color(annotator_id: int, slide_id: int, part: int) → numpy.ndarray

Get the original image with annotation as the annotator sees in OpenHI system.

Parameters
  • annotator_id (int) – The annotator ID in the OpenHI system.

  • slide_id (int) – The Slide ID in the OpenHI system.

  • part (int) – represent which part in the slide.

Returns

Original image extracted from WSI.

Return type

ndarray

Image result example
_images/annotation_color.png

Visualized annotation without original image.

openhi.img.legacy.get_annotation_grid(annotator_id: int, slide_id: int, part: int) → numpy.ndarray

Get the original image with visible grid and annotation as the annotator sees in OpenHI system.

Parameters
  • annotator_id (int) – The annotator ID in the OpenHI system.

  • slide_id (int) – The Slide ID in the OpenHI system.

  • part (int) – represent which part in the slide.

Returns

Original image extracted from WSI.

Return type

ndarray

Image result example
_images/original_grid_annotation.png

Original image with grid seen by the annotator with annotations.

SQL Module

OpenHI SQL Module

This module contains functions to deal with OpenHI business with MySQL database.

openhi.legacy.anno_sql.create_connector()

Connect to MySQL server and database based on preset values. Return database object.

Input

This function require the OpenHI configuration file. Example conf can be found at “static/OpenHI_conf.ini”.

Returns

MySQL database object

openhi.legacy.anno_sql.re_create_connector(mydatabase)

If the connection is timeout,then reconnect to MySQL server and database based on preset values. If not,keep the old connection.Return database object.

Returns

MySQL database object

openhi.legacy.anno_sql.check_record_point(db, tl_coor, viewer_size, sobj, dobj, loader, asess)

Insert the recording point validation code in this section

Parameters
  • db

  • tl_coor

  • viewer_size

  • sobj

  • dobj

  • loader

  • asess

Returns

openhi.legacy.anno_sql.record_point2(db, tl_coor, viewer_size, annotator_id, slide_id, dobj, loader, asess)

This function properly records annotation points from the annotator.

Parameters
  • db – database object

  • tl_coor – (1x2 tuple) top-left coordinate

  • viewer_size – (1x2 tuple) the viewing size

  • sobj – static object of OpenHI

  • dobj – dynamic object of OpenHI

  • loader – LoaderConfiguration of OpenHI

  • asess – annotator object of OpenHI

Returns

number of recorded points that have been successfully recorded to MySQL database.

openhi.legacy.anno_sql.get_batch(db, pslv, annotator_id, slide_id)

This function can fetch current maximum annotation batch from the database according to given pslv, annotator, and slide ID.

Parameters
  • db – OpenHI MySQL database connector object

  • pslv – specific pslv that max annotation batch number is needed

  • annotator_id – annotator id

  • slide_id – slide id

Returns

(int) max annotation batch from MySQL database

openhi.legacy.anno_sql.delete_point(db, dobj, loader, annotator_id, slide_id)

Delete annotation point by …

Parameters
  • db

  • dobj

  • loader

  • annotator_id

  • slide_id

Returns

openhi.legacy.anno_sql.search_region(db, xy_coor, pslv, loader, annotator_id, slide_id)

Search region ???

Parameters
  • db

  • xy_coor

  • pslv

  • loader

  • annotator_id

  • slide_id

Returns

openhi.legacy.anno_sql.get_record(db, tl, sz, max_pslv, annotator_id, slide_id)

Get a list of annotated points according to pre-segmentation level

Parameters
  • db – OpenHI database object

  • tl – top-left coordinate

  • sz – size of the viewing area

  • max_pslv (int) – maximum pre-segmentation level

  • annotator_id (int) – annotator id

  • slide_id (int) – slide id

Returns

openhi.legacy.anno_sql.get_tba_list(db, slide_id)

This function will fetch the to be annotated list from the MySQL database based on the give slide id.

Parameters
  • db – OpenHI database object.

  • slide_id – (int) slide id

Returns

(list) tuple of x and y coordinate.

Image processing module

openhi.legacy.anno_img.call_wsi(loader, tl_coor, viewing_size, viewer_size, write_url=False)

This function can be used to load the WSI image with specified coordinates. Version 3 supports calling WSI without reloading OpenSlide pointer object

Parameters
  • loader – WSI loader object

  • tl_coor – top-left coordinate of the desired viewing area

  • viewing_size – specified viewing area size

  • viewer_size – specified output image size to be saved

Returns

Cropped and resized (downsampled) WSI as specified viewing are and viewer size.

openhi.legacy.anno_img.load_bwboundary(full_path, option_show_image=0)

This is a simple function to loads the full logical boundary matrix from the database into the memory

Parameters
  • full_path – (string) Full path to the binary boundary image.

  • option_show_image – (To be depreciated)

Returns

openhi.legacy.anno_img.img_crop(bw, tl_coor, viewer_size, op_show_img=0)

Crop the full binary boundary image according to the given WSI viewing area.

Parameters
  • bw – Full binary boundary image. This can be acquired from the Loader object of each annotator.

  • tl_coor – Top-left coordinate of the viewing area on the WSI.

  • viewer_size – Viewing size.

  • op_show_img – (To be depreciated)

Returns

(np-array) Cropped boundary image of the specified viewing area.

openhi.legacy.anno_img.cvt_point_to_mat(boun_img, point_list_single_pslv)

Convert list of point with grade (x, y, grade) to image surface area with flood-fill operation.

Parameters
  • boun_img – (m-n-1 np-array) boundary image (binary image)

  • point_list_single_pslv – (n-by-3 list) list of point with grade (x, y, grade)

Returns

(np-array) of “boun_img” size

openhi.legacy.anno_img.gen_image_with_annotation(l, coor_tl, size_viewing, size_viewer, write_url, db, anno_id, slide_id, asess, invalid_points, conf)

Use input parameters to generate new viewing image and save to specified path and filename.

Parameters
  • l – WSI-Annotator loader object

  • coor_tl – top-left coordinate of the viewing area

  • size_viewing – size of the viewing image

  • size_viewer – size of the viewer

  • write_url – destination filename

  • db – MySQL database object

  • anno_id – annotator id

  • slide_id – slide id

  • asess – annotation session object

  • invalid_points – (tuple of tuple(s)) input invalid point(s) if exist

  • conf – OpenHI system configuration loaded from the system configuration Python-INI file.

Returns

None

openhi.legacy.anno_img.internal_gen_annotation_export(l: Any, coor_tl, size_viewing, size_viewer, db, anno_id, slide_id, asess, conf, show_hide_grid=False) → Any

Use input parameters to generate new viewing image and save to specified path and filename.

Parameters
  • l – WSI-Annotator loader object

  • coor_tl – top-left coordinate of the viewing area

  • size_viewing – size of the viewing image

  • size_viewer – size of the viewer

  • db – MySQL database object

  • anno_id – annotator id

  • slide_id – slide id

  • asess – annotation session object

  • conf – OpenHI system configuration loaded from the system configuration Python-INI file.

  • show_hide_grid (bool) – option to show or hide grid

Returns

None

openhi.legacy.anno_img.add_grid(img, size_viewing, size_viewer, smallest_allowed_grid, pixel_size=0.25)

This function overlay grid on to the input image. The grid size is made based on the given viewing area value. The pixel size (physical size of the glass slide that was captured by one digital pixel) is set to default of 0.25 micron/pixel which is based on 40x scans. The size of the grid is specified as embedded text on the top-left of the output image.

Parameters
  • img (ndarray) – Full OpenCV-BRG color viewer image for overlaying the grid on.

  • size_viewing – (1x2 list) OpenHI viewing area size.

  • size_viewer – (1x2 list) OpenHI viewer size.

  • pixel_size (float) – (optional: default = 0.25) Physical size of one pixel in micron/pixel. (Typically 0.25 for 40x scan, and 0.5 for 20x scan) Noted that this value can be extracted from the WSI’s metadata.

Returns

Input image with the overlaying grid if the number of grid does not exceed 10 lines while the maximum grid size is 50 um.

openhi.legacy.anno_img.wsi_get_thumbnail(loader, write_url, viewer_size)

Fetch WSI-s thumbnail with this function.

openhi.legacy.anno_img.get_assoc_coor(bwboun_img, tl_coor, seedpoint)

This function get associated coordinates in the same superpixeled sub-region as the specified seedpoint.

Parameters
  • bwboun_img

  • tl_coor

  • seedpoint

Returns

openhi.legacy.anno_img.add_invalid_points(img_to_viewer, coor_tl, size_viewing, size_viewer, invalid_points)

This function add the invalid point annotation to the given resized image (W and H was adjusted to the viewer size). The annotation point will added to the image according to the given ‘invalid_points’. The configuration in the function can be adjusted locally using ‘point_*’ variable.

Parameters
  • img_to_viewer – Final image before viewing at the viewer, noted that the size of this image should be the same as given ‘size_viewer’.

  • coor_tl – current top-left coordinate

  • size_viewing – current viewing size

  • size_viewer – current viewer size

  • invalid_points – (tuple of tuple(s)) invalid points should be given as a tuple of (x, y), hence there are many points, this function will accept a tuple of those points such as ((x_1, y_1), (x_2, y_2), …, (x_n, y_n))

Returns

Original image with invalid points added to the image according to the configuration in this function.

openhi.legacy.anno_img.check_for_overlapping_regions(checking_img, bwboun_img, top_left_coor, seedpoints, grade)

This function will check each point in the given list of seedpoint(s) if it overlaps with current annotations.

Parameters
  • checking_img (ndarray) – multilayer (up to the number of max grading) image of the annotated region. This can be read from web.get_current_annotation()

  • bwboun_img (ndarray) – black-white boundary image showing in the current viewer. This image can be called using img.img_crop(…).

  • top_left_coor – (1x2 tuple) current top-left coordinate.

  • seedpoints – (nx2 tuple) a list of seedpoints that we want to check if overlapping sub-regions for each of them exist. There could be n points to be checked.

  • grade (int) – grade that is needed to be checked.

Returns

the status of each seedpoints. If the seedpoint overlaps with existing annotated region(s), the corresponding location of the list will return 1, and it will return 0 otherwise.

Return type

nx1 tuple

Web module