imsegm.utilities.drawing module

Framework for visualisations

Copyright (C) 2016-2018 Jiri Borovec <jiri.borovec@fel.cvut.cz>

imsegm.utilities.drawing._draw_disk(x, y, r, shape)[source]

Wrapper for drawing circle/disk invariant to scikit-image

Parameters
  • x – center X

  • y – center Y

  • r – radius

  • shape – plane shape

Returns

image

>>> im = np.zeros((8, 12), dtype=int)
>>> x, y = _draw_disk(4, 6, 5, shape=im.shape)
>>> im[x, y] = 1
>>> im
array([[0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0]])
imsegm.utilities.drawing._ellipse(r, c, r_radius, c_radius, orientation=0.0, shape=None)[source]

temporary wrapper until release New version scikit-image v0.13

Parameters
  • r (int) – center position in rows

  • c (int) – center position in columns

  • r_radius (int) – ellipse diam in rows

  • c_radius (int) – ellipse diam in columns

  • orientation (float) – ellipse orientation

  • shape (tuple(int,int)) – size of output mask

Return tuple(list(int),list(int))

indexes of filled positions

>>> img = np.zeros((10, 12), dtype=int)
>>> rr, cc = _ellipse(5, 6, 3, 5, orientation=np.deg2rad(30))
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
imsegm.utilities.drawing.closest_point_on_line(start, end, point)[source]

projection of the point to the line

Parameters
  • start (list(int)) – line starting point

  • end (list(int)) – line ending point

  • point (list(int)) – point for extimation

Return list(int)

point on the line

>>> closest_point_on_line([0, 0], [1, 2], [0, 2])
array([ 0.8,  1.6])
imsegm.utilities.drawing.create_figure_by_image(img_size, subfig_size, nb_subfigs=1, extend=0.0)[source]

crearting image according backround_image

Parameters
  • img_size (tuple(int,int)) – image size

  • subfig_size (float) – maximal sub-figure size

  • nb_subfigs (int) – number of sub-figure

  • extend (float) – extension

Return tuple(Figure,list)

imsegm.utilities.drawing.draw_color_labeling(segments, lut_labels)[source]

visualise the graph cut results

Parameters
  • segments (ndarray) – np.array<height, width>

  • lut_labels (list(int)) – look-up-table

Return ndarray

np.array<height, width, 3>

imsegm.utilities.drawing.draw_eggs_ellipse(mask_shape, pos_ant, pos_lat, pos_post, threshold_overlap=0.6)[source]

from given 3 point estimate the ellipse

Parameters
Return ndarray

>>> pos_ant, pos_lat, pos_post = [10, 10], [20, 20], [35, 20]
>>> points = np.array([pos_ant, pos_lat, pos_post])
>>> _= plt.plot(points[:, 0], points[:, 1], 'og')
>>> mask = draw_eggs_ellipse([30, 50], [pos_ant], [pos_lat], [pos_post])
>>> mask.shape
(30, 50)
>>> _= plt.imshow(mask, alpha=0.5, interpolation='nearest')
>>> _= plt.xlim([0, mask.shape[1]]), plt.ylim([0, mask.shape[0]]), plt.grid()
>>> # plt.show()
imsegm.utilities.drawing.draw_eggs_rectangle(mask_shape, pos_ant, pos_lat, pos_post)[source]

from given 3 point estimate the ellipse

Parameters
Return list(ndarray)

>>> pos_ant, pos_lat, pos_post = [10, 10], [20, 20], [35, 20]
>>> points = np.array([pos_ant, pos_lat, pos_post])
>>> _= plt.plot(points[:, 0], points[:, 1], 'og')
>>> masks = draw_eggs_rectangle([30, 50], [pos_ant], [pos_lat], [pos_post])
>>> [m.shape for m in masks]
[(30, 50)]
>>> for mask in masks:
...     _= plt.imshow(mask, alpha=0.5, interpolation='nearest')
>>> _= plt.xlim([0, mask.shape[1]]), plt.ylim([0, mask.shape[0]]), plt.grid()
>>> # plt.show()
imsegm.utilities.drawing.draw_graphcut_unary_cost_segments(segments, unary_cost)[source]

visualise the unary cost for each class

Parameters
  • segments (ndarray) – np.array<height, width>

  • unary_cost (ndarray) – np.array<nb_spx, nb_classes>

