滤波概览#

在本笔记本中,我们使用细胞核示例图像演示一些更典型的滤波器。

import numpy as np

import matplotlib.pyplot as plt
from skimage.io import imread
from skimage import data
from skimage import filters
from skimage import morphology
from scipy.ndimage import convolve, gaussian_laplace
import stackview
image3 = imread('../../data/mitosis_mod.tif').astype(float)

plt.imshow(image3, cmap='gray')
<matplotlib.image.AxesImage at 0x12d1b7ce940>
../_images/1107f156ea3b98fb630c2bea6468a8a0fb0abccb4f4ee6b2bfa53a7f65a95c85.png

去噪#

用于图像去噪的常见滤波器包括均值滤波器、中值滤波器和高斯滤波器。

denoised_mean = filters.rank.mean(image3.astype(np.uint8), morphology.disk(1))

plt.imshow(denoised_mean, cmap='gray')
<matplotlib.image.AxesImage at 0x12d1ba2df10>
../_images/49ec37ddeaedbcf59741d9c4dbd1ca27ead9a4a5591ea4b176600f63b44803e4.png
denoised_median = filters.median(image3, morphology.disk(1))

plt.imshow(denoised_median, cmap='gray')
<matplotlib.image.AxesImage at 0x12d1b8ef340>
../_images/91f917f59f09e9c7c4b5409fe148b1589496cf0abf9e519bf150a28476c0076f.png
denoised_median2 = filters.median(image3, morphology.disk(5))

plt.imshow(denoised_median2, cmap='gray')
<matplotlib.image.AxesImage at 0x12d1b96bb20>
../_images/49608828f31d0a9ab9c68428c0e09c400d3b18fa6d7d59f3b6fc80af1b78d4b6.png
denoised_gaussian = filters.gaussian(image3, sigma=1)

plt.imshow(denoised_gaussian, cmap='gray')
<matplotlib.image.AxesImage at 0x12d1bbbb880>
../_images/6a0d5ff42a636f64e724bfd66ee0fa10fc0b35bfd20e80a8cfeb27917cae2050.png

我们还可以使用matplotlib将这些图像并排显示。

fig, axes = plt.subplots(1,3, figsize=(15,15))

axes[0].imshow(denoised_mean, cmap='gray')
axes[1].imshow(denoised_median, cmap='gray')
axes[2].imshow(denoised_gaussian, cmap='gray')
<matplotlib.image.AxesImage at 0x12d1bae6d60>
../_images/12981ee94f92a9f21e0f7c810da1d5724b2beb650430cdeca1ffc43b8acdf923.png

顶帽滤波 / 背景去除#

top_hat = morphology.white_tophat(image3, morphology.disk(15))

plt.imshow(top_hat, cmap='gray')
<matplotlib.image.AxesImage at 0x12d1d549c10>
../_images/ea8aef136b032c70c346c1f383994f49951670ba234c69017f4bd8d1fa4a6a77.png

边缘检测#

sobel = filters.sobel(image3)

plt.imshow(sobel, cmap='gray')
<matplotlib.image.AxesImage at 0x12d1ccc6bb0>
../_images/572e1d5995f860a01435483c2e74183d079607d0ba4481c2583c2be31ae1d99d.png

练习#

应用不同半径的顶帽滤波器,并将它们并排显示。