Image Enhancement Technique in Spatial Filtering Method using MATLAB with Source Code

Image Enhancement Technique in Spatial Filtering Method using MATLAB with Source Code

Digital Image Processing Using MATLAB

Introduction
Filter term in “Digital image processing” is stated to the subimage, filtering is a technique for adapting or enhancing an image.
There are others term to call subimage such as kernel, mask, template, or window
The value in a filter subimage are stated as coefficients, rather than pixels.

Basics of Spatial Filtering
Spatial filtering term is the filtering operations that are performed directly on the pixels of an image, Spatial domain operation or filtering (the processed value for the present pixel processed value for the present pixel be contingent on both itself and nearby pixels). Henceforth Filtering is a region operation, the value of any assumed pixel in the output image is determined by applying some procedure to the values of the pixels in the neighborhood of the consistent input pixel. A pixel's area is some set of pixels, defined by their positions relative to that pixel. The concept of filtering has its roots in the use of the Fourier transform for signal processing in the so-called frequency domain.

Mechanics of spatial filtering
The process contains simply of moving the filter mask from point to point in an image.
At each point (x,y) the response of the filter at that point is calculated using a predefined relationship
Linear spatial filtering
Generally, linear filtering of an image f of size MxN with a filter mask of size mxn is given by the expression

The result is the sum of products of the mask coefficients with the corresponding pixels directly under the mask
The coefficient w(0,0) coincides with image value f(x,y), indicating that the mask is centered at (x,y) when the computation of sum of products takes place.

For a mask of size mxn, we assume that m-2a+1 and n=2b+1, where a and b are nonnegative integer. Then m and n are odd.

The process of linear filtering similar to a frequency domain concept called “convolution”

Nonlinear spatial filtering
Nonlinear spatial filters also operate on neighborhoods, and the mechanism of sliding a mask previous an image are the same as was just outlined.
The filtering operation is based conditionally on the values of the pixels in the neighborhood under consideration
Smoothing Spatial Filters
Smoothing filters are used for blurring and for noise reduction.
Blurring is used in preprocessing stages, such as removal of small details from an image prior to object extraction, and bridging of small gaps in lines or curves
Noise reduction can be accomplished by blurring
Type of smoothing filtering
There are two types of smoothing spatial filters
Smoothing Linear Filters
Order-Statistics Filters

Smoothing Linear Filters
Linear spatial filter is just the average of the pixels contained in the neighborhood of the filter mask.
Sometimes it is called “averaging filters”.
The idea is substituting the value of every pixel in an image by the average of the gray levels in the neighborhood defined by the filter mask.
The general implementation for filtering an MxN image with a weighted averaging filter of size mxn is given by the expression


Two 3x3 Smoothing Linear Filters

5x5 Smoothing Linear Filters
Result of Smoothing Linear Filters      

Order-Statistics Filters
Order-statistics filters are nonlinear spatial filters whose response is based on ordering or ranking the pixels contained in the image area included by the filter, and then swapping the value of the center pixel with the value determined by the ranking result.
Best-known as “median filter”
Process of Median filter
Corp region of neighborhood
Sort the values of the pixel in our region
In the MxN mask the median is MxN div 2 +1

Result of median filter

Sharpening Spatial Filters
The principal objective of sharpening is to highpoint fine detail in an image or to enhance feature that has been blurred, either in error or as a natural effect of a specific method of image acquisition.
The image blurring is accomplished in the spatial domain by pixel averaging in a neighborhood.
Since averaging is similar to integration.
Sharpening could be accomplished by spatial differentiation.
Definition for a first derivative
A basic definition of the first-order derivative of a one-dimensional function f(x) is

Must be zero in flat segments
Must be nonzero at the onset of a gray-level step or ramp; and
Must be nonzero along ramps.

Definition for a second derivative
We define a second-order derivative as the difference

Must be zero in flat areas;
Must be nonzero at the onset and end of a gray-level step or ramp;
Must be zero along ramps of constant slope
Analyze
1st make thick edge and
2nd make thin edge
The 1st-order derivative is nonzero along the whole ramp, while the 2nd-order derivative is nonzero only at the start and end of the ramp.
The reply at and around the point is much stronger for the 2nd- than for the 1st-order derivative

MATLAB Source Code For Image Enhancement in Spatial Filtering 

clc;
clear all;
close all;
a=imread('C:\Users\natheem\Desktop\images\mri.jpg');
b=double(a)+50;
subplot(3,3,1);
imshow(a);
title('original image');
subplot(3,3,2);
imshow(uint8(b));
title('enhanced image');
b1=double(a-70);
subplot(3,3,3);
imshow(uint8(b1));
title('brightness suppressed image');
e=a*.5;
f=a*.20;
subplot(3,3,4);
imshow(e);
title('increased in contrast');
subplot(3,3,5);
imshow(f);
title('decreased in contrast');
h1=1/9*ones(3,3);
h2=1/25*ones(5,5);
b1=conv2(a,h1,'same');
b2=conv2(a,h2,'same');
subplot(3,3,6);
imshow(uint8(b1));
title('output usins 3*3 mask');
subplot(3,3,7);
imshow(uint8(b2));
title('output using 5*5 mask');
Result

MATLAB Source Code for using separate figure
















Comments

Popular posts from this blog

Spatial Intensity Resolution Project Using MATLAB with Source Code

Image Intensity Transformation Using MATLAB with Source Code

Histogram Equalization Project Using MATLAB with Source Code