Working with multi-dimensional images#

[1]:
import seaborn_image as isns

from skimage import exposure # for adjusting image exposure
from skimage import filters  # for applying filters

Load a sample multi-dimension image array

[2]:
cells = isns.load_image("cells")
cells.shape
[2]:
(256, 256, 60)

Plot specific slices from 3-D data#

[3]:
g = isns.ImageGrid(cells, slices=[10,20,30,40,50,55])
/home/docs/checkouts/readthedocs.org/user_builds/seaborn-image/envs/v0.7.0/lib/python3.8/site-packages/traitlets/traitlets.py:3437: FutureWarning: --rc={'figure.dpi': 96} for dict-traits is deprecated in traitlets 5.0. You can pass --rc <key=value> ... multiple times to add items to a dict.
  warn(
../_images/Tutorial_Multi_Dim_Images_5_1.svg

You can apply changes to the entire grid. Here, we hide the colorbar and change the colormap.

[4]:
g = isns.ImageGrid(cells, slices=[10,20,30,40,50,55], cbar=False, cmap="inferno")
../_images/Tutorial_Multi_Dim_Images_7_0.svg

Index along different axis#

[5]:
g = isns.ImageGrid(
    cells,
    slices=[10,20,30,40,50,55],
    axis=1,
    cbar=False
)
../_images/Tutorial_Multi_Dim_Images_9_0.svg

Variable step sizes and start/end points#

[6]:
g = isns.ImageGrid(
    cells,
    step=3,
    start=10,
    stop=40,
    cbar=False
)
../_images/Tutorial_Multi_Dim_Images_11_0.svg

Variable column length and figure size#

Change column length and figure size using the col_wrap and height parameter, respectively

[7]:
g = isns.ImageGrid(cells, cbar=False, height=1, col_wrap=10)
../_images/Tutorial_Multi_Dim_Images_13_0.svg

Map a function to transform the 3-D data#

Here, we will adjust the exposure using the adjust_gamma function from scikit-image. This can done by passing the function object to the map_func parameter. Additional parameters to the function object can be passed as kwargs.

[8]:
g = isns.ImageGrid(
    cells,
    map_func=exposure.adjust_gamma,
    map_func_kw={"gamma" : 0.5},
    cbar=False,
    height=1,
    col_wrap=10)
../_images/Tutorial_Multi_Dim_Images_15_0.svg

Plot 4d data#

We now load a small sample of the cifar10 dataset.

This array will be composed of 9 images of size 32x32 with 3 channels, RGB

[9]:
cifar10_sample = isns.load_image("cifar10")
cifar10_sample.shape
[9]:
(60, 32, 32, 3)

Plot specific slices#

[10]:
g = isns.ImageGrid(cifar10_sample, slices=[4, 7, 9, 14, 19, 43])
../_images/Tutorial_Multi_Dim_Images_20_0.svg

This time images don’t have a color map, since the channels are always interpreted as RGB channels.

[11]:
g = isns.ImageGrid(
    cifar10_sample,
    start=0,
    stop=12,
    step=2,
    axis=0
)
../_images/Tutorial_Multi_Dim_Images_22_0.svg
[12]:
cifar10_sample = isns.load_image("cifar10")


# use sobel filter and adjust output datatypes
def sobel_3d(img, **extra_params):
    return filters.sobel(img, **extra_params)*256

g = isns.ImageGrid(
    cifar10_sample,
    map_func=sobel_3d,
    height=1.5,
    col_wrap=10,
)
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
../_images/Tutorial_Multi_Dim_Images_23_1.svg

Plot list of 3d images#

[13]:
cifar10_sample_list = isns.load_image("cifar10 list")
cifar10_sample_list[0].shape
[13]:
(32, 32, 3)
[14]:
g = isns.ImageGrid(cifar10_sample_list[:6])
../_images/Tutorial_Multi_Dim_Images_26_0.svg