superdsm.render

class superdsm.render.ContourPaint(fg_mask, radius, where='center')

Bases: object

Yields masks corresponding to contours of objects.

Parameters:
  • fg_mask – Binary mask of the image foreground. Any contour never overlaps the image foreground except of those image regions corresponding to the contoured object itself.

  • radius – The radius of the contour (half width).

  • where – The position of the contour (inner, center, or outer).

get_contour_mask(mask)

Returns the binary mask of the contour of an object.

Parameters:

mask – Binary mask of an object.

Returns:

Binary mask the contour

superdsm.render.colorize_labels(labels, bg_label=0, cmap='gist_rainbow', bg_color=(0, 0, 0), shuffle=None)

Returns a colorized representation of an integer-valued image.

Parameters:
  • labels – An object of type numpy.ndarray corresponding to labeled segmentation masks.

  • bg_label – Image areas with this label are forced to the color bg_color.

  • cmap – The colormap used to colorize the remaining labels (see the list).

  • bg_color – The color used to represent the image regions with label bg_label (RGB).

  • shuffle – If not None, then used as seed to shuffle the labels before colorization (see shuffle_labels()), and not used otherwise.

Returns:

An object of type numpy.ndarray corresponding to an RGB image.

  • _images/bbbc033-z28.png

    Original image (BBBC033).

  • _images/bbbc033-z281.png

    Result of using rasterize_labels() and colorize_labels().

superdsm.render.draw_line(p1, p2, thickness, shape)

Returns binary mask corresponding to a straight line.

Parameters:
  • p1 – Coordinates of the first endpoint of the line.

  • p2 – Coordinates of the second endpoint of the line.

  • thickness – The thickness of the line.

  • shape – The shape of the binary mask to be returned.

Returns:

Binary mask corresponding to the straight line between the two endpoints.

superdsm.render.normalize_image(img, spread=1, ret_minmax=False)

Performs contrast enhancement of an image.

Parameters:
  • img – The image to be enhanced (object of numpy.ndarray type).

  • spread – Governs the amount of enhancement. The lower the value, the stronger the enhancement.

  • ret_minmaxTrue if the clipped image intensities should be returned and False otherwise.

Returns:

The contrast-enhanced image if ret_minmax is False, and a tuple of the structure (img, minval, maxval) if ret_minmax is True, where img is the contrast-enhanced image, and minval and maxval are the clipped image intensities, respectively.

  • _images/bbbc033-z28.png

    Original image (BBBC033).

  • _images/bbbc033-z282.png

    Result of using normalize_image().

superdsm.render.rasterize_labels(data, objects='postprocessed_objects', merge_overlap_threshold=inf, dilate=0, background_label=0)

Returns an integer-valued image corresponding to uniquely labeled segmentation masks.

Parameters:
  • data – The pipeline data object.

  • objects – Either the name of the output which is to be rasterized (see Inputs and outputs), or a list of BaseObject instances.

  • merge_overlap_threshold – Any pair of two objects with an overlap larger than this threshold will be merged into a single object.

  • dilate – Dilates the segmentation mask of each object by this value, or erodes if negative.

  • background_label – The label which is to be assigned to the image background. Must be non-positive.

Returns:

An object of type numpy.ndarray corresponding the uniquely labeled segmentation masks.

superdsm.render.rasterize_objects(data, objects, dilate=0)

Generator which yields the segmentation masks of objects.

Parameters:
  • data – The pipeline data object.

  • objects – Either the name of the output which is to be rasterized (see Inputs and outputs), or a list of BaseObject instances.

  • dilate – Dilates the segmentation mask of each object by this value, or erodes if negative.

superdsm.render.rasterize_regions(regions, background_label=None, radius=3)

Returns the binary masks corresponding to the border of image regions and, optionally, the image background.

Parameters:
  • regions – Integer-valued image (object of numpy.ndarray type) corresponding to the labels of different image regions.

  • background_label – A designated label value, which is to be treated as the image background.

  • radius – The half width of the borders.

Returns:

Tuple of the structure (borders, background), where borders is a binary mask of the borders of the image regions, and background is a binary mask of the union of those regions corresponding to the background_label, if this is not None. Otherwise, background is an binary mask filled with False values.

superdsm.render.render_adjacencies(data, normalize_img=True, edge_thickness=3, endpoint_radius=5, endpoint_edge_thickness=2, edge_color=(1, 0, 0), endpoint_color=(1, 0, 0), endpoint_edge_color=(0, 0, 0), override_img=None)

Returns a visualization of the adjacency graph (see Coarse-to-fine region analysis).

By default, the adjacency graph is rendered on top of the contrast-enhanced raw image itensities. Contrast enhancement is performed using the normalize_image() function.

Parameters:
  • data – The pipeline data object.

  • normalize_imgTrue if contrast-enhancement should be performed and False otherwise. Only used if override_img is None.

  • edge_thickness – The thickness of the edges of the adjacency graph.

  • endpoint_radius – The radius of the nodes of the adjacency graph.

  • endpoint_edge_thickness – The thickness of the border drawn around the nodes of the adjacency graph.

  • edge_color – The color of the edges of the adjacency graph (RGB).

  • endpoint_color – The color of the nodes of the adjacency graph (RGB).

  • endpoint_edge_color – The color of the border drawn around the nodes of the adjacency graph (RGB).

  • override_img – The image on top of which the adjacency graph is to be rendered. If None, the (contrast-enhanced) raw image itensities will be used.

Returns:

