Image Processing and Analysis
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.)
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
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
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