Generation
API
FetalSynthGen
Source code in fetalsyngen/generator/model.py
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 119 120 121 122 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 |
|
__init__(shape, resolution, device, intensity_generator, spatial_deform, resampler, bias_field, noise, gamma, blur_cortex=None, struct_noise=None, simulate_motion=None, boundaries=None, stack_sampler=None)
Initialize the model with the given parameters.
Note
Augmentations related to SR artifacts are optional and can be set to None if not needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shape
|
Iterable[int]
|
Shape of the output image. |
required |
resolution
|
Iterable[float]
|
Resolution of the output image. |
required |
device
|
str
|
Device to use for computation. |
required |
intensity_generator
|
ImageFromSeeds
|
Intensity generator. |
required |
spatial_deform
|
SpatialDeformation
|
Spatial deformation generator. |
required |
resampler
|
RandResample
|
Resampler. |
required |
bias_field
|
RandBiasField
|
Bias field generator. |
required |
noise
|
RandNoise
|
Noise generator. |
required |
gamma
|
RandGamma
|
Gamma correction generator. |
required |
blur_cortex
|
BlurCortex | None
|
Cortex blurring generator. |
None
|
struct_noise
|
StructNoise | None
|
Structural noise generator. |
None
|
simulate_motion
|
SimulateMotion | None
|
Motion simulation generator. |
None
|
boundaries
|
SimulatedBoundaries | None
|
Boundaries generator |
None
|
stack_sampler
|
StackSampler | None
|
Stack sampler. |
None
|
Source code in fetalsyngen/generator/model.py
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 |
|
sample(orientation, image, segmentation, seeds, genparams={})
Generate a synthetic image from the input data. Supports both random generation and from a fixed genparams dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Tensor | None
|
Image to use as intensity prior if required. |
required |
segmentation
|
Tensor
|
Segmentation to use as spatial prior. |
required |
seeds
|
Tensor | None
|
Seeds to use for intensity generation. |
required |
genparams
|
dict
|
Dictionary with generation parameters. Used for fixed generation. Should follow the structure and be of the same type as the returned generation parameters. |
{}
|
Returns:
Type | Description |
---|---|
tuple[Tensor, Tensor, Tensor, dict]
|
The synthetic image, the segmentation, the original image, and the generation parameters. |
Source code in fetalsyngen/generator/model.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 |
|
ImageFromSeeds
Source code in fetalsyngen/generator/intensity/rand_gmm.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 116 117 118 119 120 121 122 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 |
|
__init__(min_subclusters, max_subclusters, seed_labels, generation_classes, meta_labels=[1, 2, 3, 4])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min_subclusters
|
int
|
Minimum number of subclusters to use. |
required |
max_subclusters
|
int
|
Maximum number of subclusters to use. |
required |
seed_labels
|
Iterable[int]
|
Iterable with all possible labels that can occur in the loaded seeds. Should be a unique set of integers starting from [0, ...]. 0 is reserved for the background, that will not have any intensity generated. |
required |
generation_classes
|
Iterable[int]
|
Classes to use for generation. Seeds with the same generation calss will be generated with the same GMM. Should be the same length as seed_labels. |
required |
meta_labels
|
int
|
Number of meta-labels used. Defaults to 4. |
[1, 2, 3, 4]
|
Source code in fetalsyngen/generator/intensity/rand_gmm.py
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 |
|
load_seeds(seeds, mlabel2subclusters=None, genparams={}, orientation=Orientation('RAS'))
Generate an intensity image from seeds.
If seed_mapping is provided, it is used to
select the number of subclusters to use for
each meta label. Otherwise, the number of subclusters
is randomly selected from a uniform discrete distribution
between min_subclusters
and max_subclusters
(both inclusive).
Args:
seeds: Dictionary with the mapping `subcluster_number: {meta_label: seed_path}`.
mlabel2subclusters: Mapping to use when defining how many subclusters to
use for each meta-label. Defaults to None.
genparams: Dictionary with generation parameters. Defaults to {}.
Should contain the key "mlabel2subclusters" if the mapping is to be fixed.
orientation: Orientation to use. Defaults to Orientation("RAS").
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Intensity image with the same shape as the seeds.
Tensor dimensions are (H, W, D). Values inside the tensor
correspond to the subclusters, and are grouped by meta-label.
|
Source code in fetalsyngen/generator/intensity/rand_gmm.py
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 |
|
sample_intensities(seeds, device, genparams={})
Sample the intensities from the seeds.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seeds
|
Tensor
|
Tensor with the seeds. |
required |
device
|
str
|
Device to use. Should be "cuda" or "cpu". |
required |
genparams
|
dict
|
Dictionary with generation parameters. Defaults to {}. Should contain the keys "mus" and "sigmas" if the GMM parameters are to be fixed. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Tensor with the intensities. |
Source code in fetalsyngen/generator/intensity/rand_gmm.py
119 120 121 122 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 |
|
SpatialDeformation
Class defining the spatial deformation of the image. Combines both random affine and nonlinear transformations to deform the image.
Source code in fetalsyngen/generator/deformation/affine_nonrigid.py
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 119 120 121 122 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 |
|
__init__(max_rotation, max_shear, max_scaling, size, prob, nonlinear_transform, nonlin_scale_min, nonlin_scale_max, nonlin_std_max, flip_prb, device)
Initialize the spatial deformation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_rotation
|
float
|
Maximum rotation in degrees. |
required |
max_shear
|
float
|
Maximum shear. |
required |
max_scaling
|
float
|
Maximum scaling. |
required |
size
|
Iterable[int]
|
Size of the output image. |
required |
prob
|
float
|
Probability of applying the deformation. |
required |
nonlinear_transform
|
bool
|
Whether to apply nonlinear transformation. |
required |
nonlin_scale_min
|
float
|
Minimum scale for the nonlinear transformation. |
required |
nonlin_scale_max
|
float
|
Maximum scale for the nonlinear transformation. |
required |
nonlin_std_max
|
float
|
Maximum standard deviation for the nonlinear transformation. |
required |
flip_prb
|
float
|
Probability of flipping the image. |
required |
device
|
str
|
Device to use for computation. Either "cuda" or "cpu". |
required |
Source code in fetalsyngen/generator/deformation/affine_nonrigid.py
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 |
|
deform(image, segmentation, output, genparams={})
Deform the image, segmentation and output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Tensor
|
Image to deform. |
required |
segmentation
|
Tensor
|
Segmentation to deform. |
required |
output
|
Tensor
|
Output to deform. |
required |
genparams
|
dict
|
Dictionary with generation parameters. Defaults to {}. Should contain the keys "affine" and "non_rigid" if the parameters are fixed. Affine parameters should contain the keys "rotations", "shears" and "scalings". Non-rigid parameters should contain the keys "nonlin_scale", "nonlin_std" and "size_F_small". |
{}
|
Returns:
Type | Description |
---|---|
tuple[Tensor, Tensor, Tensor, dict]
|
Deformed image, segmentation, output and deformation parameters. |
Source code in fetalsyngen/generator/deformation/affine_nonrigid.py
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
RandResample
Bases: RandTransform
Resample the input image to a random resolution sampled uniformly between
min_resolution
and max_resolution
with a probability of prob
.
If the resolution is smaller than the input resolution, no resampling is performed.
Source code in fetalsyngen/generator/augmentation/synthseg.py
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 119 120 121 122 |
|
__init__(prob, min_resolution, max_resolution)
Initialize the augmentation parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prob
|
float
|
Probability of applying the augmentation. |
required |
min_resolution
|
float
|
Minimum resolution for the augmentation (in mm). |
required |
max_resolution
|
float
|
Maximum resolution for the augmentation. |
required |
Source code in fetalsyngen/generator/augmentation/synthseg.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
__call__(output, input_resolution, device, genparams={})
Apply the resampling to the input image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output
|
Tensor
|
Input image to resample. |
required |
input_resolution
|
array
|
Resolution of the input image. |
required |
device
|
str
|
Device to use for computation. |
required |
genparams
|
dict
|
Generation parameters. Default: {}. Should contain the key "spacing" if the spacing is fixed. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
Resampled image. |
Source code in fetalsyngen/generator/augmentation/synthseg.py
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 |
|
RandBiasField
Bases: RandTransform
Add a random bias field to the input image with a probability of prob
.
Source code in fetalsyngen/generator/augmentation/synthseg.py
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 |
|
__init__(prob, scale_min, scale_max, std_min, std_max)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prob
|
float
|
Probability of applying the augmentation. |
required |
scale_min
|
float
|
Minimum scale of the bias field. |
required |
scale_max
|
float
|
Maximum scale of the bias field. |
required |
std_min
|
float
|
Minimum standard deviation of the bias field. |
required |
std_max
|
float
|
Maximum standard deviation of the bias. |
required |
Source code in fetalsyngen/generator/augmentation/synthseg.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
__call__(output, device, genparams={})
Apply the bias field to the input image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output
|
Tensor
|
Input image to apply the bias field. |
required |
device
|
str
|
Device to use for computation. |
required |
genparams
|
dict
|
Generation parameters. Default: {}. Should contain the keys "bf_scale", "bf_std" and "bf_size" if the bias field parameters are fixed. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
Image with the bias field applied. |
Source code in fetalsyngen/generator/augmentation/synthseg.py
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 |
|
RandNoise
Bases: RandTransform
Add random Gaussian noise to the input image with a probability of prob
.
Source code in fetalsyngen/generator/augmentation/synthseg.py
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 |
|
__init__(prob, std_min, std_max)
The image scale is 0-255 so the noise is added in the same scale. Args: prob: Probability of applying the augmentation. std_min: Minimum standard deviation of the noise. std_max: Maximum standard deviation of the noise
Source code in fetalsyngen/generator/augmentation/synthseg.py
199 200 201 202 203 204 205 206 207 208 209 |
|
__call__(output, device, genparams={})
Apply the noise to the input image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output
|
Tensor
|
Input image to apply the noise. |
required |
device
|
str
|
Device to use for computation. |
required |
genparams
|
dict
|
Generation parameters. Default: {}. Should contain the key "noise_std" if the noise standard deviation is fixed. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
Image with the noise applied. |
Source code in fetalsyngen/generator/augmentation/synthseg.py
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 |
|
RandGamma
Bases: RandTransform
Apply gamma correction to the input image with a probability of prob
.
Source code in fetalsyngen/generator/augmentation/synthseg.py
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 |
|
__init__(prob, gamma_std)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prob
|
float
|
Probability of applying the augmentation. |
required |
gamma_std
|
float
|
Standard deviation of the gamma correction. |
required |
Source code in fetalsyngen/generator/augmentation/synthseg.py
246 247 248 249 250 251 252 253 |
|
__call__(output, device, genparams={})
Apply the gamma correction to the input image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output
|
Tensor
|
Input image to apply the gamma correction. |
required |
device
|
str
|
Device to use for computation. |
required |
genparams
|
dict
|
Generation parameters. Default: {}. Should contain the key "gamma" if the gamma correction is fixed. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
Image with the gamma correction applied. |
Source code in fetalsyngen/generator/augmentation/synthseg.py
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 |
|