Data¶
General¶
USE_CV2 = True
module-attribute
¶
RandomDiskGenerator
¶
Source code in src/chromatix/data/data.py
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 427 428 | |
N = N
instance-attribute
¶
num_planes = shape[-1]
instance-attribute
¶
num_points = num_points
instance-attribute
¶
radius = radius
instance-attribute
¶
shape = shape
instance-attribute
¶
z_range = z_range
instance-attribute
¶
__call__()
¶
Get a new sample. Automatically iterates through samples of coordinates with every call. Will cause the random coordinates to be regenerated when the last sample is reached.
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray A (num_points 2) or (num_points 3) array containing the coordinates. |
ndarray
|
numpy.ndarray 2D or 3D Image corresponding to the coordinates. |
Source code in src/chromatix/data/data.py
__getitem__(idx)
¶
Get a new sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
idx
|
int
|
Index of the current sample that needs to be generated. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray A (num_points 2) or (num_points 3) array containing the coordinates. |
ndarray
|
numpy.ndarray 2D or 3D Image corresponding to the coordinates. |
Source code in src/chromatix/data/data.py
__init__(N, num_points, radius, shape, z_range)
¶
Create a dataset of random 3D coordinates and their associated image.
Each generated sample consists of an array of x y z coordinates with
shape: (n_points 3), accompanied by a 3D image with shape shape.
The last dimension of shape represents the z axis, if it exists. The
number of planes will be inferred from the shape argument. This is
meant for TensorFlow and PyTorch data loaders that support generators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int
|
Number of samples in the dataset. Avoid large N as the coordinates
on each epoch are pre-stored for speed. On each new epoch the
samples are randomized again (new random coordinates are generated)
therefore you can easily use small |
required |
num_points
|
int
|
Number of points in each sample. For 3D samples these samples will be randomly split between the planes. |
required |
radius
|
int
|
Radius of the disks to be drawn on each plane. |
required |
shape
|
tuple[int, int, int]
|
Shape of the output image. Dimensions are [h w n_z] where n_z is the number of planes in 3D. For 2D samples use z=1. |
required |
z_range
|
tuple[int, int]
|
list Minimum and Maximum values for z values [min, max]. The returned coordinates are [x y z] and this parameter determines the range of the z coordinates. |
required |
Source code in src/chromatix/data/data.py
__len__()
¶
reset()
¶
Generate all the random coordinates. This is called when generator is instantiated or the last sample in the generator is reached.
Source code in src/chromatix/data/data.py
draw_disks(shape, coordinates, radius, color=255)
¶
Create a grayscale image with disks drawn at each provided coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_size
|
The desired image size as (height, width). |
required | |
coordinates
|
ndarray
|
A list of (x, y) coordinates where disks should be drawn. |
required |
radius
|
int
|
The radius of the disks. |
required |
color
|
int
|
An optional intensity for the disks (0-255). |
255
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: The resulting grayscale image with disks drawn at the specified coordinates. |
Source code in src/chromatix/data/data.py
draw_line(arr, start, stop, thickness=0.3, intensity=1.0)
¶
Draw a line in a 3D object with a given thickness and intensity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
ndarray
|
The object to draw the line in. |
required |
start
|
ndarray
|
The start of the line. |
required |
end
|
The end of the line. |
required | |
thickness
|
float
|
The thickness of the line. |
0.3
|
intensity
|
float
|
The intensity of the line. |
1.0
|
Source code in src/chromatix/data/data.py
filaments_3d(sz, intensity=1.0, radius=0.8, rand_offset=0.05, rel_theta=1.0, num_filaments=50, thickness=0.3, seed=True)
¶
Create a 3D representation of filaments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sz
|
tuple[int, int, int]
|
A 3D shape tuple representing the size of the object. |
required |
radius
|
float | tuple[float, float, float]
|
A tuple of real numbers (or a single real number) representing
the relative radius of the volume in which the filaments will be
created. Default is 0.8. If a tuple is used, the filamets will be
created in a corresponding elliptical volume. Note that the radius
is only enforced in the version |
0.8
|
rand_offset
|
float
|
A tuple of real numbers representing the random offsets of the filaments in relation to the size. Default is 0.05. |
0.05
|
rel_theta
|
float
|
A real number representing the relative theta range of the filaments. Default is 1.0. |
1.0
|
num_filaments
|
int
|
An integer representing the number of filaments to be created. Default is 50. |
50
|
thickness
|
float
|
A real number representing the thickness of the filaments in pixels. Default is 0.8. |
0.3
|
seed
|
int | None
|
An optional integer used to seed the random number generator
for randomly generating filaments. This can be used to repeatedly
generate the same sample. Default is |
True
|
This code is based on the SyntheticObjects.jl package by Hossein Zarei Oshtolagh and Rainer Heintzmann.
Source code in src/chromatix/data/data.py
pollen_3d(sz, intensity=1.0, radius=0.8, dphi=0.0, dtheta=0.0, thickness=0.8, filled=False, filled_rel_intensity=0.1)
¶
Create a 3D representation of a pollen grain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sz
|
tuple[int, int, int]
|
A tuple of three integers representing the size of the volume in
which the pollen grain will be created. Default is |
required |
radius
|
float
|
Roughly the relative radius of the pollen grain. |
0.8
|
dphi
|
float
|
A float representing the phi angle offset in radians. Default is 0.0. |
0.0
|
dtheta
|
float
|
A float representing the theta angle offset in radians. Default is 0.0. |
0.0
|
thickness
|
float
|
A float representing the thickness of the pollen grain. Default is 0.8. |
0.8
|
filled
|
bool
|
A boolean representing whether the pollen grain should be
filled. Default is |
False
|
filled_rel_intensity
|
A float representing the relative intensity of the filled part of the pollen grain. Default is 0.1. |
0.1
|
Returns: ret: A 3D array representing the pollen grain.
This code is based on the SyntheticObjects.jl package by Hossein Zarei Oshtolagh and Rainer Heintzmann and the original code by Kai Wicker.
Source code in src/chromatix/data/data.py
siemens_star(num_pixels=512, num_spokes=32, radius=None)
¶
Generates a 2D Siemens star image of shape num_pixels. A single input
is interpreted as a square-shaped array. radius is the radius of the
star in pixels. If not provided, it will be half of the image size along
each dimension.
Number of spokes in the star can be controlled with num_spokes. Spokes
will alternate between black and white (0.0 and 1.0).
Source code in src/chromatix/data/data.py
sqr_dist_to_line(z, y, x, start, n)
¶
Returns an array with each pixel being assigned to the square distance to that line and an array with the distance along the line.
Source code in src/chromatix/data/data.py
Objects¶
create_radial_pattern(shape)
¶
Create a basic radial pattern image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple
|
Shape of the image (height, width). |
required |
Returns:
| Type | Description |
|---|---|
|
jnp.ndarray: Radial pattern image. |
Source code in src/chromatix/data/objects.py
normalize_grayscale_image(input_path, output_path)
¶
Source code in src/chromatix/data/objects.py
save_phase_pattern()
¶
Source code in src/chromatix/data/objects.py
Permittivity Tensors¶
calc_scattering_potential(epsilon_r, refractive_index, wavelength)
¶
Create the scattering potential from the permittivity tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsilon_r
|
ndarray
|
The permittivity tensor of the material. |
required |
refractive_index
|
float
|
The refractive index of the background medium. |
required |
wavelength
|
float
|
The wavelength of the light (microns). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
The scattering potential. |
Source code in src/chromatix/data/permittivity_tensors.py
create_calcite_crystal(shape, extraordinary_axis='z')
¶
Create a calcite crystal phantom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Tuple[int, int, int]
|
Shape of the phantom (z, y, x) |
required |
extraordinary_axis
|
Optional[str]
|
Axis which is extraordinary ('x', 'y', or 'z') |
'z'
|
Returns:
| Type | Description |
|---|---|
Array
|
4D array representing the phantom with the permittivity tensor at each voxel. |
Source code in src/chromatix/data/permittivity_tensors.py
create_homogeneous_phantom(shape, n_o, n_e, extraordinary_axis='x')
¶
Create a homogeneous uniaxial anisotropic phantom.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Tuple[int, int, int]
|
Shape of the phantom (z, y, x) |
required |
n_o
|
float
|
Ordinary refractive index |
required |
n_e
|
float
|
Extraordinary refractive index |
required |
extraordinary_axis
|
Optional[str]
|
Axis which is extraordinary ('x', 'y', or 'z') |
'x'
|
Returns:
| Type | Description |
|---|---|
Array
|
4D array representing the phantom with the permittivity tensor at each voxel. |
Source code in src/chromatix/data/permittivity_tensors.py
create_homogeneous_scattering_potential(shape, n_o, n_e, background_permittivity)
¶
Create a homogeneous uniaxial anisotropic scattering potential.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple
|
Shape of the phantom (z, y, x) |
required |
n_o
|
float
|
Ordinary refractive index |
required |
n_e
|
float
|
Extraordinary refractive index |
required |
background_permittivity
|
float
|
Background permittivity |
required |
Returns:
| Type | Description |
|---|---|
Array
|
4D array representing the scattering potential. |
Source code in src/chromatix/data/permittivity_tensors.py
create_scattering_potential(permittivity_tensor, background_permittivity)
¶
Create the scattering potential from the permittivity tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
permittivity_tensor
|
ndarray
|
The permittivity tensor of the material. |
required |
background_permittivity
|
float
|
The permittivity of the background medium. |
required |
Returns:
| Type | Description |
|---|---|
|
The scattering potential. |
Source code in src/chromatix/data/permittivity_tensors.py
expand_potential_dims(tensor)
¶
generate_dummy_potential(vol_shape)
¶
generate_permittivity_tensor(n_o, n_e, extraordinary_axis='x')
¶
Generate the permittivity tensor for a uniaxial anisotropic material.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_o
|
float
|
Ordinary refractive index |
required |
n_e
|
float
|
Extraordinary refractive index |
required |
extraordinary_axis
|
str
|
Axis which is extraordinary ('x', 'y', or 'z') |
'x'
|
Returns:
| Type | Description |
|---|---|
Array
|
Permittivity tensor with the order of axes as zyx. |