Pollen grain 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 pollen_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 pollen_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 a synthetic pollen¶
In [3]:
Copied!
arr = pollen_3d([128, 128, 128], filled=True)
arr_p = jnp.sum(arr, axis=1)
plt.imshow(colorize(arr_p))
# np.max(arr_p)
arr = pollen_3d([128, 128, 128], filled=True)
arr_p = jnp.sum(arr, axis=1)
plt.imshow(colorize(arr_p))
# np.max(arr_p)
Out[3]:
<matplotlib.image.AxesImage at 0x7f0e005bc2f0>
In [4]:
Copied!
z = 84
plt.imshow(colorize(arr[:, z, :]))
z = 84
plt.imshow(colorize(arr[:, z, :]))
Out[4]:
<matplotlib.image.AxesImage at 0x7f0e00333b10>
In [ ]:
Copied!