Functions for marking up label images using a trained model

Setup environment

Imports

Define directories

img_path = Path('nbs_test_data')
mrk_path = Path('nbs_test_data/markup')  
mrk_path.mkdir(parents=True, exist_ok=True)
fnames = sorted(get_image_files(img_path))
fn = fnames[1]
fn
PosixPath('nbs_test_data/236568 - 10.jpg')
fnames
[PosixPath('nbs_test_data/235443 - 1.jpg'),
 PosixPath('nbs_test_data/236568 - 10.jpg')]

utilities

padImage_t[source]

padImage_t(img, pad=100)

cut_tiles_t[source]

cut_tiles_t(img, TM=4, TN=4, pad=100)

lay_tiles_t[source]

lay_tiles_t(tiles, TM=4, TN=4, pad=100)

run_prediction[source]

run_prediction(learn, fn, filesavedir=None, tile=False, pad=100)

run predictions and return dictionary of raw predictions

  • learn: learner to use
  • fn: filename
  • filesavedir: if set will save to this directory
  • tile: use tiling or not
  • pad: padding factor for tiling
  • return rediction tensor
print("Class Labels")
CLASS_LABELS
Class Labels
{'Background': {'Code': '0', 'Fill': (0, 0, 0, 127)},
 'Liver Fluke': {'Code': '11', 'Fill': (255, 0, 0, 127)},
 'Rumen Fluke': {'Code': '40', 'Fill': (0, 255, 0, 127)},
 'Other': {'Code': '255', 'Fill': (0, 0, 255, 127)}}

find_prediction_blobs[source]

find_prediction_blobs(img, CONF=0.5, min_area=500, offset=0)

plot the prediction blobs on an image

Test find_prediction_blobs( cls, img, min_conf=0.1, min_area=100)

 find_prediction_blobs( cls, img,  min_conf=0.1, min_area=100)

annotate_json[source]

annotate_json(data, shape_type='circle', points=None)

calc_probs[source]

calc_probs(raw_pred:tensor)

Calculate the probabilities from a raw prediction raw_pred by finding the average value of all the pixels within a region This assumes that there is only one cell in the image

  • raw_pred: the raw predictions from the learner
  • return: list of probabilities

draw_labels_cv[source]

draw_labels_cv(img, json, radius=20)

markup_one_image[source]

markup_one_image(fn:str, preds:dict)