Synthetic data generation
qim3d.generate
Generation for synthetic datasets.
qim3d.generate.ParameterVisualizer
Class for visualizing and experimenting with parameter changes and combinations on synthetic data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_shape |
tuple
|
Determines the shape of the generate volume. This will not be update when exploring parameters and must be determined when generating the visualizer. |
(128, 128, 128)
|
seed |
int
|
Determines the seed for the volume generation. Enables the user to generate different volumes with the same parameters. |
0
|
initial_config |
dict
|
Dictionary that defines the starting parameters of the visualizer. Can be used if a specific setup is needed. The dictionary may contain the keywords: |
None
|
nsmin |
float
|
Determines minimum value for the noise scale slider. Defaults to 0.0. |
0.0
|
nsmax |
float
|
Determines maximum value for the noise scale slider. Defaults to 0.1. |
0.1
|
dsmin |
float
|
Determines minimum value for the decay rate slider. Defaults to 0.1. |
0.1
|
dsmax |
float
|
Determines maximum value for the decay rate slider. Defaults to 20. |
20.0
|
gsmin |
float
|
Determines minimum value for the gamma slider. Defaults to 0.1. |
0.1
|
gsmax |
float
|
Determines maximum value for the gamma slider. Defaults to 2.0. |
2.0
|
tsmin |
float
|
Determines minimum value for the threshold slider. Defaults to 0.0. |
0.0
|
tsmax |
float
|
Determines maximum value for the threshold slider. Defaults to 1.0. |
1.0
|
grid_visible |
bool
|
Determines if the grid should be visible upon plot generation. Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
ValueError
|
If base_shape is invalid. |
ValueError
|
If noise slider values are invalid. |
ValueError
|
If decay slider values are invalid. |
ValueError
|
If gamma slider values are invalid. |
ValueError
|
If threshold slider values are invalid. |
Example
import qim3d
viz = qim3d.generate.ParameterVisualizer(base_shape=(128,128,128), seed=0, grid_visible=True)

Source code in qim3d/generate/_generators.py
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 |
|
qim3d.generate.volume
volume(base_shape=(128, 128, 128), final_shape=None, noise_scale=0.02, noise_type='perlin', decay_rate=10, gamma=1, threshold=0.5, max_value=255, shape=None, tube_hole_ratio=0.5, axis=0, order=1, dtype='uint8', hollow=0, seed=0)
Generate a 3D volume with Perlin noise, spherical gradient, and optional scaling and gamma correction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_shape |
tuple of ints
|
Shape of the initial volume to generate. Defaults to (128, 128, 128). |
(128, 128, 128)
|
final_shape |
tuple of ints
|
Desired shape of the final volume. If unspecified, will assume same shape as base_shape. Defaults to None. |
None
|
noise_scale |
float
|
Scale factor for Perlin noise. Defaults to 0.05. |
0.02
|
noise_type |
str
|
Type of noise to be used for volume generation. Should be |
'perlin'
|
decay_rate |
float
|
The decay rate of the fading of the noise. Can also be interpreted as the sharpness of the edge of the volume. Defaults to 5.0. |
10
|
gamma |
float
|
Applies gamma correction, adjusting contrast in the volume. If gamma<0, the volume intensity is increased and if gamma>0 it's decreased. Defaults to 0. |
1
|
threshold |
float
|
Threshold value for clipping low intensity values. Defaults to 0.5. |
0.5
|
max_value |
int
|
Maximum value for the volume intensity. Defaults to 255. |
255
|
shape |
str
|
Shape of the volume to generate, either |
None
|
tube_hole_ratio |
float
|
Ratio for the inverted fade mask used to generate tubes. Will only have an effect if shape= |
0.5
|
axis |
int
|
Axis of the given volume_shape. Will only be active if volume_shape is defined. Defaults to 0. |
0
|
order |
int
|
Order of the spline interpolation used in resizing. Defaults to 1. |
1
|
dtype |
data - type
|
Desired data type of the output volume. Defaults to |
'uint8'
|
hollow |
bool
|
Determines thickness of the hollowing operation. Volume is only hollowed if hollow>0. Defaults to 0. |
0
|
seed |
int
|
Specifies a fixed offset for the generated noise. Only works for perlin noise. Defaults to 0. |
0
|
Returns:
Name | Type | Description |
---|---|---|
volume |
ndarray
|
Generated 3D volume with specified parameters. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
TypeError
|
If |
TypeError
|
If |
TypeError
|
If |
ValueError
|
If |
Example
Example:
import qim3d
# Generate synthetic blob
vol = qim3d.generate.volume(noise_scale = 0.02)
# Visualize 3D volume
qim3d.viz.volumetric(vol)

