Filaments phantom data generator
In [1]:
Copied!
from colorsys import hls_to_rgb
import jax as jax
import jax.numpy as jnp
import matplotlib.pyplot as plt
import numpy as np
from jax.numpy import pi
from chromatix.utils import filaments_3d
from colorsys import hls_to_rgb
import jax as jax
import jax.numpy as jnp
import matplotlib.pyplot as plt
import numpy as np
from jax.numpy import pi
from chromatix.utils import filaments_3d
In [2]:
Copied!
# CC nadapez: from https://stackoverflow.com/a/20958684
def colorize(arr, normalize=True, gamma=0.3):
z = arr
r = np.abs(z)
if normalize:
r = r / np.max(r)
arg = np.angle(z)
hue = (arg + pi) / (2 * pi) + 0.5
lightness = 1.0 - 1.0 / (1.0 + r**gamma)
saturation = 0.8
c = np.vectorize(hls_to_rgb)(hue, lightness, saturation) # --> tuple
c = np.array(c) # --> array of (3,n,m) shape, but need (n,m,3)
c = c.swapaxes(0, 2)
c = c.swapaxes(0, 1)
return c
# CC nadapez: from https://stackoverflow.com/a/20958684
def colorize(arr, normalize=True, gamma=0.3):
z = arr
r = np.abs(z)
if normalize:
r = r / np.max(r)
arg = np.angle(z)
hue = (arg + pi) / (2 * pi) + 0.5
lightness = 1.0 - 1.0 / (1.0 + r**gamma)
saturation = 0.8
c = np.vectorize(hls_to_rgb)(hue, lightness, saturation) # --> tuple
c = np.array(c) # --> array of (3,n,m) shape, but need (n,m,3)
c = c.swapaxes(0, 2)
c = c.swapaxes(0, 1)
return c
Generate a 3D sample with thin filaments of varying length in random orientations¶
In [3]:
Copied!
arr = filaments_3d((128, 128, 128), 1, radius=0.9, rand_offset=0.2, num_filaments=50)
arr_p = jnp.sum(arr, axis=1)
plt.imshow(colorize(1j * arr_p))
arr = filaments_3d((128, 128, 128), 1, radius=0.9, rand_offset=0.2, num_filaments=50)
arr_p = jnp.sum(arr, axis=1)
plt.imshow(colorize(1j * arr_p))
Out[3]:
<matplotlib.image.AxesImage at 0x7f82d05d02f0>
In [4]:
Copied!
z = 84
plt.imshow(colorize(1j * arr[:, z, :] * (arr[:, z, :] < 15)))
z = 84
plt.imshow(colorize(1j * arr[:, z, :] * (arr[:, z, :] < 15)))
Out[4]:
<matplotlib.image.AxesImage at 0x7f82d02b0190>
In [ ]:
Copied!