Processing images using SimpleITK#

See also

import numpy as np
from skimage.io import imread
import napari_simpleitk_image_processing as nsitk
import stackview
blobs = imread('https://samples.fiji.sc/blobs.png')
stackview.insight(blobs)
shape(254, 256)
dtypeuint8
size63.5 kB
min8
max248

Median filter#

nsitk.median_filter(blobs, 5, 5, 0)
n-sitk made image
shape(254, 256)
dtypeuint8
size63.5 kB
min24
max248

Gaussian blur#

nsitk.gaussian_blur(blobs, 10, 10, 0)
n-sitk made image
shape(254, 256)
dtypeuint8
size63.5 kB
min28
max247

Edge enhancement / edge detection#

nsitk.laplacian_filter(blobs)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min-88.0
max72.0
nsitk.laplacian_of_gaussian_filter(blobs, sigma=20)
n-sitk made image
shape(254, 256)
dtypefloat32
size254.0 kB
min-0.15148893
max0.0996153
nsitk.sobel(blobs)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min0.0
max519.0761023202667
nsitk.gradient_magnitude(blobs)
n-sitk made image
shape(254, 256)
dtypefloat32
size254.0 kB
min0.0
max66.211784
nsitk.morphological_gradient(blobs)
n-sitk made image
shape(254, 256)
dtypeuint8
size63.5 kB
min0
max240
nsitk.standard_deviation_filter(blobs)
n-sitk made image
shape(254, 256)
dtypeuint8
size63.5 kB
min0
max89
nsitk.canny_edge_detection(blobs)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min0.0
max1.0

Denoising#

nsitk.bilateral_filter(blobs, radius=10)
n-sitk made image
shape(254, 256)
dtypeuint8
size63.5 kB
min34
max238
nsitk.binominal_blur_filter(blobs, repetitions=20)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min30.42419422074899
max247.4738098724574
nsitk.curvature_flow_denoise(blobs, number_of_iterations=150)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min19.85105575700593
max248.34350816581673

Deconvolution#

kernel = np.zeros((15, 15))
kernel[7,7] = 1
kernel = nsitk.gaussian_blur(kernel, variance_x=3, variance_y=3)
kernel
n-sitk made image
shape(15, 15)
dtypefloat64
size1.8 kB
min0.0
max0.05936943721673174
nsitk.richardson_lucy_deconvolution(blobs, kernel)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min0.36973499065669824
max311.62447178679207
nsitk.wiener_deconvolution(blobs, kernel)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min-626.7738812690973
max1074.581976763582
nsitk.tikhonov_deconvolution(blobs, kernel, regularization_constant=0.5)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min-0.05634032528120539
max172.71681721775462

Background / foreground removal#

nsitk.white_top_hat(blobs)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min0.0
max208.0
nsitk.black_top_hat(blobs)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min0.0
max224.0
nsitk.h_maxima(blobs, height=100)
n-sitk made image
shape(254, 256)
dtypeuint8
size63.5 kB
min8
max148
nsitk.h_minima(blobs, height=100)
n-sitk made image
shape(254, 256)
dtypeuint8
size63.5 kB
min108
max248

Other filters#

rescaled = nsitk.rescale_intensity(blobs)

print(rescaled.max())

rescaled
0.9999999999999999
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min0.0
max0.9999999999999999
nsitk.adaptive_histogram_equalization(blobs, radius_x=5, radius_y=5)
n-sitk made image
shape(254, 256)
dtypefloat64
size508.0 kB
min20.719606939426107
max237.734319340099
nsitk.invert_intensity(blobs)
n-sitk made image
shape(254, 256)
dtypeuint8
size63.5 kB
min7
max247