Segmentation

Dataset download


[1]:
import numpy as np
import pandas as pd

import skimage.feature
import skimage.filters
import skimage.filters.rank
import skimage.io
import skimage.morphology
import skimage.segmentation

import scipy.ndimage

import colorcet

import bebi103

import bokeh_catplot

import bokeh
bokeh.io.output_notebook()
Loading BokehJS ...

In this part of the lesson, we will continue to use the Bacillus images, but use the more convenient RFP channel to segment our images.

The function we wrote in the last tutorial to display images next to each other is useful.

[2]:
def show_two_ims(
    im_1,
    im_2,
    titles=[None, None],
    interpixel_distances=[0.13, 0.13],
    cmap=None,
):
    """Convenient function for showing two images side by side."""
    p_1 = bebi103.image.imshow(
        im_1,
        frame_height=200,
        title=titles[0],
        cmap=cmap,
        interpixel_distance=interpixel_distances[0],
        length_units="µm",
    )
    p_2 = bebi103.image.imshow(
        im_2,
        frame_height=200,
        title=titles[1],
        cmap=cmap,
        interpixel_distance=interpixel_distances[0],
        length_units="µm",
    )
    p_2.x_range = p_1.x_range
    p_2.y_range = p_1.y_range

    return bokeh.layouts.gridplot([p_1, p_2], ncols=2)

Let’s look at the RFP channel more closely, including a convenient region of the image to consider.

[3]:
# Define directory containing files
im_file = "../data/bacillus_images/rfp.tif"

# So we have it, the interpixel distance
ip = 0.065  # microns

# Get image file
im = skimage.io.imread(im_file)

# Get convenient slice
zoom = np.s_[100:300, 850:1050]

# Display the image, including another nice zoom region
p_1 = bebi103.image.imshow(
    im, frame_height=200, interpixel_distance=ip, length_units="µm"
)
p_2 = bebi103.image.imshow(
    im[zoom], frame_height=200, interpixel_distance=ip, length_units="µm"
)
bokeh.io.show(bokeh.layouts.gridplot([p_1, p_2], ncols=2))