KinoRewind
[swirl, radius, angle, colored, tornado]
|> TensorPlot.plot(
concat: :wrappable,
columns: 3,
cmap: :viridis,
cmaps: ["viridis", "blues", "greys"],
size: 360,
titel: "Composition of a Swirl",
labels: ["Swirl", "Radius", "Angle", "Colored Swirl", "RGB Tornado"]
)
KinoRewind is a helper module for rendering 3D and 4D Nx.Tensors as sequence of images or single image in Livebook via VegaLite.
Installation
In Livebook add kino_rewind to your dependencies:
Mix.install([
{:nx, "~> 0.10.0"},
{:kino, "~> 0.18.0"},
{:image, "~> 0.62.1"},
# add this:
{:kino_rewind, "~> 0.1.0"}
])Example
Inside Livebook a list of Nx.Tensors can be rendered like this:
rad = 12
dx = Nx.iota({rad * 2, 1}) |> Nx.subtract(rad) |> Nx.divide(rad)
dy = Nx.iota({1, rad * 2}) |> Nx.subtract(rad) |> Nx.divide(rad)
dx2 = Nx.pow(dx, 2)
dy2 = Nx.pow(dy, 2)
radius = Nx.add(dx2, dy2) |> Nx.sqrt()
angle = Nx.atan2(dy, dx)
[radius, angle, dx, dy]
|> TensorPlot.plot(
concat: :wrappable,
columns: 4,
cmap: :viridis,
size: 360,
titel: "Imagees",
labels: ["Radius", "Angle", "DX", "DY"]
)