Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Digital Image Processing and Analysis Laboratory 4: Image Enhancement

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Digital image processing and analysis

Laboratory 4: Image enhancement


Vedrana Baličević, Pavle Prentašić
2014.

4.1 First order histogram


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

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

4.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(121), imshow(img)
>> subplot(122), imshow(imgEQ)

1
For more details on histeq() function call MATLAB’s built-in help:

>> help histeq

4.2.1 Problems
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?

4.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 distrib
>> 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

4.3.1 Problems
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.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. 4.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

2
Figure 4.1: Scheme 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. In MATLAB, median filtering is performed
using the function med f 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.4.1 Problems
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?

4.5 Unsharpness removal


First attempts of removing the unsharpness from an image consisted of subtracting the blurred version of
an image from the original image. More precisely, the unsharpness is removed using the Eq. 4.1, where A
denotes a positive number larger than 1, and Il f denotes a blurred version of the image (ie. the low-pass
filtered image).

Ihb (x, y) = AI(x, y) − Il f (x, y) (4.1)


0 There are other statistical filters that calculate a certain statistical value for the each input block.

3
The first applications of this method were registered in Germany in 1930s. However, we can observe
this procedure from another point of view, ie. instead of subtracting the blurred image from the original
one, we can add the image with the emphasized edges to the original one. If the image I consists of low and
high derivatives (I = Il f + Ih f ), then the Eq. 4.1 can be rewritten as:

Ihb (x, y) = AI(x, y) − Il f (x, y) = AIh f (x, y) + AIl f (x, y) − Il f (x, y) = (A − 1)Il f (x, y) + AIh f (x, y) (4.2)

From the obtained expression, we can see that we can increase the sharpness of a blurred image by
adding proper high frequencies to it. This procedure is also called high − boost filtering, therefore we
denote the output image as Ihb . The biggest problem of this procedure is to obtain the high frequencies of
the image. In this exercise we will estimate them by means of derivative estimations. The scheme of the
experiment is given in Fig. 4.2. The image is blurred with an averaging mask of an arbitrary size, ie. 3 × 3.

Figure 4.2: Scheme of the experiment.

An example
[img,map]=imread(’blood1.tif’); % read the image
maska=ones(3);
maska=maska/sum(maska(:)); % impulse response of the averaging filter
imgZ=conv2(img,maska,’same’); % image averaging

In a case of one-dimensional signal, the derivative in a point x can be approximated by the following
expression:
f (x + h) − f (x)
∆(x) =
h
In a two-dimensional case, the derivative has it’s direction and the value, and can be estimated with some
of existing operators. In our experiment, we will estimate the first derivative, ie. the gradient, with a Sobel
operator, and the second derivative with a Laplace operator. For that purpose, we use the function f special
for creating the mask that approximates the Laplace operator:

An example
>> lap=fspecial(’laplacian’,0.2) % a mask that approximates the Laplace operator
ans =
0.1667 0.6667 0.1667
0.6667 -3.3333 0.6667
0.1667 0.6667 0.1667

4
4.5.1 Problems
1. Choose an arbitrary image and perform the procedure explained with a scheme in a Fig. 4.2. Display
the difference between the images. How satisfied are you with the increased sharpness (reconstruc-
tion)?

2. Read the image medalja dubrovnik.png and increase her sharpness by subtracting its blurred version
(according to the Eq. 4.1). What did you obtain with this procedure?

3. Read the image medalja dubrovnik.png and increase her sharpness by adding its first derivative esti-
mation, obtained by Sobel operator (according to the Eq. 4.2). What did you obtain?

4. Read the image 5.1.09.tiff from the USC-SIPI database and try to increase the sharpness by adding
the first derivative (gradient) and the second derivative (Laplace operator). Which of these methods
gives better results?

5. What are the results like if you use these masks as Laplacian operator approximations:
   
1 1 1 0 −1 0
1 8 1 , −1 4 −1 (4.3)
1 1 1 0 −1 0

Hint: try this part of the code:

>> lap1=fspecial(’laplacian’,0)
>> lap2=3*fspecial(’laplacian’,0.5)

6. Try both methods (adding the 1st and the 2nd derivative estimation) on several more images. What
is the relevant difference between adding the 1st and the 2nd derivative to an image? Which method
gives better results?

0 Explanation: While adding of the 2nd order derivative estimation, it is added if the central coefficient of the Laplace mask is
positive, and subtracted if the central coefficient of the Laplace mask is negative.

You might also like