Example
import qim3d
# Generate tubular synthetic blob
vol = qim3d.generate.volume(base_shape = (200, 100, 100),
final_shape = (400,100,100),
noise_scale = 0.03,
threshold = 0.85,
decay_rate=20,
gamma=0.15,
shape = "tube",
tube_hole_ratio = 0.4,
)
# Visualize synthetic volume
qim3d.viz.volumetric(vol)

Example
import qim3d
# Generate tubular synthetic blob
vol = qim3d.generate.volume(base_shape = (200, 100, 100),
final_shape = (400, 100, 100),
noise_scale = 0.03,
gamma = 0.12,
threshold = 0.85,
volume_shape = "tube"
)
# Visualize synthetic blob
qim3d.viz.volumetric(vol)

Source code in qim3d/generate/_generators.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 |
|
qim3d.generate.volume_collection
volume_collection(num_volumes=15, collection_shape=(200, 200, 200), positions=None, shape_range=((40, 40, 40), (60, 60, 60)), volume_shape_zoom=(1.0, 1.0, 1.0), noise_type='perlin', noise_range=(0.02, 0.03), rotation_degree_range=(0, 360), rotation_axes=None, gamma_range=(0.9, 1), value_range=(128, 255), threshold_range=(0.5, 0.55), decay_rate_range=(5, 10), shape=None, tube_hole_ratio=0.5, axis=0, verbose=False, same_seed=False, hollow=False, seed=0, return_positions=False)
Generate a 3D volume of multiple synthetic volumes using Perlin or Simplex noise.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_volumes |
int
|
Number of synthetic volumes to include in the collection. Defaults to 15. |
15
|
collection_shape |
tuple of ints
|
Shape of the final collection volume to generate. Defaults to (200, 200, 200). |
(200, 200, 200)
|
positions |
list[tuple]
|
List of specific positions as (z, y, x) coordinates for the volumes. If not provided, they are placed randomly into the collection. Defaults to None. |
None
|
shape_range |
tuple of tuple of ints
|
Determines the shape of the generated volumes with first element defining the minimum size and second element defining maximum. Defaults to ((40,40,40), (60,60,60)). |
((40, 40, 40), (60, 60, 60))
|
volume_shape_zoom |
tuple of floats
|
Scaling factors for each dimension of each volume. Defaults to (1.0, 1.0, 1.0). |
(1.0, 1.0, 1.0)
|
noise_type |
str
|
Type of noise to be used for volume generation. Should be |
'perlin'
|
noise_range |
tuple of floats
|
Determines range for noise. First element is minimum and second is maximum. Defaults to (0.02, 0.03). |
(0.02, 0.03)
|
rotation_degree_range |
tuple of ints
|
Determines range for rotation angle in degrees. First element is minimum and second is maximum. Defaults to (0, 360). |
(0, 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)]. |
None
|
gamma_range |
tuple of floats
|
Determines minimum and maximum gamma correctness factor. Defaults to (0.9, 1.0) |
(0.9, 1)
|
value_range |
tuple of ints
|
Determines minimum and maximum value for volume intensity. Defaults to (128, 255). |
(128, 255)
|
threshold_range |
tuple of ints
|
Determines minimum and maximum value for thresholding. Defaults to (0.5, 0.55). |
(0.5, 0.55)
|
decay_rate_range |
float
|
Determines minimum and maximum value for the decay_range. Defaults to (5,10). |
(5, 10)
|
shape |
str or None
|
Shape of the volume to generate, either "cylinder", or "tube". Defaults to None. |
None
|
tube_hole_ratio |
float
|
Ratio for the inverted fade mask used to generate tubes. Will only have an effect if shape= |
0.5
|
axis |
int
|
Determines the axis of the volume_shape if this is defined. Defaults to 0. |
0
|
verbose |
bool
|
Flag to enable verbose logging. Defaults to False. |
False
|
same_seed |
bool
|
Use the same seed for each generated volume. Note that in order to generate identical volumes, the min and max for the different parameters should be identical. |
False
|
hollow |
bool
|
Create hollow objects using qim3d.operations.make_hollow(). Defaults to False. |
False
|
seed |
int
|
Seed for reproducibility. Defaults to 0. Each generated volume will be generated with a randomly selected sub-seed generated from the original seed. |
0
|
return_positions |
bool
|
Flag to return position of randomly placed blobs. |
False
|
Returns:
Name | Type | Description |
---|---|---|
volume_collection |
ndarray
|
3D volume of the generated collection of synthetic volumes with specified parameters. |
labels |
ndarray
|
Array with labels for each voxel, same shape as volume_collection. |
Raises:
Type | Description |
---|---|
ValueError
|
If |
TypeError
|
If |
ValueError
|
If volume parameters are invalid. |
ValueError
|
If the |
ValueError
|
If the |
Example
import qim3d
# Generate synthetic collection of volumes
volume_collection, labels = qim3d.generate.volume_collection(num_volumes=15)
# Visualize the collection
qim3d.viz.volumetric(volume_collection, grid_visible=True)

