Image I/O

import plotly.io as pio
import plotly.offline as py
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 import plotly.io as pio
      2 import plotly.offline as py

ModuleNotFoundError: No module named 'plotly'
from timagetk.io.image import imread
from timagetk.io.image import imsave
from timagetk.visu.plotly import stack_browser

Loading images

It is possible to load images using:

  • path: an absolute or relative path to an image file;

  • URL: a HTTP(S) URL pointing to an image file;

  • ~~shared data: an absolute or relative path to an image file;~~

Load an image from an URL:

url = 'https://zenodo.org/record/3737630/files/sphere_membrane_t0.inr.gz'
img = imread(url)
type(img)

A safer way to do is is to use the md5 checksum to verify the file integrity:

md5_cs = "24cc1edfaca092c26486a58fd6979827"
img = imread(url, hash_value=md5_cs)
fig = stack_browser(img)

Load an image and force its returned type:

It is possible to force the returned instance type by providing it to imread, here we force it to LabelledImage using the rtype keyword argument.

from timagetk import LabelledImage
url = 'https://zenodo.org/record/3737630/files/sphere_membrane_t0_seg.inr.gz'
md5_cs = 'ff67c70d6a655ba0609363438a2ac421'
img = imread(url, hash_value=md5_cs, rtype=LabelledImage, not_a_label=0)
type(img)

Note that it is also possible to pass arguments to the object constructor, here not_a_label=0, using keyword arguments.

print(img.not_a_label)
fig = stack_browser(img, cmap='jet')