<jupyter_start><jupyter_text>Importing images using AICSimageIO and viewing them with napari 1. Introduction- **AICSimageIO** is a python module allowing to load several microscopy image formats like TIFF, CZI, LIF, and OME-TIFF.- **Napari** is an interactive python image viewer based on Qt that helps displaying multidimensional data.Here's a short preview of how it looks like with the example file :![Image of napari](images/illustrations/napari-brain-sample.gif)  2. Using AICSimageIOHere is how to use the basic AICSimageIO syntax to load an image and get some info : To start we need to importing the necessary libraries :<jupyter_code>from aicsimageio import AICSImage, imread
import napari
import matplotlib.pyplot as plt
# Get an AICSImage object

img_path = "images/first-instar-brain.tif"

img = AICSImage(img_path)

img.data  # returns 6D STCZYX numpy array
print("dimensions: " + img.dims)  # returns string "STCZYX"
print(f"shape: {img.shape}")  # returns tuple of dimension sizes in STCZYX order

# Get 6D STCZYX numpy array
data = imread(img_path)
img_to_view = img.get_image_data("SZYX", C=0, T=0)  # returns 4D SZYX numpy array<jupyter_output>dimensions: STCZYX
shape: (3, 1, 1, 56, 256, 256)<jupyter_text>**For more info** on how to use the module, read the documentation here : [Aicsimageio documentation at readthedocs](https://allencellmodeling.github.io/aicsimageio/index.html)  3. Viewing data with Napari vs Matplolib 3.1 The Napari viewerHere's how to use **napari *within* a Jupyter notebook** :<jupyter_code>with napari.gui_qt():
    viewer = napari.view_image(img_to_view)  # launches napari GUI and viewer<jupyter_output><empty_output><jupyter_text>3.2 Viewing images with matplotlibAnd here's how to view the same data with **matplolib**. You will notice we have to go through a loop to display the three channels and we don't have an easy access to slices.<jupyter_code>fig = plt.figure(figsize=(30, 10))
nb_channels = img_to_view.shape[0]
for x in range(0, nb_channels):
    fig.add_subplot(1, nb_channels + 1, x + 1)
    plt.imshow(img_to_view[x, 0, :, :])<jupyter_output><empty_output><jupyter_text>3.3 Viewing images interactively with matplolib and ipywidgetsWe can put the previous code in a function and use a slider with **ipywidgets** to display and interactive view of the dataset.<jupyter_code>from ipywidgets import interact, IntSlider


def plot_img(slice):
    fig = plt.figure(figsize=(30, 10))
    nb_channels = img_to_view.shape[0]
    for x in range(0, nb_channels):
        fig.add_subplot(1, nb_channels + 1, x + 1)
        plt.imshow(img_to_view[x, slice, :, :])


interact(
    plot_img,
    slice=IntSlider(
        min=0, max=img_to_view.shape[1], step=1, value=0, continuous_update=False
    ),
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09446839080459771, 'fraction_numerical': 0.017241379310344827, 'mean_word_length': 5.067538126361656, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '383942', 'license': 'MIT', 'n_tokens_mistral': 999, 'n_tokens_neox': 949, 'n_words': 310, 'path': '00_BASES_Import_images_AICSIO_and_napari.ipynb', 'repo_name': 'UniversalBuilder/Python-and-Microscopy', 'size': '2784'}