Table of Contents
Edge Detection and De-Convolution using scikit-image python library
In this tutorial, I will show you Edge Detection and De-Convolution using scikit-image python library
First, download the following tools to get started
- Download and install anaconda3 navigation https://www.anaconda.com/products/individual
- Spyder IDE https://www.spyder-ide.org/
Then install scikit-image library on anaconda3 navigator. (scikit-image default library in anaconda3)
Scikit-image Library
Scikit-image is an open-source image processing library for the python language. It consists algorithms for segmentation, color space manipulation, geometric transformation, analysis,filtering,feature detection and much more. The library developed is based on two python libraries numerical(NumPy) and scientific(SciPy).
Let’s discuss the folllowing in this article
- Edge detection
- De-convolution
First we will write some basic coding for image segmentation (Image rescaling, resizing and downscale).
Python coding for rescaling, resizing and downscale.
from skimage import io
from matplotlib import pyplot as plt
img = io.imread(“images/test_image.jpg”, as_gray = True) //Read image path
from skimage.transform import rescale, resize, downscale_local_mean
rescaled_img = rescale(img, 1.0/4.0, anti_aliasing=True)
resized_img = resize(img, (200.0,200.0))
downscaled_img = downscale_local_mean(img, (4,3))
plt.imshow(downscaled_img)
print(img.shape)
Variable output

Output image
Now we will discuss about some edge detection methods available on scikit-image,
Edge Detection
The principal of edge segmentation method, detect the most edge of the image and create the independent part from the image based on edge pixel value. Usually the easiest place to detect a part of an image is the edge of the image. The most intense change of image information takes place at the edges of the image.
from scikit-image library some methods used for edge detection process such as roberts, sobel, scharr, prewitt these method are very difficult to implement on basic coding but scikit-image library doing this huge process in one or two line of code, let see the code
from skimage.filters import roberts, sobel, scharr, prewitt //calling edge detection function from skimage
edge_roberts = roberts(img)
edge_sobel = sobel(img)
edge_scharr = scharr(img)
edge_prewitt = prewitt(img)
fig, axes = plt.subplots(nrows=3, ncols=2, sharex=True, sharey=True, figsize=(8,8))
ax = axes.ravel()
ax[0].imshow(img, cmap=plt.cm.gray)
ax[0].set_title(‘original image’)
ax[1].imshow(edge_roberts, cmap=plt.cm.gray)
ax[1].set_title(‘robet edge edtection’)
ax[2].imshow(edge_sobel, cmap=plt.cm.gray)
ax[2].set_title(‘sobel edge edtection’)
ax[3].imshow(edge_scharr, cmap=plt.cm.gray)
ax[3].set_title(‘scharr edge edtection’)
ax[4].imshow(edge_prewitt, cmap=plt.cm.gray)
ax[4].set_title(‘prewitt edge edtection’)
for a in ax:
a.axis(‘off’)
plt.tight_layout()
plt.show()
Output of the image

These methods are filters methods .Now we will see one of favorite edge filter method on skimage called canny egde detection filter methods. Canny is not the skimage filter it’s one of the feature of skimage. The important benefit of canny edge detection methods remove the noise from images. Because most of the edge detection results are easily affected by noise in the image.
Coding for canny edge detection method
from skimage.feature import canny
edge_canny = canny(img, sigma=3)
plt.imshow(edge_canny)
Note :- sigma plays the role of a scale parameter for the edges: large values of sigma produce coarser scale edges and small values of sigma produce finer scale edges
Output image

If we increase the sigma level example sigma=5
Output

Now look the edge amount
De-convolution
De-convolution is the operation inverse to convolution. This operation used on signal processing and image segmentation. De-convolution is a computationally intensive image processing technique. This technique improves the contrast and resolution of digital images especially on microscope captured images.
Why light microscope captured images blur?
The light spots on a specific spot instead of one specific pixel in light microscope. So this happens while blurring images. The light is spread so that the light create a halo effect. So the halo makes our microscope images worthless. The halo or the way is light spread called Point Spread Function (PSF).
(Note :- the point spread function determine the microscope functional worth.)
De-convolution = original image + point spread function.
from skimage import restoration //the utilization of restoration method for de-convolution process
import numpy as np
psf = np.ones((3,3)) / 9
*psf = point spread function
deconvolved, _ = restoration.unsupervised_wiener(img, psf)
plt.imsave(“images/deconvoled2.jpg”, deconvolved, cmap=’gray’)

So, in conclusion, if you can try the de-convolution coding for microscope captured image we could process an optimistic output.
Therefore in the next article, we can find the above techniques on real-world scenario.
Author: Suhath S M BSc (Hons) in IT, PGD, MSc in IT (R)
Great idea,useful for IT students 👍