Ip Lab Manual
Ip Lab Manual
SUBJECT:
IMAGE PROCESSING
BE (COMPUTER)
SEM VII
IMAGE PROCESSING
INDEX
3 Histogram Equalization
4 Histogram Specification
Tool MATLAB
Theory The negative of an image with gray levels in the range [ 0, L-1] is obtained by
using the negative transformation given by the expression
S= L 1 r(1)
This is according to the transformation S = T ( r ) In above transformation ( 1 ) ,
the intensity of the output image decreases as the intensity of the input increases.
The type of processing is particularly suited for enhancing white or gray detail
embedded in dark regions of an image especially when black areas are dominants
in site.
Tool MATLAB
Theory Thresholding is a simple process to separate the interested object from the
background. It gives the binary image. The formula for achieving thresholding is
as follows
s=0 if r <= t
s = L-1 if r > t
L-1
t L-1 r
Tool MATLAB
Theory Low contrast images can result from poor illumination, lack of dynamic range in
the imaging sensor etc. The idea behind contrast stretching is to increase the
dynamic range of the gray levels in the image being processed. The
transformation function for contrast stretching is given by
r 0 r r1
= (r-r1)+s1 r1 r r2
(r-r2 )+ s2 r2 r L-1
The location of the points (r1 , s1) & (r2 , s2) control the shape of the
transformation function.
Tool MATLAB
Theory This transformation involves determining the number of usually significant bits in
an image. In case of a 8 bit image each pixel is represented by 8 bits. Imagine that
the image is composed of eight 1 bit planes ranging from bit plane 0 for the least
significant bit to bit plane 7 for the most significant bit. Plane 0 contains all the
lowest order bits in the bytes comprising the pixels in the image & plane 7
contains all the high order bits. The higher order bits contain usually significant
data and the other bit planes contribute to more subtle details in the iamge.
Separating a digital image into its bit planes is useful for analyzing the relative
importance played by each bit of the image.
Questions 1. Explain the importance of bit plane slicing in image enhancement & image
compression.
Experiment No. 3 Histogram Equalization
Aim To implement histogram equalization.
Tool MATLAB
Theory Histogram of a digital image with gray levels in range [0,L-1] is a discrete
function h( k) = nk where k kth gray level and nk = no. of pixels of an image
having gray level rk In histogram there are 3 possibilities as follows,
1. For a dark image the components of histogram on the low (dark) side.
2. For a bright image the component are on high ( bright ) side &
3. For an image with low contrast they are in the middle of gray side.
Histogram equalization is done to spread there component uniformly over the gray
scale as far as possible.
This is obtained by function Sk = (limit k to i=0) hi /n;
k = 0,1,2,3,...i-l
Thus processed image is obtained by mapping each pixel with level rk into a
corresponding pixel with level sk in o/p image. This transformation is called
Histogram equalization
Tool MATLAB
Tool MATLAB
Algorithm Replication:
1. Read i/p image.
2. Replicate each pixel
3. Replicate each row
4. Display o/p image
Interpolation
1. Read i/p image
2. Average of two adjacent pixels along the rows is taken and placed between two
pixels.
3. Do the same along columns
4. Display o/p image.
Conclusion Zooming by interpolation is more effective than zooming by replication
Tool MATLAB
Theory Low pass filtering as the name suggests removes the high frequency content from
the image. It is used to remove noise present in the image. Mask for the low pass
filter is :
1/9 1/9 1/9
1/9 1/9 1/9
1/9 1/9 1/9
One important thing to note from the spatial response is that all the coefficients are
positive. We could also use 5 x 5 or 7 x 7 mask as per our requirement. We place a
3 x 3 mask on the image . We start from the left hand top corner. We cannot work
with the borders and hence are normally left as they are. We then multiply each
component of the image with the corresponding value of the mask. Add these
values to get the response. Replace the center pixel of the o/p image with these
response. We now shift the mask towards the right till we reach the end of the line
and then move it downwards.
Tool MATLAB
Theory High pass filtering as the name suggests removes the low frequency content from
the image. It is used to highlight fine detail in an image or to enhance detail that
has been blurred. Mask for the high pass filter is :
One important thing to note from the spatial response is that sum of all the
coefficients is zero. We could also use 5 x 5 or 7 x 7 mask as per our requirement.
We place a 3 x 3 mask on the image . We start from the left hand top corner. We
cannot work with the borders and hence are normally left as they are. We then
multiply each component of the image with the corresponding value of the mask.
Add these values to get the response. Replace the center pixel of the o/p image
with these response. We now shift the mask towards the right till we reach the end
of the line and then move it downwards.
Tool MATLAB
Theory Median filtering is a signal processing technique developed by tukey that is useful
for noise suppression in images. Here the input pixel is replaced by the median of
the pixels contained in the window around the pixel. The median filter disregards
extreme values and does not allow them to influence the selection of a pixel value
which is truly representative of the neighborhood.
Tool MATLAB
Z1 Z2 Z3
Z4 Z5 Z6
Z7 Z8 Z9
Therefore masks are
There are masks along x&y gradient. The sum of two Roberts Masks
1 1
1 1
Algorithm 1. Read i/p image & its size
2. apply prewitt, sobel & laplacian edge masks on i/p image
3. Display i/p image & edge detected image.
Use prewitt mask
1 1 1 1 0 1
m1 = 0 0 0 m2 = 1 0 1
1 1 1 1 0 1
sobel mask
1 2 1 1 0 1
m1 = 0 0 0 m2 = 2 0 2
1 2 1 1 0 1
laplacian
0 1 0
m= 1 4 1
0 1 0
Conclusion Prewitt is simpler to implement but sobel gives the better result. Laplacian is more
sensitive to noise.
Questions 1. Give the difference between first order derivative filter and second order
derivative filter
2. What is compass gradient mask
Experiment No. Data compression using Huffman coding
8
Aim To implement data compression using Huffman coding
Tool MATLAB
Theory It is used to reduce the space that an image uses on disk or in transit. It is the most
popular technique to remove the coding redundancy. When coding the symbols of
an information source individually Huffman coding yields the smallest possible
number of code symbols per source symbol. It is lossless coding technique.
Algorithm 1. Order the gray levels according to their frequency of use, most frequent first
2. Combine the two least used gray levels into one group, combine their
frequencies and reorder the gray levels
3. Continue to do this until only two gray levels are left
4. Now allocate a '0' to one of these gray level groups and '1' to the other
5. Work back through the groupings so that where two groups have been
combined to form a new , larger, group which is currently coded as 'ccc' , code
one of the smaller groups as 'ccc0' and the other as 'cccc1'.
Conclusion Huffman code is an instantaneous uniquely decodable block code.
Tool MATLAB
Theory Low pass filters attenuate or eliminate high frequency components while
leaving low frequencies untouched. High frequency components characterize
edges and other sharp details in an image so that the net effect of low pass
filtering is image blurring. The transfer function for an ideal low pass filter is
given by
H ( u,v ) = 1 if D(u,v) D0 & 0 if D(u,v)>D0
Where D0 is a specified non-negative quality and D(u,v) is the distance from
point (u,v) to the origin of the frequency plane. In case of a NxN image ,
D(u,v) = [(u N/2)2 + (V N/2)2 ]1/2
The point of transition between H(u,v)= 1 and H(u,v)=0 is called cut off
frequency. In this case it is Do .
Algorithm 1. Read the i/p image & its size.
2. Read the cutoff frequency fc
3. Implement the function d =[(u N/2)2 + (V N/2)2 ]
4. Find impulse response such that if d<fc
IR=1 else IR=0 for LPF
5. Find EFT 2- DFT of i/p image .
6. Shift 2D FFT image
7. Multiply IR with shifted 2DFFT o/p element by element.
8. Take absolute multiple value of image
9. Display Low pan image.
Conclusion As cutoff frequency goes on decreasing we get more and more blurring effect.
Questions 1. Why ideal low pass filter gives rise to ringing effect?
Experiment No. Filtering in frequency domain: High pass filtering
9B
Aim To study High Pass Filtering
Tool MATLAB
Theory This class of filters can be designed by their effect of emphasizing or strengthening
the edges within an image. A high pass filter has the inverse characteristic of a low
pass filter, it will not change the high frequency component of the signal but will
attenuate the low frequencies and eliminate any constant background intensity. The
transfer function for an ideal high pass filter is given by
H ( u,v ) = 0 if D(u,v) D0 & 1 if D(u,v)>D0
Where Do is the cutoff distance measured from the origin of the frequency plane.
D(u,v) is the distance from the point (u,v) to the origin of frequency plane for NxN
image
D(u,v) = [(u N/2)2 + (V N/2)2 ]1/2
Tool MATLAB
Theory The Hadamard transform is based on the Hadamard matrix which is a square array
having entries of +1 or -1 only. The Hadamard matrix of order 2 is given by
H(2)= 1 1
1 -1
The rows and columns are orthogonal. For orthogonality of vectors the dot product
has to be zero. We get H(4) from the Kronecker product of H(2)
H(4) = H(2) X H(2)
So we know that the Hadamard matrices of order 2n can be recursively generated
H(2n) = H(2) X H(2n-1)
The rows of Hadamard matrix can be considered to be samples of rectangular
waves with sub-periods of 1/N units.
If x(n) is N-point 1 dimensional sequence of finite valued real numbers arranged in
a column then the Hadamard transformed sequence is given by
X = T.x X[n] = [H(N) x(n)]
The inverse Hadamard transform is given by
x(n) = 1/N H(N) X(n)
For a two dimensional sequence f of size N X N, we compute the Hadamard
transform using equation
F=TfT F = [H(N) f H(N)]