Return []

[np.array<height, width, 3>] * nb_cls

>>> seg = np.random.randint(0, 100, (100, 150))
>>> u_cost = np.random.random((100, 3))
>>> imgs = draw_graphcut_unary_cost_segments(seg, u_cost)
>>> len(imgs)
3
>>> [img.shape for img in imgs]
[(100, 150, 3), (100, 150, 3), (100, 150, 3)]
imsegm.utilities.drawing.draw_graphcut_weighted_edges(segments, centers, edges, edge_weights, img_bg=None, img_alpha=0.5)[source]

visualise the edges on the overlapping a background image

Parameters
  • centers ([tuple(int,int)]) – list of centers

  • segments (ndarray) – np.array<height, width>

  • edges (ndarray) – list of edges of shape <nb_edges, 2>

  • edge_weights (ndarray) – weight per edge <nb_edges, 1>

  • img_bg (ndarray) – image background

  • img_alpha (float) – transparency

Return ndarray

np.array<height, width, 3>

>>> slic = np.array([[0] * 3 + [1] * 3 + [2] * 3+ [3] * 3] * 4 +
...                 [[4] * 3 + [5] * 3 + [6] * 3 + [7] * 3] * 4)
>>> centres = [[1, 1], [1, 4], [1, 7], [1, 10],
...            [5, 1], [5, 4], [5, 7], [5, 10]]
>>> edges = [[0, 1], [1, 2], [2, 3], [0, 4], [1, 5],
...          [4, 5], [2, 6], [5, 6], [3, 7], [6, 7]]
>>> img = np.random.randint(0, 256, slic.shape + (3,))
>>> edge_weights = np.ones(len(edges))
>>> edge_weights[0] = 0
>>> img = draw_graphcut_weighted_edges(slic, centres, edges, edge_weights, img_bg=img)
>>> img.shape
(8, 12, 3)
imsegm.utilities.drawing.draw_image_clusters_centers(ax, img, centres, points=None, labels_centre=None, segm=None)[source]

draw imageas bacround and clusters centers

Parameters
  • ax – figure axis

  • img (ndarray) – image

  • centres (ndarray) – points

  • points (ndarray) – optional list of all points

  • labels_centre (list(int)) – optional list of labels for points

  • segm (ndarray) – optional segmentation

>>> img = np.random.randint(0, 256, (100, 100, 3))
>>> seg = np.random.randint(0, 3, (100, 100))
>>> centres = np.random.randint(0, 100, (3, 2))
>>> points = np.random.randint(0, 100, (25, 2))
>>> labels = np.random.randint(0, 4, 25)
>>> draw_image_clusters_centers(plt.Figure().gca(), img[:, :, 0], centres, points, labels, seg)
imsegm.utilities.drawing.draw_image_segm_points(ax, img, points, labels=None, slic=None, color_slic='w', lut_label_marker={- 1: ('.', '#7E7E7E'), 0: ('x', '#7E7E7E'), 1: ('.', '#FFFB00')}, seg_contour=None)[source]
on plane draw background image or segmentation, overlap with SLIC

contours, add contour of adative segmentation like annot. for centers plot point with specific property (shape and colour) according label

Parameters
  • ax – figure axis

  • img (ndarray) – image

  • points (list(tuple(int,int))) – collection of points

  • labels (list(int)) – LUT labels for superpixels

  • slic (ndarray) – superpixel segmentation

  • color_slic (str) – color dor superpixels

  • lut_label_marker (dict) – dictionary {int: (str, str)} of label and markers

  • seg_contour (ndarray) – segmentation contour

>>> img = np.random.randint(0, 256, (100, 100))
>>> points = np.random.randint(0, 100, (25, 2))
>>> labels = np.random.randint(0, 5, len(points))
>>> slic = np.random.randint(0, 256, (100, 100))
>>> draw_image_segm_points(plt.Figure().gca(), img, points, labels, slic)
imsegm.utilities.drawing.draw_rg2sp_results(ax, seg, slic, debug_rg2sp, iter_index=- 1)[source]

drawing Region Growing with shape prior

Parameters
  • ax – figure axis

  • seg (ndarray) – segmentation

  • slic (ndarray) – superpixels

  • debug_rg2sp (dict) – dictionary with debug results

  • iter_index (int) – iteration index

