%matplotlib inline
import math
import numpy as np
import matplotlib.pyplot as plt
from skimage import io
from skimage.morphology import erosion, dilation
from skimage.morphology import disk
Change the size of the structural element to understand how the output changes.
def plot_comparison(original, filtered, filter_name):
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(10, 10), sharex=True,
sharey=True)
ax1.imshow(original, cmap=plt.cm.gray)
ax1.set_title('original')
ax1.axis('off')
ax2.imshow(filtered, cmap=plt.cm.gray)
ax2.set_title(filter_name)
ax2.axis('off')
image = io.imread("../images/nuclei-dapi.tif")
To study the effect of morphological filters we will work with a binarised verison of the image
threshold = 33
binary = ~(image <= threshold)
selem = disk(4)
dilation = dilation(binary, selem)
plot_comparison(binary, dilation, 'dilation')