An object of type numpy.ndarray corresponding to an RGB image of the adjacency graph.

  • _images/bbbc033-z28.png

    Original image (BBBC033).

  • _images/bbbc033-z283.png

    Result of using render_adjacencies().

superdsm.render.render_atoms(data, normalize_img=True, discarded_color=(0.3, 1, 0.3, 0.1), border_radius=2, border_color=(0, 1, 0), override_img=None)

Returns a visualization of the atomic image regions (see Coarse-to-fine region analysis).

Parameters:
  • data – The pipeline data object.

  • normalize_imgTrue if contrast-enhancement should be performed and False otherwise. Only used if override_img is None.

  • discarded_color – The color of image regions which are entirely discarded from processing (RGBA).

  • border_radius – The half width of the borders of the atomic image regions.

  • border_color – The color of the borders of the atomic image regions (RGB).

  • override_img – The image on top of which the borders of the atomic image regions are to be rendered. If None, the (contrast-enhanced) raw image itensities will be used.

Returns:

An object of type numpy.ndarray corresponding to an RGB image of the atomic image regions.

  • _images/bbbc033-z28.png

    Original image (BBBC033).

  • _images/bbbc033-z284.png

    Result of using render_atoms().

superdsm.render.render_foreground_clusters(data, normalize_img=True, discarded_color=(0.3, 1, 0.3, 0.1), border_radius=2, border_color=(0, 1, 0), override_img=None)

Returns a visualization of regions of possibly clustered objects (see Joint segmentation and cluster splitting).

Parameters:
  • data – The pipeline data object.

  • normalize_imgTrue if contrast-enhancement should be performed and False otherwise. Only used if override_img is None.

  • discarded_color – The color of image regions which are entirely discarded from processing (RGBA).

  • border_radius – The half width of the borders of the regions of possibly clustered objects.

  • border_color – The color of the borders of the regions of possibly clustered objects (RGB).

  • override_img – The image on top of which the borders of the regions of possibly clustered objects are to be rendered. If None, the (contrast-enhanced) raw image itensities will be used.

Returns:

An object of type numpy.ndarray corresponding to an RGB image of the regions of possibly clustered objects.

  • _images/bbbc033-z28.png

    Original image (BBBC033).

  • _images/bbbc033-z285.png

    Result of using render_foreground_clusters().

superdsm.render.render_regions_over_image(img, regions, background_label=None, color=(0, 1, 0), bg=(0.6, 1, 0.6, 0.3), **kwargs)

Returns a visualization of image regions.

Parameters:
  • img – The image on top of which the image regions are to be rendered.

  • regions – Integer-valued image (object of numpy.ndarray type) corresponding to the labels of different image regions.

  • background_label – A designated label value, which is to be treated as the image background.

  • color – The color of the borders of the image regions (RGB).

  • bg – The color of the image regions corresponding to the image background (RGBA). Only used if background_label is not None.

  • kwargs – Keyword arguments passed to the rasterize_regions() function.

Returns:

An object of type numpy.ndarray corresponding to an RGB image of the image regions.

superdsm.render.render_result_over_image(data, objects='postprocessed_objects', merge_overlap_threshold=inf, normalize_img=True, border_width=6, border_position='center', override_img=None, color='g')

Returns a visualization of the segmentation result.

By default, the segmentation result is rendered on top of the contrast-enhanced raw image intensities.

Parameters:
  • data – The pipeline data object.

  • objects – Either the name of the output which is to be treated as the segmentation result (see Inputs and outputs), or a list of BaseObject instances.

  • merge_overlap_threshold – Any pair of two objects with an overlap larger than this threshold will be merged into a single object.

  • normalize_imgTrue if contrast-enhancement should be performed and False otherwise. Only used if override_img is None.

  • border_width – The width of the contour to be drawn around the segmented objects.

  • border_position – The position of the contour to be drawn around the segmented objects (inner, center, or outer).

  • override_img – The image on top of which the contours of the segmented objects are to be rendered. If None, the (contrast-enhanced) raw image itensities will be used.

  • color – The color of the contour to be drawn around the segmented objects (r for red, g for green, b for blue, y for yellow, t for teal, or w for white).

Returns:

An object of type numpy.ndarray corresponding to an RGB image of the segmentation result.

  • _images/bbbc033-z28.png

    Original image (BBBC033).

  • _images/bbbc033-z286.png

    Result of using render_result_over_image().

superdsm.render.render_ymap(data, clim=None, cmap='bwr')

Returns a visualization of the offset image intensities \(Y_\omega|_{\omega = \Omega}\) (see Convex energy minimization).

Parameters:
  • data – The pipeline data object.

  • clim – Tuple of the structure (cmin, cmax), where cmin and cmax are used for intensity clipping. The limits cmin and cmax are chosen automatically if clim is set to None.

  • cmap

    Name of the color map to use for encoding the offset image intensities (see the list).

Returns:

An object of type numpy.ndarray corresponding to an RGB image of the offset image intensities.

  • _images/bbbc033-z28.png

    Original image (BBBC033).

  • _images/bbbc033-z287.png

    Result of using render_ymap().

superdsm.render.shuffle_labels(labels, bg_label=None, seed=None)

Randomly shuffles the values of an integer-valued image.

Parameters:
  • labels – An object of type numpy.ndarray corresponding to labeled segmentation masks.

  • bg_label – If not None, then this label stays fixed.

  • seed – The seed used for randomization.

Returns:

An object of type numpy.ndarray corresponding to labels with shuffled values (labels).