Date post: | 19-Jan-2018 |
Category: |
Documents |
Upload: | dominick-ray |
View: | 242 times |
Download: | 0 times |
CHAPTER 6Filtering the
Images
In this chapter, we will cover:
Filtering images using low-pass filters
Filtering images using a median filter
Applying directional filters to detect edges
Computing the Laplacian of an image
Introduction
Definition:- A Filter.=>is an operation that
amplifis certain bands of frequencies of an image while blocking (or reducing) other image frequency bands
==> is one of the fundamental tasks in signal and image processing
Signals : stationary &non stationary
Why using filter? It is a process aimed1- extracting certain aspects of an image
that are considered to convey importantinformation in the context of a given
application.2- Filtering removes noise in images,3- extracts interesting visual features4- allows image resampling, and so on
When we look at an image, we observe how the different gray-level (or colors) are distributed over the image. Images differ from each others because they have a different gray-level distribution
low pass filter One simple way to achieve this goal is to replace
each pixel by the average value of the pixels around.
The objective of the cv::blur function is to smooth an image by replacing each pixel by the average pixel value computed over a rectangular neighborhood. This low-pass filter is appliedas follows:
cv::blur(image,result,cv::Size(5,5)); This kind of fiter is also called a box fiter low pass filter= box fiter
problem :-In some cases, it might be desirable to give more importance to the closer pixels in the
neighborhood of a pixel. This can be achieved by using a weighted scheme that follows a
Gaussian function (a "bell-shaped" function). The
cv::GaussianBlur function applies such a fiter and it is called as follows:
cv::GaussianBlur(image,result,cv::Size(5,5),1.5);
How does it work?
This is like multiplying each neighboring pixel by 1 over the total number
of pixels and summing all of these values.
Median Filter
Linear & Non-linear
Non-linear filters median filters are particularly useful to
combat salt-and-pepper noise
How does it work? The call to the median filtering function is
done in a way similar to the other filters: cv::medianBlur(image,result,5);
Computing the Laplacian of an image
The Laplacian is another high pass(high frequancy) it show the edges of image.
linear filter that is based on the computation of the imagederivatives. As it will be explained, it computes second-order derivatives to measure thecurvature of the image function.
Relating edges and derivatives
One derivatives
Second derivatives
How it in opencv? The Open CV function cv :: Laplacian
computes the Laplacian of an image. It is very similar to the cv::Sobel function. In fact, it uses the same basic function cv :: getDerivKernels in order to obtain its kernel matrix. The only difference is that there is no derivative order parameters since these ones are by defination second order derivatives. For this operator, we will create a simple class that will encapsulate some useful operations related to the Laplacian.
The Code class LaplacianZC { private: // original image cv::Mat img; // 32-bit float image containing the Laplacian cv::Mat laplace; // Aperture size of the laplacian kernel int aperture; public: LaplacianZC() : aperture(3) {} // Set the aperture size of the kernel void setAperture(int a) { aperture= a; } // Compute the floating point Laplacian cv::Mat computeLaplacian(const cv::Mat& image) { // Compute Laplacian cv::Laplacian(image,laplace,CV_32F,aperture); // Keep local copy of the image (used for zero-crossings) img= image.clone(); return laplace; }
Before code After code
About The Sobel and Laplacian Edge Detectors
The function of The Sobel and Laplacian Edge Detectors is do edge detection.
But Laplacian Edge Detectors is more showing edge detection than Sobel .
It is similar in mask to Sobel that in Sobel the kernel (mask) is 3x3 but compute the Laplacian using larger kernels such as 7x7 kernel.
The disadvanteges is more sensitive to image noise because it show clearly the edges.
You need specific filter according to need of application
The Sobel and Laplacian Edge Detectors
How it work? In its simplest form, it can be
approximated by the following 3x3 kernel:
As for the Sobel operator, it is also possible to compute the Laplacian using larger kernels , and since this operator is even more sensitive to image noise.
zero-crossing
zero-crossing The zero crossing detector looks for
places in the Laplacian of an image where the value of the Laplacian passes through zero.
zero crossings also occur at any place where the image intensity gradient starts increasing or starts decreasing, and this may happen at places that are not obviously edges