Processing images using SimpleITK#

See also

import numpy as np
import pandas as pd
from skimage.io import imread, imshow
from napari_simpleitk_image_processing import threshold_otsu, median_filter, gaussian_blur, signed_maurer_distance_map,\
    morphological_watershed, morphological_watershed, connected_component_labeling, \
    touching_objects_labeling, watershed_otsu_labeling, binary_fill_holes
blobs = imread('https://samples.fiji.sc/blobs.png')
imshow(blobs)
<matplotlib.image.AxesImage at 0x2b8a6c6eb50>
../_images/simpleitk_2_1.png

Median filter#

imshow(median_filter(blobs, 5, 5, 0))
<matplotlib.image.AxesImage at 0x2b8a6ea45e0>
../_images/simpleitk_4_1.png

Gaussian blur#

imshow(gaussian_blur(blobs, 10, 10, 0))
<matplotlib.image.AxesImage at 0x2b8a6f08370>
../_images/simpleitk_6_1.png

Edge enhancement / edge detection#

from napari_simpleitk_image_processing import laplacian_filter
imshow(laplacian_filter(blobs))
<matplotlib.image.AxesImage at 0x2b8a73b2610>
../_images/simpleitk_8_1.png
from napari_simpleitk_image_processing import laplacian_of_gaussian_filter
imshow(laplacian_of_gaussian_filter(blobs, sigma=20))
<matplotlib.image.AxesImage at 0x2b8a8464250>
../_images/simpleitk_9_1.png
from napari_simpleitk_image_processing import sobel
imshow(sobel(blobs))
C:\Users\rober\Anaconda3\envs\bio_39\lib\site-packages\skimage\io\_plugins\matplotlib_plugin.py:150: UserWarning: Float image out of standard range; displaying image with stretched contrast.
  lo, hi, cmap = _get_display_range(image)
<matplotlib.image.AxesImage at 0x2b8a851e640>
../_images/simpleitk_10_2.png
from napari_simpleitk_image_processing import gradient_magnitude
imshow(gradient_magnitude(blobs))
<matplotlib.image.AxesImage at 0x2b8a85cfe80>
../_images/simpleitk_11_1.png
from napari_simpleitk_image_processing import morphological_gradient
imshow(morphological_gradient(blobs))
<matplotlib.image.AxesImage at 0x2b8a867dbe0>
../_images/simpleitk_12_1.png
from napari_simpleitk_image_processing import standard_deviation_filter
imshow(standard_deviation_filter(blobs))
<matplotlib.image.AxesImage at 0x2b8a86eedf0>
../_images/simpleitk_13_1.png
from napari_simpleitk_image_processing import canny_edge_detection
imshow(canny_edge_detection(blobs))
<matplotlib.image.AxesImage at 0x2b8a875e0d0>
../_images/simpleitk_14_1.png

Denoising#

from napari_simpleitk_image_processing import bilateral_filter
imshow(bilateral_filter(blobs, radius=10))
<matplotlib.image.AxesImage at 0x2b8a87b7b50>
../_images/simpleitk_16_1.png
from napari_simpleitk_image_processing import binominal_blur_filter
imshow(binominal_blur_filter(blobs, repetitions=20))
<matplotlib.image.AxesImage at 0x2b8a881baf0>
../_images/simpleitk_17_1.png
from napari_simpleitk_image_processing import curvature_flow_denoise
imshow(curvature_flow_denoise(blobs, number_of_iterations=150))
<matplotlib.image.AxesImage at 0x2b8a88d5370>
../_images/simpleitk_18_1.png

Deconvolution#

kernel = np.zeros((15, 15))
kernel[7,7] = 1
kernel = gaussian_blur(kernel, variance_x=3, variance_y=3)
imshow(kernel)
C:\Users\rober\Anaconda3\envs\bio_39\lib\site-packages\skimage\io\_plugins\matplotlib_plugin.py:150: UserWarning: Low image data range; displaying image with stretched contrast.
  lo, hi, cmap = _get_display_range(image)
<matplotlib.image.AxesImage at 0x2b8a8991970>
../_images/simpleitk_20_2.png
from napari_simpleitk_image_processing import richardson_lucy_deconvolution
imshow(richardson_lucy_deconvolution(blobs, kernel))
<matplotlib.image.AxesImage at 0x2b8a9a2a2b0>
../_images/simpleitk_21_1.png
from napari_simpleitk_image_processing import wiener_deconvolution
imshow(wiener_deconvolution(blobs, kernel))
<matplotlib.image.AxesImage at 0x2b8a9ac9e80>
../_images/simpleitk_22_1.png
from napari_simpleitk_image_processing import tikhonov_deconvolution
imshow(tikhonov_deconvolution(blobs, kernel, regularization_constant=0.5))
<matplotlib.image.AxesImage at 0x2b8a9b94ca0>
../_images/simpleitk_23_1.png

Background / foreground removal#

from napari_simpleitk_image_processing import white_top_hat
imshow(white_top_hat(blobs))
<matplotlib.image.AxesImage at 0x2b8a9c37f40>
../_images/simpleitk_25_1.png
from napari_simpleitk_image_processing import black_top_hat
imshow(black_top_hat(blobs))
<matplotlib.image.AxesImage at 0x2b8a9ce9790>
../_images/simpleitk_26_1.png
from napari_simpleitk_image_processing import h_maxima
imshow(h_maxima(blobs, height=100))
<matplotlib.image.AxesImage at 0x2b8a9db0130>
../_images/simpleitk_27_1.png
from napari_simpleitk_image_processing import h_minima
imshow(h_minima(blobs, height=100))
<matplotlib.image.AxesImage at 0x2b8a9e1f280>
../_images/simpleitk_28_1.png

Other filters#

from napari_simpleitk_image_processing import rescale_intensity
rescaled = rescale_intensity(blobs)

print(rescaled.max())
imshow(rescaled)
0.9999999999999999
<matplotlib.image.AxesImage at 0x2b8a9e80610>
../_images/simpleitk_30_2.png
from napari_simpleitk_image_processing import adaptive_histogram_equalization
imshow(adaptive_histogram_equalization(blobs, radius_x=5, radius_y=5))
<matplotlib.image.AxesImage at 0x2b8a9ee3670>
../_images/simpleitk_31_1.png
from napari_simpleitk_image_processing import invert_intensity
imshow(invert_intensity(blobs))
<matplotlib.image.AxesImage at 0x2b8a9f9c3d0>
../_images/simpleitk_32_1.png