Returns

ax

imsegm.utilities.drawing.ellipse(r, c, r_radius, c_radius, orientation=0.0, shape=None)[source]

temporary wrapper until release New version scikit-image v0.13

Note

Should be solved in skimage v0.13

Parameters
  • r (int) – center position in rows

  • c (int) – center position in columns

  • r_radius (int) – ellipse diam in rows

  • c_radius (int) – ellipse diam in columns

  • orientation (float) – ellipse orientation

  • shape (tuple(int,int)) – size of output mask

Return tuple(list(int),list(int))

indexes of filled positions

>>> img = np.zeros((14, 20), dtype=int)
>>> rr, cc = ellipse(7, 10, 3, 9, np.deg2rad(30), img.shape)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
imsegm.utilities.drawing.ellipse_perimeter(r, c, r_radius, c_radius, orientation=0.0, shape=None)[source]

see New version scikit-image v0.14

Note

Should be solved in skimage v0.14

Parameters
  • r (int) – center position in rows

  • c (int) – center position in columns

  • r_radius (int) – ellipse diam in rows

  • c_radius (int) – ellipse diam in columns

  • orientation (float) – ellipse orientation

  • shape (tuple(int,int)) – size of output mask

Return tuple(list(int),list(int))

indexes of filled positions

>>> img = np.zeros((14, 20), dtype=int)
>>> rr, cc = ellipse_perimeter(7, 10, 3, 9, np.deg2rad(30), img.shape)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
imsegm.utilities.drawing.figure_annot_slic_histogram_labels(dict_label_hist, slic_size=- 1, slic_regul=- 1)[source]

plot ration of labels assigned to each superpixel

Parameters
  • dict_label_hist – dictionary of label name and histogram

  • slic_size (int) – used for figure title

  • slic_regul (float) – used for figure title

Return Figure

>>> np.random.seed(0)
>>> dict_label_hist = {'a': np.tile([1, 0, 0, 0, 1], (25, 1)),
...                    'b': np.tile([0, 1, 0, 0, 1], (30, 1))}
>>> fig = figure_annot_slic_histogram_labels(dict_label_hist)
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_ellipse_fitting(img, seg, ellipses, centers, crits, fig_size=9)[source]

show figure with result of the ellipse fitting

Parameters
  • img (ndarray) – image

  • seg (ndarray) – segmentation

  • ellipses (list(tuple(int,int,int,int,float))) – collection of ellipse parameters ell. parameters: (x, y, height, width, orientation)

  • centers (list(tuple(int,int))) – points

  • crits (list(float)) –

  • fig_size (float) – maximal figure size

Return Figure

>>> img = np.random.random((100, 150, 3))
>>> seg = np.random.randint(0, 2, (100, 150))
>>> ells = np.random.random((3, 5)) * 25
>>> centers = np.random.random((3, 2)) * 25
>>> crits = np.random.random(3)
>>> fig = figure_ellipse_fitting(img[:, :, 0], seg, ells, centers, crits)
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_image_adjustment(fig, img_size)[source]

adjust figure as nice image without axis

Parameters
  • fig – Figure

  • img_size (tuple(int,int)) – image size

Return Figure

>>> fig = figure_image_adjustment(plt.figure(), (150, 200))
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_image_segm_centres(img, segm, centers=None, cmap_contour=<matplotlib.colors.LinearSegmentedColormap object>)[source]

visualise the input image and segmentation in common frame

Parameters
  • img (ndarray) – image

  • segm (ndarray) – segmentation

  • centers ([tuple(int,int)]|ndarray) – or np.array

  • cmap_contour (obj) –

Return Figure

>>> img = np.random.random((100, 150, 3))
>>> seg = np.random.randint(0, 2, (100, 150))
>>> centre = [[55, 60]]
>>> fig = figure_image_segm_centres(img, seg, centre)
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_image_segm_results(img, seg, subfig_size=9, mid_labels_alpha=0.2, mid_image_gray=True)[source]

creating subfigure with original image, overlapped segmentation contours and clean result segmentation… it turns the sequence in vertical / horizontal according major image dim

Parameters
  • img (ndarray) – image as background

  • seg (ndarray) – segmentation

  • subfig_size (int) – max image size

  • mid_image_gray (fool) – used color image as bacround in middele

  • mid_labels_alpha (float) – alpha for middle segmentation overlap

