Image Enhancement
scikit-shape
includes algorithms for image enhancement that can be
used for image preprocessing to improve performance of image analysis
algorithms. Some of these enhancement algorithms act like denoising
algorithms. They reduce noise or variation in the image while preserving
or improving salience of important features, such as edges, in the image. These
algorithms can be found in the module skshape.image.enhancement
.
Below we include an example, in which we apply a spatially-varying
weighted smoothing to the given image to remove noise and clutter
within regions.
Weighted image smoothing
The function weighted_smoothing()
in module skshape.image.enhancement
module can be used to apply a spatially-varying weighted smoothing to the given
image. The weighting of the smoothing is such that it is strong within low-variation
image regions, away from region boundaries, and it is minimal on edges or boundaries.
Thus, it smoothes the image within regions, but keeps the edges sharp. The spatial
weight of the smoothing is given by the edge indicator function, whose value is close
to 1 in smooth areas of the image, but small on locations of high variation or high
image gradient, such as edges. The definition of the edge indicator function
g(x) is given by
where x is the spatial location on the image and I(x) is the image intensity function.
The weighted smoothing procedure can be applied to an image as shown below
>>> import matplotlib.pyplot as plt
>>> from skshape.image.enhancement import weighted_smoothing
>>> image = plt.imread('data/bacteria.jpg') / 255.0
>>> smoothed_image = weighted_smoothing( image )
>>> plt.figure()
>>> plt.subplot(1,2,1); plt.axis('off'); plt.gray()
>>> plt.title('Original image'); plt.imshow(image)
>>> plt.subplot(1,2,2); plt.axis('off'); plt.gray()
>>> plt.title('Smoothed image'); plt.imshow(smoothed_image)
>>> plt.show()
The amount of smoothing can be adjusted with the parameters diffusion_weight
and data_weight of the function weighted_smoothing()
. Increasing
diffusion_weight will make the result smoother, and increasing data_weight
will keep the result closer to the original image. The following shows the
input image used by the example above, and the resulting smoothed image.

