B.Sc. (CS) TY Unit4 FOIP (BCS-602)
B.Sc. (CS) TY Unit4 FOIP (BCS-602)
Background
The term spatial domain refers to the image plane itself and the methods in this category are
based on the direct manipulation of pixels of an image.
In Intensity transformation, the processing operations are done directly on the pixels present
inside the image.
g(x,y)=T[f(x,y)]
Where, f(x,y) is an input image, g(x,y) is the output i.e. processed image and T is an
operator on f.
Following is the most commonly used intensity transformation function imadjust () function
which can also be called gamma transformation.
Basic intensity transformation using imadjust () function-
The function imadjust () is the basic IPT tool for intensity transformation of gray scale
images or intensity images. It has the basic syntax:
g=imadjust(f,[low_in high_in ],[low_out high_out ],gamma);
In above syntax, f is an input image and g is the mapped image or adjusted image.
The intensity values below low_in or equal to low_in will map to low_out and values above
high_in and equal to high_in map to high_out.
The input image can be of data class uint8, uint16 or double class and output image hassame
class as input.
The values of low_in,high_in, low_out, high_out should be in the range[0 1]. The imadjust
function multiplies these values by 255 for unit8, and 65535 for unit16.
Using empty matrix [ ] for [low_in high_in] or for [low_out high_out] results in the default
values [0 1].
The parameter gamma specifies the shape of curve that maps the intensities of Input image f
to g.
The default value of gamma parameter is 1, then it is called as linear mapping. If gamma is
less than 1 then mapping is weighted towards brighter output values and if itis greater than 1
then mapping is weighted towards darker output values.
Example
In an image histogram ,the horizontal axis(x axis) of the graph represents the gray level
intensities, while the vertical axis(y axis) represents the total number of pixels or frequency
of these intensities.
The histogram of a digital image with L total possible intensity levels in the range[0,G] is
defined as the discrete function.
h(rk)=nk
Where, rk is the kth intensity level in the interval [0,G] and nk is the number of pixels in the
image whose intensity level is rk.
The value of G is 255 for images of class uint8 and 65535 for images of class uint16 and 1 for
images of class double.
Normally the image histogram can be normalized by simply dividing all elements of h(rk)
with the total number of pixels in the image.
P(rk)=h(rk)/n
=nk/n
Computing histogram
The basic IPT tool to compute image histogram is imhist() function which has the following
basic syntax:
h=imhist(f,b)
Where, f is an input image,h is its histogram(h(rk)) and b is the number of bins(parts) used
in forming the histogram.
Example
%Computing histogram
>> f=imread('cameraman.tif');
>> size(f)
ans =
256 256
>> 256*256
ans =
65536
>> h=imhist(f,2)
h=
26477
39059
1. Bar graph
The x axis of the histogram shows the range of intensities or gray levels whereas on the y
axis, it is the frequency(count) of the intensities of each gray level.
If input image is of data class uint8, that means it has 256 different gray levels or shades of
gray in it. That’s why the range of x axis starts from 0 and end at 255.
bar(horz,v,width)
Where, v is a vector containing the points to be plotting, horz is a vector of same size as v
that contains the increment of the horizontal scale and width is a number between 0 and 1.
If horz is omitted, the horizontal axis is divided in units from 0 to length(v).
The default value of width is 0.8.
Example
2. Stem graph
A stem graph is similar to the bar graph. It is also used to plot the image histograms.
stem(horz,v,’color_linestyle_marker’,’fill’)
Where v is a row vector containing the points to be plotting, horz is a vector of same
dimension as v.
The fill keyword fills the specified color into the marker if it is square, circle or diamond.
Example
Output
The plot graph plots a set of points of image histogram and link them with a straight line.
plot(horz,v,’color_linestyle_marker’)
Where, v is a row vector containing the points to be plotting, horz is a vector of same
dimension as v and the argument ’color_linestyle_marker’ is described as above in the table
in stem graph.
Example
Output:
Where f is the input image, nlev is the number of intensity levels(L) specified for the output
image.
Histogram Equalization of digital image is used to improve the quality of given input image
i.e. contrast level of image.
Example-
>> %Histogram Equalization of digital image in MATLAB
>> f=imread('tire.tif');
>> h=histeq(f);
>> subplot(2,2,1),imshow(f),title('Input Image(f)')
>> subplot(2,2,2),imhist(f),title('imhist(f)')
>> subplot(2,2,3),imshow(h),title('imshow(h)')
>> subplot(2,2,4),imhist(h),title('imhist(h)')
Output-
Image processing operations are implemented with filtering include smoothing, sharpening and
edge enhancement.
In Image processing, we can perform two types of processing on the images such as spatial
domain processing and frequency domain processing.
The operations performed in spatial domain of an image again further classified into intensity
transformation and Spatial filtering.
Then perform operations on these surrounded pixels i.e. neighbourhood pixels and assign the
resultant intensity value is to the centered pixel by repeating this process for every pixel in the
image.
The function used to perform linear spatial filtering is imfilter() whose syntax is:
g=imfilter(f,w,’filter_mode’,’boundry_option’,’size_option’);
a) p
The boundry of the input image is extended by padding with a value p. This is a default
buoundry option with value zero.
b) ‘replicate’
The boundry of the input image is extended by replicating the values in it’s outer border.
c) ‘symmetric’
The boundry of the input image is extended by mirror reflecting the values accross it’s
border.
5) ‘size_option’
It has following values which are explained as below-
a) ‘Same’
The size of the output image is same as an input image.
b) ‘full’
The size of the output image is same as an extended image.
Example
g=colfilt(f,[m n],’sliding’,@function,parametrs)
Where, f is an input image, [m n] is a dimension of filter region,’sliding’ indicates that
the process is one of sliding the MXN region from pixel to pixel in the input image f.
The @ symbol is called a function handle which is any valid matlab function.
The parameters indicate parameters required by the function.
Example
>> %Non-Linear Spatial Filtering
>> f=imread('rice.png');
>> g=colfilt(f,[3 3],'sliding',@min);
>> h=colfilt(f,[3 3],'sliding',@max);
>> i=colfilt(f,[3 3],'sliding',@median);
>> subplot(2,2,1),imshow(f),title('Input Image');
>> subplot(2,2,2),imshow(g),title('Low pass filtering');
>> subplot(2,2,3),imshow(h),title('High pass filtering');
>> subplot(2,2,4),imshow(h),title('Median filtering');
Output: