from timagetk import MultiChannelImage
from timagetk import LabelledImage

from timagetk.io import imsave
from timagetk.io import imread
from timagetk.synthetic_data.labelled_image import example_layered_sphere_labelled_image
from timagetk.synthetic_data.nuclei_image import nuclei_image_from_point_positions
from timagetk.synthetic_data.wall_image import example_layered_sphere_wall_image
from timagetk.visu.plotly import simple_z_slider
/builds/J-gEBwyb/0/mosaic/timagetk/src/timagetk/components/labelled_image.py:31: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from tqdm.autonotebook import tqdm
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 9
      7 from timagetk.synthetic_data.nuclei_image import nuclei_image_from_point_positions
      8 from timagetk.synthetic_data.wall_image import example_layered_sphere_wall_image
----> 9 from timagetk.visu.plotly import simple_z_slider

File /builds/J-gEBwyb/0/mosaic/timagetk/src/timagetk/visu/plotly.py:17
     11 """Plotly based graph methods.
     12 
     13 See `timagetk/notebooks/plotly_examples.ipynb` for examples.
     14 """
     16 import numpy as np
---> 17 import plotly.express as px
     18 import plotly.graph_objects as go
     19 from ipywidgets import widgets

ModuleNotFoundError: No module named 'plotly'

Creating synthetic labelled images

seg_img, points = example_layered_sphere_labelled_image(extent=50., voxelsize=(0.5, 0.5, 0.5), n_points=15,
                                                        n_layers=1, return_points=True)
seg_img.labels()
seg_img.nb_labels()
f,w = simple_z_slider(seg_img, colorscale="jet", live=True, start_slice=50)
w
img_path = '/tmp/labelled_medium_image.tif'
imsave(img_path, seg_img)
image = imread(img_path, LabelledImage, not_a_label=0)
print(image)
image.nb_labels()

Creating synthetic wall images

Small image

def make_small_wall_image():
    wall_img = example_layered_sphere_wall_image(extent=15., voxelsize=(0.5, 0.5, 0.5), wall_sigma=0.05,
                                                 n_points=3, n_layers=1, wall_intensity=255,
                                                 return_points=False, dtype='uint8')
    return wall_img
small_wall_image = make_small_wall_image()
small_wall_image.get_shape()
small_wall_image.get_voxelsize()
f,w = simple_z_slider(small_wall_image, live=True, start_slice=15)
w
from timagetk.algorithms.linearfilter import linearfilter
realistic_small_wall_image = linearfilter(small_wall_image, method="smoothing", sigma=1., real=False)
f,w = simple_z_slider(realistic_small_wall_image, start_slice=15)
w

Medium image

def make_medium_wall_image():
    wall_img = example_layered_sphere_wall_image(extent=50., voxelsize=(1., 0.5, 0.5), wall_sigma=0.1,
                                                 n_points=10, n_layers=2, wall_intensity=255,
                                                 return_points=False, dtype='uint8')
    return wall_img
medium_wall_image = make_medium_wall_image()
medium_wall_image.get_shape()
medium_wall_image.get_voxelsize()
f,w = simple_z_slider(medium_wall_image, start_slice=25)
w

Large image

def make_large_wall_image():
    wall_img = example_layered_sphere_wall_image(extent=100., voxelsize=(1., 0.5, 0.5), wall_sigma=0.15,
                                                 n_points=10, n_layers=2, wall_intensity=255,
                                                 return_points=False, dtype='uint8')
    return wall_img
large_wall_image = make_large_wall_image()
large_wall_image.get_shape()
large_wall_image.get_voxelsize()
f,w = simple_z_slider(large_wall_image, start_slice=50, live=True)
w

Creating synthetic multichannel images

from timagetk.bin.synthetic_image import N_POINTS_SMALL_IMG
from timagetk.bin.synthetic_image import N_POINTS_MEDIUM_IMG
from timagetk.bin.synthetic_image import N_POINTS_LARGE_IMG
small_kwargs = {"extent": 15., "voxelsize": (0.5, 0.5, 0.5), "n_points": N_POINTS_SMALL_IMG, "n_layers": 1}
medium_kwargs = {"extent": 50., "voxelsize": (1., 0.5, 0.5), "n_points": N_POINTS_MEDIUM_IMG, "n_layers": 2}
large_kwargs = {"extent": 100., "voxelsize": (1., 0.5, 0.5), "n_points": N_POINTS_LARGE_IMG, "n_layers": 2}

small_wall_kwargs = {"wall_sigma": 0.05, "wall_intensity": 255}
medium_wall_kwargs = {"wall_sigma": 0.1, "wall_intensity": 255}
large_wall_kwargs = {"wall_sigma": 0.15, "wall_intensity": 255}

small_nuclei_kwargs = {"nuclei_radius": 1., "nuclei_intensity": 255}
medium_nuclei_kwargs = {"nuclei_radius": 1.5, "nuclei_intensity": 255}
large_nuclei_kwargs = {"nuclei_radius": 2., "nuclei_intensity": 255}
wall_img, points = example_layered_sphere_wall_image(return_points=True, dtype='uint8', **medium_kwargs,
                                                     **medium_wall_kwargs, **medium_nuclei_kwargs)
nuclei_img = nuclei_image_from_point_positions(points, dtype='uint8', **medium_kwargs,
                                               **medium_wall_kwargs, **medium_nuclei_kwargs)
mc_img = MultiChannelImage({'wall': wall_img, 'nuclei': nuclei_img})
print(mc_img)
imsave("/tmp/medium_multichannel_image.tif", mc_img)
from timagetk.io import imread
mc_img = imread("/tmp/medium_multichannel_image.tif", channel_names=["wall", "nuclei"])
print(mc_img)
mc_img.get_channel('wall').max()
f,w = simple_z_slider(mc_img.get_channel('wall'), live=True, start_slice=25)
w
f,w = simple_z_slider(mc_img.get_channel('nuclei'), colorscale='viridis', live=True, start_slice=25)
w