Return Figure

>>> img = np.random.random((100, 150, 3))
>>> seg = np.random.randint(0, 2, (100, 150))
>>> fig = figure_image_segm_results(img, seg)
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_overlap_annot_segm_image(annot, segm, img=None, subfig_size=9, drop_labels=None, segm_alpha=0.2)[source]

figure showing overlap annotation - segmentation - image

Parameters
  • annot (ndarray) – user annotation

  • segm (ndarray) – segmentation

  • img (ndarray) – original image

  • subfig_size (int) – maximal sub-figure size

  • segm_alpha (float) – use transparency

  • drop_labels (list(int)) – labels to be ignored

Return Figure

>>> img = np.random.random((100, 150, 3))
>>> seg = np.random.randint(0, 2, (100, 150))
>>> fig = figure_overlap_annot_segm_image(seg, seg, img, drop_labels=[5])
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_ray_feature(segm, points, ray_dist_raw=None, ray_dist=None, points_reconst=None, title='')[source]

visualise the segmentation with specific point and estimated ray dist.

Parameters
  • segm (ndarray) – segmentation

  • points (list(tuple(float,float))) – collection of points

  • ray_dist_raw (list(float)) –

  • ray_dist (list(float)) – Ray feature distances

  • points_reconst (ndarray) – collection of reconstructed points

  • title (str) – figure title

Return Figure

Note

for more examples, see unittests

imsegm.utilities.drawing.figure_rg2sp_debug_complete(seg, slic, debug_rg2sp, iter_index=- 1, max_size=5)[source]

draw figure with all debug (intermediate) segmentation steps

Parameters
  • seg (ndarray) – segmentation

  • slic (ndarray) – superpixels

  • debug_rg2sp – dictionary with some debug parameters

  • iter_index (int) – iteration index

  • max_size (int) – max figure size

Return Figure

>>> seg = np.random.randint(0, 4, (100, 150))
>>> slic = np.random.randint(0, 80, (100, 150))
>>> dict_debug = {
...     'lut_data_cost': np.random.random((80, 3)),
...     'lut_shape_cost': np.random.random((15, 80, 3)),
...     'labels': np.random.randint(0, 4, (15, 80)),
...     'centres': [np.array([np.random.randint(0, 100, 80),
...                           np.random.randint(0, 150, 80)]).T] * 15,
...     'shifts': np.random.random((15, 3)),
...     'criteria': np.random.random(15),
... }
>>> fig = figure_rg2sp_debug_complete(seg, slic, dict_debug)
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_segm_boundary_dist(segm_ref, segm, subfig_size=9)[source]

visualise the boundary distances between two segmentation

Parameters
  • segm_ref (ndarray) – reference segmentation

  • segm (ndarray) – estimated segmentation

  • subfig_size (int) – maximal sub-figure size

Return Figure

>>> seg = np.zeros((100, 100))
>>> seg[35:80, 10:65] = 1
>>> fig = figure_segm_boundary_dist(seg, seg.T)
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_segm_graphcut_debug(images, subfig_size=9)[source]

creating subfigure with slic, graph edges and results in the first row and individual class unary terms in the second row

Parameters
  • images (dict) – dictionary composed from name and image array

  • subfig_size (int) – maximal sub-figure size

Return Figure

>>> images = {
...     'image': np.random.random((100, 150, 3)),
...     'slic': np.random.randint(0, 2, (100, 150)),
...     'slic_mean': np.random.random((100, 150, 3)),
...     'img_graph_edges': np.random.random((100, 150, 3)),
...     'img_graph_segm': np.random.random((100, 150, 3)),
...     'imgs_unary_cost': [np.random.random((100, 150, 3))],
... }
>>> fig = figure_segm_graphcut_debug(images)
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.figure_used_samples(img, labels, slic, used_samples, fig_size=12)[source]

draw used examples (superpixels)

Parameters
  • img (ndarray) – input image for background

  • labels (list(int)) – labels associated for superpixels

  • slic (ndarray) – superpixel segmentation

  • used_samples (list(bool)) – used samples for training

  • fig_size (int) – figure size

Return Figure

