How to create an intensity image from a segmentation

from timagetk.components.labelled_image import hollow_out_labelled_image
from timagetk.io.util import shared_data
from timagetk.components.labelled_image import LabelledImage
from timagetk.visu.stack import orthogonal_view
from timagetk.io import imread
from skimage import img_as_ubyte
from timagetk.components.spatial_image import SpatialImage
from timagetk.algorithms.linearfilter import linearfilter
/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

Load the example cell segmented image

seg_img_path = shared_data('sphere_membrane_0.0_seg.inr.gz', "sphere")
seg_img = imread(seg_img_path, rtype=LabelledImage, not_a_label=0)
orthogonal_view(seg_img, cmap='glasbey', val_range='auto')
../_images/92fbeadd7c519b66a3e08fda5575669b5af7c45859473f38d6b297ff7bd0b6cc.png

Hollow out the cells

hollow_seg = hollow_out_labelled_image(seg_img)
orthogonal_view(hollow_seg, cmap='glasbey', val_range='auto')
INFO     [timagetk.components.labelled_image] Hollowing out labelled numpy array... 
INFO     [timagetk.components.labelled_image] done in 0.282s
../_images/ba81d2946c4942772844e160d33112416ba6b0753d51ddf62fe839ff4bca9f92.png

Create a membrane image from the labelled image

membrane_img = SpatialImage(img_as_ubyte(hollow_seg), voxelsize=seg_img.get_voxelsize())  # convert image to unsigned 8bits
membrane_img[membrane_img != 0] = 255
orthogonal_view(membrane_img, cmap='gray')
WARNING  [timagetk.components.spatial_image] Undefined parameter ``axes_order``, using default: ZYX
WARNING  [timagetk.components.spatial_image] Undefined parameter ``origin``, using default: [0, 0, 0]
WARNING  [timagetk.components.spatial_image] Undefined parameter ``unit``, using default: 1e-06
/opt/conda/envs/timagetk/lib/python3.9/site-packages/skimage/util/dtype.py:549: UserWarning: Downcasting uint16 to uint8 without scaling because max value 64 fits in uint8
  return _convert(image, np.uint8, force_copy)
../_images/500f482b7ac5371c62d55a6700bb3d7e6d99fae1579f88ca2e3d87e2ec1ea9ce.png

Make it a bit more realistic

membrane_img_real = linearfilter(membrane_img, method="smoothing", sigma=0.5, real=True)
orthogonal_view(membrane_img_real, cmap='gray')
../_images/eab79ebc90b6bd6f85f0d196515e80d606bff08440016d87b651db480d2168a0.png