This module provides functions to segmentate an image into superpixels. It is largely based on the scikit-image toolbox. Apart from the regular segmentation functions it provides postprocessing functions to ensure connected segments in a regular grid. It also provides various visualization tools for segmented images.
Average colors per superpixels
Returns an image where each pixel has the average color of the superpixel that it belongs to.
Parameters: |
|
---|---|
Returns: | NxM or NxMx3 matrix with averaged image |
Return type: | np.ndarray |
Checks if segmentation data is complete
Checks if the segmentation data indeed contains nx*ny segments and if the set of segment numbers is continuous.
Parameters: |
|
---|---|
Returns: | Returns true if segmentation is valid and false otherwise |
Return type: | bool |
Return contours of superpixels
Parameters: | segments (np.ndarray) – NxM matrix with segment numbering |
---|---|
Returns: | list of lists for each segment in segments. Each segment list contains one or more contours. Each contour is defined by a list of 2-tuples with an x and y coordinate. |
Return type: | list |
Examples
>>> contours = get_contours(segments)
>>> plot(contours[0][0][0][0], contours[0][0][0][1]) # plot first contour of first segment
Return segmentation of image
Parameters: |
|
---|---|
Returns: | NxM matrix with segment numbering |
Return type: | np.ndarray |
Examples
>>> img = argus2.rest.get_image(station='kijkduin')[0]
>>> segments = get_segmentation(img)
Return shape of superpixels grid
Parameters: |
|
---|---|
Returns: | tuple containing M and N dimension of regular superpixel grid |
Return type: | 2-tuple |
Shuffle class identifiers
Parameters: | img (np.ndarray) – NxM matrix with segment numbering |
---|---|
Returns: | NxM matrix with shuffled segment numbering |
Return type: | np.ndarray |
Examples
>>> seg = get_segmentation(img)
>>> fig, axs = plt.subplots(1, 2)
>>> axs[0].imshow(seg)
>>> axs[1].imshow(shuffle_pixels(seg))
Simple region growing algorithm
Parameters: |
|
---|---|
Returns: |
|
Create a regular grid from a collection of image segments
The number of segments supplied is supposed to be larger than the number of segments in the target grid (nx*ny). A regular grid of size nx*ny over the image grid NxM is constructed. Subsequently, the segments are ordered based on size. the nx*ny largest segments are preserved and assigned to a single grid cell in the regular grid based on least squares fit. The smaller segments are added to the preserved segment that is closest based on their centroids.
Parameters: |
|
---|---|
Returns: | NxM matrix with alternative segment numbering with segments in a regular grid |
Return type: | np.ndarray |
Remove disjoint regions in segmentation
Remove disjoint regions in segmentation by running a region growing algorihtm for each segment. Any segment that appears to consist out of multiple disconnected parts is splitted. The biggest part remains as placeholder of the existing superpixel. The smaller parts are joined with the neighbouring superpixels. If multiple neighbouring superpixels exist, the one that shares the largest border is chosen.
Parameters: | segments (np.ndarray) – NxM matrix with segment numbering |
---|---|
Returns: | NxM matrix with alternative segment numbering with connected segments |
Return type: | np.ndarray |
Get binary image data
Parameters: |
|
---|---|
Returns: | Binary image data |
Return type: | str |
Plot segmentation result
Parameters: |
|
---|---|
Returns: | Binary image data or 2-tuple with matplotlib.figure.Figure and matplotlib.axes.AxesSubplot objects |
Return type: | str or 2-tuple |
Get binary image data
Parameters: |
|
---|---|
Returns: | Binary image data or 2-tuple with matplotlib.figure.Figure and matplotlib.axes.AxesSubplot objects |
Return type: | str or 2-tuple |