Processing data
Here, we provide functionalities designed specifically for 3D image analysis and processing. From filter pipelines to structure tensor computation and blob detection, qim3d
equips you with the tools you need to extract meaningful insights from your data.
qim3d.processing
qim3d.processing.structure_tensor
structure_tensor(vol, sigma=1.0, rho=6.0, base_noise=True, full=False, visualize=False, **viz_kwargs)
Wrapper for the 3D structure tensor implementation from the structure_tensor package.
The structure tensor algorithm is a method for analyzing the orientation of fiber-like structures in 3D images. The core of the algorithm involves computing a 3-by-3 matrix at each point in a volume, capturing the local orientation. This matrix, known as the structure tensor, is derived from the gradients of the image intensities and integrates neighborhood information using Gaussian kernels.
The implementation here used allows for fast and efficient computation using GPU-based processing, making it suitable for large datasets. This efficiency is particularly advantageous for high-resolution imaging techniques like X-ray computed microtomography (μCT).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vol |
ndarray
|
3D NumPy array representing the volume. |
required |
sigma |
float
|
A noise scale, structures smaller than sigma will be removed by smoothing. Defaults to 1.0. |
1.0
|
rho |
float
|
An integration scale giving the size over the neighborhood in which the orientation is to be analysed. Defaults to 6.0. |
6.0
|
base_noise |
bool
|
A flag indicating whether to add a small noise to the volume. Default is True. |
True
|
full |
bool
|
A flag indicating that all three eigenvalues should be returned. Default is False. |
False
|
visualize |
bool
|
Whether to visualize the structure tensor. Default is False. |
False
|
**viz_kwargs |
Any
|
Additional keyword arguments for passed to |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If the input volume is not 3D. |
Returns:
Name | Type | Description |
---|---|---|
val |
ndarray
|
An array with shape |
vec |
ndarray
|
An array with shape |
Example
Runtime and memory usage of the structure tensor method for different volume sizes
Performance computed on Intel(R) Xeon(R) Gold 6226 CPU @ 2.70GHz.
Reference
Jeppesen, N., et al. "Quantifying effects of manufacturing methods on fiber orientation in unidirectional composites using structure tensor analysis." Composites Part A: Applied Science and Manufacturing 149 (2021): 106541. https://doi.org/10.1016/j.compositesa.2021.106541
@article{JEPPESEN2021106541,
title = {Quantifying effects of manufacturing methods on fiber orientation in unidirectional composites using structure tensor analysis},
journal = {Composites Part A: Applied Science and Manufacturing},
volume = {149},
pages = {106541},
year = {2021},
issn = {1359-835X},
doi = {https://doi.org/10.1016/j.compositesa.2021.106541},
url = {https://www.sciencedirect.com/science/article/pii/S1359835X21002633},
author = {N. Jeppesen and L.P. Mikkelsen and A.B. Dahl and A.N. Christensen and V.A. Dahl}
}
Source code in qim3d/processing/_structure_tensor.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
qim3d.processing.local_thickness
Wrapper for the local thickness function from the local thickness package
The "Fast Local Thickness" by Vedrana Andersen Dahl and Anders Bjorholm Dahl from the Technical University of Denmark is a efficient algorithm for computing local thickness in 2D and 3D images. Their method significantly reduces computation time compared to traditional algorithms by utilizing iterative dilation with small structuring elements, rather than the large ones typically used. This approach allows the local thickness to be determined much faster, making it feasible for high-resolution volumetric data that are common in contemporary 3D microscopy.
Testing against conventional methods and other Python-based tools like PoreSpy shows that the new algorithm is both accurate and faster, offering significant improvements in processing time for large datasets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
ndarray
|
2D or 3D NumPy array representing the image/volume. If binary, it will be passed directly to the local thickness function. If grayscale, it will be binarized using Otsu's method. |
required |
scale |
float
|
Downscaling factor, e.g. 0.5 for halving each dim of the image. Default is 1. |
1
|
mask |
ndarray or None
|
Binary mask of the same size of the image defining parts of the image to be included in the computation of the local thickness. Default is None. |
None
|
visualize |
bool
|
Whether to visualize the local thickness. Default is False. |
False
|
**viz_kwargs |
Any
|
Additional keyword arguments passed to |
{}
|
Returns:
Name | Type | Description |
---|---|---|
local_thickness |
ndarray
|
2D or 3D NumPy array representing the local thickness of the input image/volume. |
Example
Runtime and memory usage of the local thickness method for different volume sizes
Performance computed on Intel(R) Xeon(R) Gold 6226 CPU @ 2.70GHz.
Reference
Dahl, V. A., & Dahl, A. B. (2023, June). Fast Local Thickness. 2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW). https://doi.org/10.1109/cvprw59228.2023.00456
@inproceedings{Dahl_2023, title={Fast Local Thickness},
url={http://dx.doi.org/10.1109/CVPRW59228.2023.00456},
DOI={10.1109/cvprw59228.2023.00456},
booktitle={2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition Workshops (CVPRW)},
publisher={IEEE},
author={Dahl, Vedrana Andersen and Dahl, Anders Bjorholm},
year={2023},
month=jun }
Source code in qim3d/processing/_local_thickness.py
qim3d.processing.get_lines
Expects list of arrays where each array is 2D segmentation with only 2 classes. This function gets the border between those two so it could be plotted. Used with qim3d.processing.segment_layers
Parameters:
Name | Type | Description | Default |
---|---|---|---|
segmentations |
list of arrays
|
List of arrays where each array is 2D segmentation with only 2 classes |
required |
Returns:
Name | Type | Description |
---|---|---|
segmentation_lines |
list
|
List of 1D numpy arrays |
Source code in qim3d/processing/_layers.py
qim3d.processing.segment_layers
segment_layers(data, inverted=False, n_layers=1, delta=1, min_margin=10, max_margin=None, wrap=False)
Works on 2D and 3D data. Light one function wrapper around slgbuilder https://github.com/Skielex/slgbuilder to do layer segmentation Now uses only MaxflowBuilder for solving.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ndarray
|
2D or 3D array on which it will be computed |
required |
inverted |
bool
|
If True, it will invert the brightness of the image. Defaults to False |
False
|
n_layers |
int
|
Determines amount of layers to look for (result in a layer and background). Defaults to 1. |
1
|
delta |
float
|
Patameter determining smoothness. Defaults to 1. |
1
|
min_margin |
int or None
|
Parameter for minimum margin. If more layers are wanted, a margin is necessary to avoid layers being identical. Defaults to None. |
10
|
max_margin |
int or None
|
Parameter for maximum margin. If more layers are wanted, a margin is necessary to avoid layers being identical. Defaults to None. |
None
|
wrap |
bool
|
If True, starting and ending point of the border between layers are at the same level. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
segmentations |
list[ndarray]
|
list of numpy arrays, even if n_layers == 1, each array is only 0s and 1s, 1s segmenting this specific layer |
Raises:
Type | Description |
---|---|
TypeError
|
If Data is not np.array, if n_layers is not integer. |
ValueError
|
If n_layers is less than 1, if delta is negative or zero |
Example
Example is only shown on 2D image, but segment_layers can also take 3D structures.
import qim3d
layers_image = qim3d.io.load('layers3d.tif')[:,:,0]
layers = qim3d.processing.segment_layers(layers_image, n_layers = 2)
layer_lines = qim3d.processing.get_lines(layers)
import matplotlib.pyplot as plt
plt.imshow(layers_image, cmap='gray')
plt.axis('off')
for layer_line in layer_lines:
plt.plot(layer_line, linewidth = 3)