Data Processing
Basic data processing functions are provided in the data_processing
module. These functions are used to preprocess data before training a model, or to post-process the output of a model.
Generic Functions
plantseg.dataprocessing.functional.dataprocessing.normalize_01(data: np.ndarray) -> np.ndarray
Normalize a numpy array between 0 and 1 and converts it to float32.
Parameters:
-
data
(ndarray
) –Input numpy array
Returns:
-
normalized_data
(ndarray
) –Normalized numpy array
Source code in plantseg/dataprocessing/functional/dataprocessing.py
164 165 166 167 168 169 170 171 172 173 174 |
|
plantseg.dataprocessing.functional.dataprocessing.scale_image_to_voxelsize(image: np.ndarray, input_voxel_size: tuple[float, float, float], output_voxel_size: tuple[float, float, float], order: int = 0) -> np.ndarray
Scale an image from a given voxel size to another voxel size.
Parameters:
-
image
(ndarray
) –Input image to scale
-
input_voxel_size
(tuple[float, float, float]
) –Input voxel size
-
output_voxel_size
(tuple[float, float, float]
) –Output voxel size
-
order
(int
, default:0
) –Interpolation order, must be 0 for segmentation and 1, 2 for images
Returns:
-
scaled_image
(ndarray
) –Scaled image as numpy array
Source code in plantseg/dataprocessing/functional/dataprocessing.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
plantseg.dataprocessing.functional.dataprocessing.image_rescale(image: np.ndarray, factor: tuple[float, float, float], order: int) -> np.ndarray
Scale an image by a given factor in each dimension
Parameters:
-
image
(ndarray
) –Input image to scale
-
factor
(tuple[float, float, float]
) –Scaling factor in each dimension
-
order
(int
) –Interpolation order, must be 0 for segmentation and 1, 2 for images
Returns:
-
scaled_image
(ndarray
) –Scaled image as numpy array
Source code in plantseg/dataprocessing/functional/dataprocessing.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
plantseg.dataprocessing.functional.dataprocessing.image_median(image: np.ndarray, radius: int) -> np.ndarray
Apply median smoothing on an image with a given radius.
Parameters:
Returns:
-
median_image
(ndarray
) –Median smoothed image as numpy array
Source code in plantseg/dataprocessing/functional/dataprocessing.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
plantseg.dataprocessing.functional.dataprocessing.image_gaussian_smoothing(image: np.ndarray, sigma: float) -> np.ndarray
Apply gaussian smoothing on an image with a given sigma.
Parameters:
-
image
(ndarray
) –Input image to apply gaussian smoothing
-
sigma
(float
) –Sigma value for gaussian smoothing
Returns:
-
smoothed_image
(ndarray
) –Gaussian smoothed image as numpy array
Source code in plantseg/dataprocessing/functional/dataprocessing.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
plantseg.dataprocessing.functional.dataprocessing.image_crop(image: np.ndarray, crop_str: str) -> np.ndarray
Crop an image from a crop string like [:, 10:30:, 10:20]
Parameters:
Returns:
-
cropped_image
(ndarray
) –Cropped image as numpy array
Source code in plantseg/dataprocessing/functional/dataprocessing.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
Segmentation Functions
plantseg.dataprocessing.functional.labelprocessing.relabel_segmentation(segmentation_image: np.ndarray) -> np.ndarray
Relabel contiguously a segmentation image, non-touching instances with same id will be relabeled differently. To be noted that measure.label is different from ndimage.label.
Parameters:
-
segmentation_image
(ndarray
) –segmentation image to relabel
Returns:
-
new_segmentation_image
(ndarray
) –relabeled segmentation image
Source code in plantseg/dataprocessing/functional/labelprocessing.py
5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
plantseg.dataprocessing.functional.labelprocessing.set_background_to_value(segmentation_image: np.ndarray, value: int = 0) -> np.ndarray
Set the largest segment (usually this is the background but not always) to a certain value.
Parameters:
-
segmentation_image
(ndarray
) –segmentation image to relabel
-
value
(int
, default:0
) –value to set the background to, default is 0
Returns:
-
new_segmentation_image
(ndarray
) –segmentation image with background set to value
Source code in plantseg/dataprocessing/functional/labelprocessing.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
Advanced Functions
Documentation in Progress
This page is under development.