Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Image Processing and Analysis

The document outlines procedures for digital image processing, focusing on histogram analysis, histogram equalization, histogram modeling, and filtering techniques. It includes MATLAB code examples for calculating histograms, equalizing them, and applying median and averaging filters to images with added noise. Additionally, it discusses the effectiveness of different filters for various noise types and emphasizes the importance of histogram inspection in image analysis.

Uploaded by

Asmaa Aljuboori
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Image Processing and Analysis

The document outlines procedures for digital image processing, focusing on histogram analysis, histogram equalization, histogram modeling, and filtering techniques. It includes MATLAB code examples for calculating histograms, equalizing them, and applying median and averaging filters to images with added noise. Additionally, it discusses the effectiveness of different filters for various noise types and emphasizes the importance of histogram inspection in image analysis.

Uploaded by

Asmaa Aljuboori
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Digital image processing and analysis

Exp. No.
1. What do the histogram indicate?
For grayscale images, the first order histogram represents a relative frequency of the
appearance of different levels of gray in the image. In MATLAB, first order histogram
can be both calculated and displayed with a function imhist().

An example
>> [img, map] = imread(’detalj.png’); % Read the indexed image
>> imhist(img,map) % calculate and display the histogram
% with a corresponding color palette
>> [img, map] = imread(’salona.png’); % Read the grayscale image
>> imhist(img) % In this case, palette is not necessary

1.1 Procedure
1. Select several images and display their first order histograms.
What do the axis of the histograms represent?

2 Histogram equalization
Histogram equalization is an operation which changes the histogram of an image so that
the number of pixels is approximately equal for all brightness levels. In MATLAB,
histogram can be equalized with the function histeq():
>> img = imread(’uskoci1.png’); % Read the image
>> img = rgb2gray(img,map); % Convert it to grayscale
>> imgEQ = histeq(img); % Equalize the histogram
>> figure,
>> subplot(1, 2, 1), imshow(img)
>> subplot(1, 2, 2), imshow(imgEQ)
2.1 Procedure
1. Read the images uskoci1:png and salona:png. Display their first order histograms
before and after the histogram equalization.
2. Do you see more details in the images before or after equalization?

3 Histogram modeling
If the function F denotes a cumulative function distribution (CDF) and F -1 denotes her
inverse, and if U denotes a set of number with a uniform distribution on an interval [0,1]
(in this case it means that the image’s pixel values are uniformly distributed between 0
and 1), then a set of numbers F-1(U) has a pixel value distribution equal to F. This fact
can be used for histogram modeling:

An example
>> [img,map]=imread(’salona.png’); % Read the image
>> img=ind2gray(img,map); % Convert it to grayscale
>> imgEQ=histeq(img); % Equalize the histogram to obtain approx.
uniform distribution
>> imgMEQ=imscale(img,[0 1]); % Rescale the values to [0 1]
>> imgMEQ=norminv(imgMEQ,0,10); % Model the histogram to a normal
distribution with a mean
3.1 Procedure
1. Choose an arbitrary image. Model its histogram to obtain a desired distribution
function.
2. Read the image auto.ti f . Model its histogram until the number on the car’s registration
plate becomes visible. (Hint: Check the interval of pixel values in the register plate area,
and determine the mapping of this interval to a larger one.)

4 Average filtering and median filtering


In this part of the exercise we will compare a statistical median filter and a regular
averaging filter with a purpose of image denoising. The scheme of the experiment is
given in Fig. 1.
We can add a noise to the image by calling the function imnoise():
An example

>> [img, map] = imread(’medalja_dubrovnik.png’); % Read the image


>> imgGN = imnoise(img,’gaussian’); % Adding the white noise
>> imgSP = imnoise(img,’salt & pepper’); %Adding the salt and pepper /
impulse noise

Figure 1 Block Diagram of the experiment

Median filter is a statistical filter which is applied block-wise in image processing: for
each input block of a given size the filter results with a median value of this block.
InMATLAB, median filtering is performed using the function medf ilt2().
Averaging, which also can be viewed as a statistical filter, can be obtained with
convolution.

>> imgMF = medfilt2(imgSP,[5 5]); % filtering the noise with a median filter, block
size 5x5
>> maska=ones(5); % create the mask of the desired size (5x5)
>> maska=maska/sum2(maska); % averaging the mask
>> maska % display the mask values % averaging filter is defined with
% a mask whos all elements are the same
maska =
0.0400 0.0400 0.0400 0.0400 0.0400
0.0400 0.0400 0.0400 0.0400 0.0400
0.0400 0.0400 0.0400 0.0400 0.0400
0.0400 0.0400 0.0400 0.0400 0.0400
0.0400 0.0400 0.0400 0.0400 0.0400

>> imgSF = conv2(imgSP,maska,’same’); % Filtering the image with an averaging filter

4.1 Procedure
1. Choose an arbitrary image. Create 2 noisy images from it: one by adding the Gaussian
noise and the other one by adding the salt&pepper noise.
2. Try denoising these images with median and averaging filters. Comment on the results.
Which filter is more appropriate for which type of the noise?

5. Image Filtering
The spatial filters are the most suitable filtering scheme that give efficient result with
different filtering techniques

5.1 Mean Filtering

5. 1. 1 MatLab code (using built in functions)


im=imread('cameraman.tif'); %loading image
I = rgb2gray(im);
%if the image is colored
I=im %if the image is monochrome
figure;imshow (I)
title('original');
N=imnoise (I,'gaussian',0,0.015);
%N=imnoise (I,'salt & pepper',0.006);
figure;imshow (N)
L=padarray(N,[1 1]); % pause
%-----------------------------------
H = fspecial('average',[3 3]);
F=imfilter (N,H);
figure;imshow (F)
5. 1. 2 MatLab code (without using built in functions)

a=imread('cameraman.tif')
I=a;
figure;imshow (I);
%subplot (2,3,1),imshow (I), title (' orginal image') ;
N=imnoise (I,'gaussian',0,0.015);
figure;imshow (N);
L=padarray(N,[1 1]);% pause
%-----------------------------------

[kk,zz]=size(N);
for k=1:kk
for z=1:zz
for i=1:3
for j=1:3
c(i,j)=L(i+(k-1),j+(z-1));
end;
end;
%%%%%%%%%%%%%% mean filter %%%%%%%%%%%
s=sum(sum(c));
average = round (s/9);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
y(k,z)=average;
end
end

6. Discussion
Plot the histogram for all the obtained image, and explain then inspection of each
histogram

You might also like