Generating synthetic data
The qim3d
library provides a set of methods for generating volumes consisting of a single synthetic blob or a collection of multiple synthetic blobs.
qim3d.generate
qim3d.generate.blob
blob(base_shape=(128, 128, 128), final_shape=(128, 128, 128), noise_scale=0.05, order=1, gamma=1.0, max_value=255, threshold=0.5, smooth_borders=False, dtype='uint8')
Generate a 3D volume with Perlin noise, spherical gradient, and optional scaling and gamma correction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_shape |
tuple
|
Shape of the initial volume to generate. Defaults to (128, 128, 128). |
(128, 128, 128)
|
final_shape |
tuple
|
Desired shape of the final volume. Defaults to (128, 128, 128). |
(128, 128, 128)
|
noise_scale |
float
|
Scale factor for Perlin noise. Defaults to 0.05. |
0.05
|
order |
int
|
Order of the spline interpolation used in resizing. Defaults to 1. |
1
|
gamma |
float
|
Gamma correction factor. Defaults to 1.0. |
1.0
|
max_value |
int
|
Maximum value for the volume intensity. Defaults to 255. |
255
|
threshold |
float
|
Threshold value for clipping low intensity values. Defaults to 0.5. |
0.5
|
smooth_borders |
bool
|
Flag for automatic computation of the threshold value to ensure a blob with no straight edges. If True, the |
False
|
dtype |
str
|
Desired data type of the output volume. Defaults to "uint8". |
'uint8'
|
Returns:
Name | Type | Description |
---|---|---|
synthetic_blob |
ndarray
|
Generated 3D volume with specified parameters. |
Raises:
Type | Description |
---|---|
TypeError
|
If |
ValueError
|
If |
Example
Source code in qim3d/generate/blob_.py
5 6 7 8 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 116 117 118 |
|
qim3d.generate.collection
collection(collection_shape=(200, 200, 200), num_objects=15, positions=None, min_shape=(40, 40, 40), max_shape=(60, 60, 60), object_shape_zoom=(1.0, 1.0, 1.0), min_object_noise=0.02, max_object_noise=0.05, min_rotation_degrees=0, max_rotation_degrees=360, rotation_axes=[(0, 1), (0, 2), (1, 2)], min_gamma=0.8, max_gamma=1.2, min_high_value=128, max_high_value=255, min_threshold=0.5, max_threshold=0.6, smooth_borders=False, seed=0, verbose=False)
Generate a 3D volume of multiple synthetic objects using Perlin noise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
collection_shape |
tuple
|
Shape of the final collection volume to generate. Defaults to (200, 200, 200). |
(200, 200, 200)
|
num_objects |
int
|
Number of synthetic objects to include in the collection. Defaults to 15. |
15
|
positions |
list[tuple]
|
List of specific positions as (z, y, x) coordinates for the objects. If not provided, they are placed randomly into the collection. Defaults to None. |
None
|
min_shape |
tuple
|
Minimum shape of the objects. Defaults to (40, 40, 40). |
(40, 40, 40)
|
max_shape |
tuple
|
Maximum shape of the objects. Defaults to (60, 60, 60). |
(60, 60, 60)
|
object_shape_zoom |
tuple
|
Scaling factors for each dimension of each object. Defaults to (1.0, 1.0, 1.0). |
(1.0, 1.0, 1.0)
|
min_object_noise |
float
|
Minimum scale factor for Perlin noise. Defaults to 0.02. |
0.02
|
max_object_noise |
float
|
Maximum scale factor for Perlin noise. Defaults to 0.05. |
0.05
|
min_rotation_degrees |
int
|
Minimum rotation angle in degrees. Defaults to 0. |
0
|
max_rotation_degrees |
int
|
Maximum rotation angle in degrees. Defaults to 360. |
360
|
rotation_axes |
list[tuple]
|
List of axis pairs that will be randomly chosen to rotate around. Defaults to [(0, 1), (0, 2), (1, 2)]. |
[(0, 1), (0, 2), (1, 2)]
|
min_gamma |
float
|
Minimum gamma correction factor. Defaults to 0.8. |
0.8
|
max_gamma |
float
|
Maximum gamma correction factor. Defaults to 1.2. |
1.2
|
min_high_value |
int
|
Minimum maximum value for the volume intensity. Defaults to 128. |
128
|
max_high_value |
int
|
Maximum maximum value for the volume intensity. Defaults to 255. |
255
|
min_threshold |
float
|
Minimum threshold value for clipping low intensity values. Defaults to 0.5. |
0.5
|
max_threshold |
float
|
Maximum threshold value for clipping low intensity values. Defaults to 0.6. |
0.6
|
smooth_borders |
bool
|
Flag for smoothing blob borders to avoid straight edges in the objects. If True, the |
False
|
seed |
int
|
Seed for reproducibility. Defaults to 0. |
0
|
verbose |
bool
|
Flag to enable verbose logging. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
synthetic_collection |
ndarray
|
3D volume of the generated collection of synthetic objects with specified parameters. |
labels |
ndarray
|
Array with labels for each voxel, same shape as synthetic_collection. |
Raises:
Type | Description |
---|---|
TypeError
|
If |
ValueError
|
If blob parameters are invalid. |
Note
- The function places objects without overlap.
- The function can either place objects at random positions in the collection (if
positions = None
) or at specific positions provided in thepositions
argument. If specific positions are provided, the number of blobs must match the number of positions (e.g.num_objects = 2
withpositions = [(12, 8, 10), (24, 20, 18)]
). - If not all
num_objects
can be placed, the function returns thesynthetic_collection
volume with as many blobs as possible in it, and logs an error. - Labels for all objects are returned, even if they are not a sigle connected component.
Example
Example
import qim3d
# Generate synthetic collection of dense blobs
synthetic_collection, labels = qim3d.generate.collection(
min_high_value = 255,
max_high_value = 255,
min_object_noise = 0.05,
max_object_noise = 0.05,
min_threshold = 0.99,
max_threshold = 0.99,
min_gamma = 0.02,
max_gamma = 0.02)
# Visualize synthetic collection
qim3d.viz.vol(synthetic_collection)
Example
import qim3d
# Generate synthetic collection of tubular structures
synthetic_collection, labels = qim3d.generate.collection(
num_objects=10,
collection_shape=(200,100,100),
min_shape = (190, 50, 50),
max_shape = (200, 60, 60),
object_shape_zoom = (1, 0.2, 0.2),
min_object_noise = 0.01,
max_object_noise = 0.02,
max_rotation_degrees=10,
min_threshold = 0.95,
max_threshold = 0.98,
min_gamma = 0.02,
max_gamma = 0.03
)
# Visualize synthetic collection
qim3d.viz.vol(synthetic_collection)
Source code in qim3d/generate/collection_.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
|