# Visualize labels
cmap = qim3d.viz.colormaps.segmentation(num_labels=num_volumes)
qim3d.viz.slicer(labels, color_map=cmap, value_max=num_volumes)

Example
Example
import qim3d
# Generate synthetic collection of cylindrical structures
volume_collection, labels = qim3d.generate.volume_collection(
num_volumes = 40,
collection_shape = (300, 150, 150),
shape_range = ((280, 10, 10), (290, 15, 15)),
noise_range = (0.06,0.09),
rotation_degree_range = (0,5),
threshold_range = (0.1,0.3),
gamma_range = (0.10, 0.20),
shape = "cylinder"
)
# Visualize the collection
qim3d.viz.volumetric(volume_collection)

Example
import qim3d
# Generate synthetic collection of tubular (hollow) structures
volume_collection, labels = qim3d.generate.volume_collection(
num_volumes = 10,
collection_shape = (200, 200, 200),
shape_range = ((185,35,35), (190,45,45)),
noise_range = (0.02, 0.03),
rotation_degree_range = (0,5),
threshold_range = (0.6, 0.7),
gamma_range = (0.1, 0.11),
shape = "tube",
tube_hole_ratio = 0.15,
)
# Visualize the collection
qim3d.viz.volumetric(volume_collection)

Source code in qim3d/generate/_aggregators.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 |
|
qim3d.generate.background
background(background_shape, baseline_value=0, min_noise_value=0, max_noise_value=20, generate_method='add', apply_method=None, seed=0, dtype='uint8', apply_to=None)
Generate a noise volume with random intensity values from a uniform distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
background_shape |
tuple
|
The shape of the noise volume to generate. |
required |
baseline_value |
float
|
The baseline intensity of the noise volume. Default is 0. |
0
|
min_noise_value |
float
|
The minimum intensity of the noise. Default is 0. |
0
|
max_noise_value |
float
|
The maximum intensity of the noise. Default is 20. |
20
|
generate_method |
str
|
The method used to combine |
'add'
|
apply_method |
str
|
The method to apply the generated noise to |
None
|
seed |
int
|
The seed for the random number generator. Default is 0. |
0
|
dtype |
data - type
|
Desired data type of the output volume. Default is 'uint8'. |
'uint8'
|
apply_to |
ndarray
|
An input volume to which noise will be applied. Only applicable if apply_method is defined. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
background |
ndarray
|
The generated noise volume (if |
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If the shape of |
Example
Example
import qim3d
# Generate synthetic collection of volumes
volume_collection, labels = qim3d.generate.volume_collection(num_volumes = 15)
# Apply noise to the synthetic collection
noisy_collection = qim3d.generate.background(
background_shape = volume_collection.shape,
min_noise_value = 0,
max_noise_value = 20,
apply_to = volume_collection,
apply_method = 'add'
)
qim3d.viz.volumetric(noisy_collection)
Example
import qim3d
# Generate synthetic collection of volumes
volume_collection, labels = qim3d.generate.volume_collection(num_volumes = 15)
# Apply noise to the synthetic collection
noisy_collection = qim3d.generate.background(
background_shape = volume_collection.shape,
baseline_value = 0,
min_noise_value = 0,
max_noise_value = 30,
generate_method = 'add',
apply_method = 'divide',
apply_to = volume_collection
)
qim3d.viz.volumetric(noisy_collection)

Example
import qim3d
# Generate synthetic collection of volumes
volume_collection, labels = qim3d.generate.volume_collection(num_volumes = 15)
# Apply noise to the synthetic collection
noisy_collection = qim3d.generate.background(
background_shape = (200, 200, 200),
baseline_value = 100,
min_noise_value = 0.8,
max_noise_value = 1.2,
generate_method = "multiply",
apply_method = "add",
apply_to = volume_collection
)
qim3d.viz.slices_grid(noisy_collection, num_slices=10, color_bar=True, color_bar_style="large")

Source code in qim3d/generate/_generators.py
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 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 |
|