Masks from meshes (2D)¶
Rebuild an approximate label image from a compressed segmentation (a 2-D mesh, its seeds and the image shape).
The rebuild draws every mesh edge into a pixel mask (Bresenham's line between the two ends, each rounded to the nearest pixel centre), then grows one region per seed by a watershed on the distance to the drawn lines. It is an approximation: measured on one shipped mask, 95.6 % of the pixels agree with the mask the mesh was built from. dw3d's rebuild of a 3-D mask is exact; dw2d's is not, yet.
The names mirror dw3d's: reconstruct_mask_from_dict(dictionary) and reconstruct_mask_from_saved_file_dict(filename).
reconstruct_mask_from_dict ¶
reconstruct_mask_from_dict(dict_mask: dict, plot: bool = False) -> NDArray[np.int64]
Rebuild an approximate label image from a compressed segmentation dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dict_mask
|
dict
|
the dictionary |
required |
plot
|
bool
|
draw the result with matplotlib. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
NDArray[int64]
|
NDArray[np.int64]: the label image; the seed at row |
reconstruct_mask_from_saved_file_dict ¶
reconstruct_mask_from_saved_file_dict(filename: str | Path) -> NDArray[np.int64]
Rebuild an approximate label image from a compressed segmentation saved with dw2d.save_compressed_segmentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str | Path
|
the |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int64]
|
NDArray[np.int64]: the label image, as |