cuisto.seg
seg module, part of cuisto.
Functions for segmentating probability map stored as an image.
convert_to_pixels(filters, pixelsize)
#
Convert some values in filters
in pixels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
dict
|
Must contain the keys used below. |
required |
pixelsize
|
float
|
Pixel size in microns. |
required |
Returns:
Name | Type | Description |
---|---|---|
filters |
dict
|
Same as input, with values in pixels. |
Source code in cuisto/seg.py
erode_mask(mask, edge_dist)
#
Erode the mask outline so that is is edge_dist
smaller from the border.
This allows discarding the edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mask
|
ndarray
|
|
required |
edge_dist
|
float
|
Distance to edges, in pixels. |
required |
Returns:
Name | Type | Description |
---|---|---|
eroded_mask |
ndarray of bool
|
|
Source code in cuisto/seg.py
get_collection_from_points(coords, properties, rescale_factor=1.0, offset=0.5)
#
Gather coordinates from coords
and put them in GeoJSON format.
An entry in coords
are pairs of (x, y) coordinates defining the point.
properties
is a dictionnary with QuPath properties of each detections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coords
|
list
|
|
required |
properties
|
dict
|
|
required |
rescale_factor
|
float
|
Rescale output coordinates by this factor. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
collection |
FeatureCollection
|
|
Source code in cuisto/seg.py
get_collection_from_poly(contours, properties, rescale_factor=1.0, offset=0.5)
#
Gather coordinates in the list and put them in GeoJSON format as Polygons.
An entry in contours
must define a closed polygon. properties
is a dictionnary
with QuPath properties of each detections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
contours
|
list
|
|
required |
properties
|
dict
|
QuPatj objects' properties. |
required |
rescale_factor
|
float
|
Rescale output coordinates by this factor. |
1.0
|
offset
|
float
|
Shift coordinates by this amount, typically to get pixel centers or edges. Default is 0.5. |
0.5
|
Returns:
Name | Type | Description |
---|---|---|
collection |
FeatureCollection
|
A FeatureCollection ready to be written as geojson. |
Source code in cuisto/seg.py
get_collection_from_skel(skeleton, properties, rescale_factor=1.0, offset=0.5)
#
Get the coordinates of each skeleton path as a GeoJSON Features in a
FeatureCollection.
properties
is a dictionnary with QuPath properties of each detections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
skeleton
|
Skeleton
|
|
required |
properties
|
dict
|
QuPatj objects' properties. |
required |
rescale_factor
|
float
|
Rescale output coordinates by this factor. |
1.0
|
offset
|
float
|
Shift coordinates by this amount, typically to get pixel centers or edges. Default is 0.5. |
0.5
|
Returns:
Name | Type | Description |
---|---|---|
collection |
FeatureCollection
|
A FeatureCollection ready to be written as geojson. |
Source code in cuisto/seg.py
get_image_skeleton(img, minsize=0)
#
Get the image skeleton.
Computes the image skeleton and removes objects smaller than minsize
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray of bool
|
|
required |
minsize
|
number
|
Min. size the object can have, as a number of pixels. Default is 0. |
0
|
Returns:
Name | Type | Description |
---|---|---|
skel |
ndarray of bool
|
Binary image with 1-pixel wide skeleton. |
Source code in cuisto/seg.py
get_pixelsize(image_name)
#
Get pixel size recorded in image_name
TIFF metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_name
|
str
|
Full path to image. |
required |
Returns:
Name | Type | Description |
---|---|---|
pixelsize |
float
|
Pixel size in microns. |
Source code in cuisto/seg.py
pad_image(img, finalsize)
#
Pad image with zeroes to match expected final size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray
|
|
required |
finalsize
|
tuple or list
|
nrows, ncolumns |
required |
Returns:
Name | Type | Description |
---|---|---|
imgpad |
ndarray
|
img with black borders. |
Source code in cuisto/seg.py
segment_lines(img, geojson_props, minsize=0.0, rescale_factor=1.0)
#
Wraps skeleton analysis to get paths coordinates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray of bool
|
Binary image to segment as lines. |
required |
geojson_props
|
dict
|
GeoJSON properties of objects. |
required |
minsize
|
float
|
Minimum size in pixels for an object. |
0.0
|
rescale_factor
|
float
|
Rescale output coordinates by this factor. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
collection |
FeatureCollection
|
A FeatureCollection ready to be written as geojson. |
Source code in cuisto/seg.py
segment_points(img, geojson_props, area_min=0.0, area_max=np.inf, ecc_min=0, ecc_max=1, dist_thresh=0, rescale_factor=1)
#
Point segmentation.
First, segment polygons to apply shape filters, then extract their centroids,
and remove isolated points as defined by dist_thresh
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray of bool
|
Binary image to segment as points. |
required |
geojson_props
|
dict
|
GeoJSON properties of objects. |
required |
area_min
|
float
|
Minimum and maximum area in pixels for an object. |
0.0
|
area_max
|
float
|
Minimum and maximum area in pixels for an object. |
0.0
|
ecc_min
|
float
|
Minimum and maximum eccentricity for an object. |
0
|
ecc_max
|
float
|
Minimum and maximum eccentricity for an object. |
0
|
dist_thresh
|
float
|
Maximal distance in pixels between objects before considering them as isolated and remove them. 0 disables it. |
0
|
rescale_factor
|
float
|
Rescale output coordinates by this factor. |
1
|
Returns:
Name | Type | Description |
---|---|---|
collection |
FeatureCollection
|
A FeatureCollection ready to be written as geojson. |
Source code in cuisto/seg.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
|
segment_polygons(img, geojson_props, area_min=0.0, area_max=np.inf, ecc_min=0.0, ecc_max=1.0, rescale_factor=1.0)
#
Polygon segmentation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
img
|
ndarray of bool
|
Binary image to segment as polygons. |
required |
geojson_props
|
dict
|
GeoJSON properties of objects. |
required |
area_min
|
float
|
Minimum and maximum area in pixels for an object. |
0.0
|
area_max
|
float
|
Minimum and maximum area in pixels for an object. |
0.0
|
ecc_min
|
float
|
Minimum and maximum eccentricity for an object. |
0.0
|
ecc_max
|
float
|
Minimum and maximum eccentricity for an object. |
0.0
|
rescale_factor
|
float
|
Rescale output coordinates by this factor. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
collection |
FeatureCollection
|
A FeatureCollection ready to be written as geojson. |