cellects.display.image
cellects.display.image
This script contains functions to display images.
display_boxes(binary_image, box_diameter, show=True)
Display grid lines on a binary image at specified box diameter intervals.
This function displays the given binary image with vertical and horizontal
grid lines drawn at regular intervals defined by box_diameter. The function
returns the total number of grid lines drawn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_image
|
ndarray
|
Binary image on which to draw the grid lines. |
required |
box_diameter
|
int
|
Diameter of each box in pixels. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
line_nb |
int
|
Number of grid lines drawn, both vertical and horizontal. |
Examples:
>>> import numpy as np
>>> binary_image = np.random.randint(0, 2, (100, 100), dtype=np.uint8)
>>> display_boxes(binary_image, box_diameter=25)
Source code in src/cellects/display/image.py
display_network_methods(network_detection, save_path=None)
Display segmentation results from a network detection object.
Extended Description
Plots the binary segmentation results for various methods stored in network_detection.all_results.
Highlights the best result based on quality metrics and allows for saving the figure to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
network_detection
|
object
|
An object containing segmentation results and quality metrics. |
required |
save_path
|
str
|
Path to save the figure. If |
None
|
Source code in src/cellects/display/image.py
show(img, interactive=True, cmap=None, axes=True, show=True)
Display a 2D image using Matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
Image data array with shape (height, width) or (height, width, channels). Must be convertible to a NumPy array. |
required | |
interactive
|
bool
|
If |
True
|
cmap
|
Colormap to apply when displaying the image. If |
None
|
|
axes
|
bool
|
When |
True
|
show
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
fig
|
The created Matplotlib |
ax
|
The |
Notes
This function alters Matplotlib's global interactive state, which may
affect subsequent plotting commands. Use interactive=False when
creating figures programmatically to avoid unintended side effects.
Source code in src/cellects/display/image.py
zoom_on_nonzero(binary_image, padding=2, return_coord=True)
Crops a binary image around non-zero elements with optional padding and returns either coordinates or cropped region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_image
|
NDArray
|
2D NumPy array containing binary values (0/1) |
required |
padding
|
int
|
Amount of zero-padding to add around the minimum bounding box |
2
|
return_coord
|
bool
|
If True, return slice coordinates instead of cropped image |
True
|
Returns:
| Type | Description |
|---|---|
If `return_coord` is True: [y_min, y_max, x_min, x_max] as 4-element Tuple.
|
If False: 2D binary array representing the cropped region defined by non-zero elements plus padding. |
Examples:
>>> img = np.zeros((10,10))
>>> img[3:7,4:6] = 1
>>> result = zoom_on_nonzero(img)
>>> print(result)
[1 8 2 7]
>>> cropped = zoom_on_nonzero(img, return_coord=False)
>>> print(cropped.shape)
(6, 5)
Notes
- Returns empty slice coordinates if input contains no non-zero elements.
- Coordinate indices are 0-based and compatible with NumPy array slicing syntax.