>>> img = np.random.random((50, 75, 3))
>>> labels = [-1, 0, 2]
>>> used = [1, 0, 0]
>>> seg = np.random.randint(0, 3, img.shape[:2])
>>> fig = figure_used_samples(img, labels, seg, used)
>>> isinstance(fig, matplotlib.figure.Figure)
True
imsegm.utilities.drawing.make_overlap_images_chess(images, chess_field=50)[source]

overlap images and show them

Parameters
  • images (list(ndarray)) – collection of images

  • chess_field (int) – size of chess field size

Return ndarray

combined image

>>> im1 = np.zeros((5, 10), dtype=int)
>>> im2 = np.ones((5, 10), dtype=int)
>>> make_overlap_images_chess([im1, im2], chess_field=2)
array([[0, 0, 1, 1, 0, 0, 1, 1, 0, 0],
       [0, 0, 1, 1, 0, 0, 1, 1, 0, 0],
       [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
       [1, 1, 0, 0, 1, 1, 0, 0, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
imsegm.utilities.drawing.make_overlap_images_optical(images)[source]

overlap images and show them

Parameters

images (list(ndarray)) – collection of images

Return ndarray

combined image

>>> im1 = np.zeros((5, 8), dtype=float)
>>> im2 = np.ones((5, 8), dtype=float)
>>> make_overlap_images_optical([im1, im2])
array([[ 0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5],
       [ 0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5],
       [ 0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5],
       [ 0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5],
       [ 0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5,  0.5]])
imsegm.utilities.drawing.merge_object_masks(masks, overlap_thr=0.7)[source]

merge several mask into one multi-class segmentation

Parameters
  • masks (list(ndarray)) – collection of masks

  • overlap_thr (float) – threshold for overlap

Return ndarray

>>> m1 = np.zeros((5, 6), dtype=int)
>>> m1[:4, :4] = 1
>>> m2 = np.zeros((5, 6), dtype=int)
>>> m2[2:, 2:] = 1
>>> merge_object_masks([m1, m1])
array([[1, 1, 1, 1, 0, 0],
       [1, 1, 1, 1, 0, 0],
       [1, 1, 1, 1, 0, 0],
       [1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0]])
>>> merge_object_masks([m1, m2])
array([[1, 1, 1, 1, 0, 0],
       [1, 1, 1, 1, 0, 0],
       [1, 1, 2, 2, 2, 2],
       [1, 1, 2, 2, 2, 2],
       [0, 0, 2, 2, 2, 2]])
imsegm.utilities.drawing.norm_aplha(alpha)[source]

normalise alpha in range (0, 1)

Parameters

alpha (float) –

Return float

>>> norm_aplha(0.5)
0.5
>>> norm_aplha(255)
1.0
>>> norm_aplha(-1)
0
imsegm.utilities.drawing.parse_annot_rectangles(rows_slice)[source]

parse annotation fromDF to lists

Parameters

rows_slice – a row from a table

Return tuple

the three points

>>> import pandas as pd
>>> dict_row = dict(ant_x=1, ant_y=2, lat_x=3, lat_y=4, post_x=5, post_y=6)
>>> row = pd.DataFrame([dict_row])
>>> parse_annot_rectangles(row)
([(1, 2)], [(3, 4)], [(5, 6)])
>>> rows = pd.DataFrame([dict_row, {n: dict_row[n] + 10 for n in dict_row}])
>>> rows
   ant_x  ant_y  lat_x  lat_y  post_x  post_y
0      1      2      3      4       5       6
1     11     12     13     14      15      16
>>> parse_annot_rectangles(rows)
([(1, 2), (11, 12)], [(3, 4), (13, 14)], [(5, 6), (15, 16)])
imsegm.utilities.drawing.COLUMNS_POSITION_EGG_ANNOT = ('ant_x', 'ant_y', 'post_x', 'post_y', 'lat_x', 'lat_y')[source]

columns from description files which marks the egg annotation by expert

imsegm.utilities.drawing.DICT_LABEL_MARKER = {-1: ('.', '#7E7E7E'), 0: ('x', '#7E7E7E'), 1: ('.', '#FFFB00')}[source]

define markers for labels of positive (+1) neutral (0) and negative (-1) class

imsegm.utilities.drawing.SIZE_CHESS_FIELD = 50[source]

for blending two images define chess field size in pixels