You are on page 1of 25

Universite Paul Sabatier

IMAGE PROCESSING
U.E 22 EARTH OBSERVATION
APARNA VEER
2/14/2014

2

CONTENTS:

Sr.No.

Title

Page No.

1.

SOME BASIC DEFINITIONS AND
CONCEPTS

3

2.

HUMAN VISION Vs COMPUTER VISION

4

3.


THE HSV(Hue-Saturation-Value) COLOR
SPACE

4

4.


IMAGE FILTERING

5

5.

MATHEMATICAL OPERATIONS

6

6.

IMAGE RESTORATION

10

7.

DATA PROCESSING

13

8.


CONCLUSIONS

15

9.

APPENDIX

16

3

1. SOME BASIC DEFINITIONS AND CONCEPTS:

An Image: An image can be defined in various contexts. In laymans terms it can be a
photo, picture or painting of something, a mental representation or expression of an idea or, like
in optics, an appearance or a counterpart produced by light (mostly by convergence) from an
object reflected in a mirror or refracted through a lens.
In computer vision, we take it as a picture captured by a camera, to put it simply. Capturing an
image might not be a complicated task, but processing it such that its of optimum use to us is the
challenge. In computer vision, an image is categorically defined as follows:
An image is a bounded and discrete application
I : N N N
(u, v) I(u, v)
which associates a value I to a pixel (u, v).
Resolution and a Pixel: A pixel is the atomic element forming the image, in which
information is uniform. A pixel is assigned size unity and the size of an image is given by the
number of pixels in it. Resolution can be explained in terms of pixel. It is either the number of
pixels in an area or the smallest visible detail in the scene.
Color in Images: A color image is coded with 3 matrices, each associated to a channel. This
codage is called the RGB color space. Color spaces are, in effect, a given set of names or
numbers which are defined by the existence of a corresponding set of physical color swatches.
The various different color spaces that exist today are the RGB, HSV, CMYK, YUV etc. color
spaces.
Image Format: There are several different graphic file formats such as JPEG, GIF,
TIFF, PNG, BMP etc.,to name a few really popular ones. They can be compared with each other
on the basis of factors like file sizes, compression, color types, transparency and interlacing as
follows:

JPEG (Joint Photographic Experts Group): 24 bit color, small file size, best for photographic
images.

GIF(Graphical Interchange Format) : graphics that use few colors. Best for icons, buttons,
cartoons.

TIFF(Tagged Image File Format) : very complicated but lossless compression and 24bit color.
It is the best for high graphic applications.

PNG (Portable Network Graphic): far surpass GIF, so will most likely someday completely
replace GIFs.

4

BMP (Bit-Map): antiquated (obsolete), does not support much compression, transparency or
interlacing. Best for Windows.


2. HUMAN VISION Vs COMPUTER VISION:

The human vision serves as the ideal in developing computer vision, since it is humans that have
developed the computer science and it will be them using the images. So the theme of computer
vision has always been to duplicate the abilities of human vision by electronically perceiving and
understanding an image. But there is a big difference between the two. Human vision is fallible,
while the computer vision is not. We will consider this through an example. The following figure
has a bar in the middle is of uniform color while the gray in the rest of the image is a varied hue.


Figure 1 : Human Vision Vs Computer Vision

However, looking at the image and the bar particularly, it does not appear to be of uniform color.
But it is. And the computer vision sees it that way, but not the human eye.


3. THE HSV(Hue-Saturation-Value) COLOR SPACE:

Using the HSV color space, a disk with a spectrum covering all colors and customized brightness
can be obtained (See Appendix for Program). The RGB color space can also give a color
combination of this type which would include all colors, but the program for it would be way
more complicated. The HSV requires only one matrix (H) to define a set of colors, basically
ranging from 0 to 1 on the circle contour. Brightness can be customized by working on another
matrix (V). The color disk obtained is as follows:
5


Figure 2 : Use of HSV Color Space

4. IMAGE FILTERING:
Image filtering allows you to apply various effects like noise removal, sharpening, deblurring etc.
on pictures. We consider an example here using a picture or photo taken during class with the
objective of changing the hue of the green mouse pad in it. This will be achieved by converting
the image to the HSV color space, applying the Hue threshold selection taken from the mouse
pad sample and setting the Hue to 1 for displaying the selection. (See Appendix for program).
The following are the two images- before and after:

Figure 3 : Filtering the Green Mouse-Pads (Before- Left, After- Right)
6


5. MATHEMATICAL OPERATIONS:
We discuss here some basic mathematical operations used in image processing.
CONVOLUTION:
Convolution can be defined by the following equation:

In image filtering, different kernels can be applied on an image and their choice greatly changes
the resulting convolution product. A point to note is to normalize the kernel while using it, i.e. for
ex. if a kernel is a 3NN matrix, then it should be divided by 9.
Examples of some typical kernels used for various operations can be given below:
For Sharpening:

For blurring:

A simple edge detection kernel: (-1 1)
Sobel filtering for clever horizontal edge detection:


We apply all these above kernels to an example image of Earth so as to see visually how these
kernels work. The figures are as below:
7


Figure 4 : Application of Different Kernels

FOURIER TRANSFORM:
The Fourier Transform in 2D can be defined with the help of the equation below:

The Fourier Transform helps in moving to the frequency domain which lets us perform some
specific operations for processing the image. We again consider an example here. When
performing the FTT on an image (See Appendix for program) with fields, the intensity is found to
8

be stronger in the frequency domain. If we isolate the more intense parts, we see that they could
be isolated on the basis of their geometry. Frequencies are shifted to have them higher on the
middle of the screen after doing a 2D Fourier Transform. The more intense part of the Fourier
Transform is concentrated on the middle (after shifting), to isolate specific shapes we need to
hide it or we keep most part of the original image information.

Figure 5 : Fourier Transform

MATHEMATICAL MORPHOLOGY:
Mathematical Morphology (MM) is a theory and technique for the analysis and processing of
geometrical structures, based on set theory, lattice theory, topology, and random functions. MM
9

is most commonly applied to digital images, but it can be employed as well on graphs, surface
meshes, solids, and many other spatial structures.
We here use it to perform Dilatation or Erosion of images using a Structuring Element (SE)
or research zone selection in order to process our image. The basic difference between
Dilatation and Erosion is that in the former, we are searching for the maximum of SE while in the
latter we are searching for the minimum of SE. These two techniques can be used for efficient
and fast filtering operations. The SE should be chosen according to what we want to select in the
image.
For ex., If we perform these operations (Refer Appendix) on an image with SE as

And display the results in the following figure:



Figure 6 : Effect of Dilatation and Erosion on an Image

The following effects are observed in the above image:
DILATATION: There is a growth like observation of the global shape which duplicates edge
black pixels and propagates them on closer white pixels.
EROSION: Inverting, those pixels are deleted in which the SE shape does not fit (small man on
the bottom right); the sole remaining part is just one pixel at the center of the head. The
explanation for this could be that, that was the only part of the man which could contain the SE.
More complex filtering like reducing the noise outside a given shape by performing an Erosion
and then a Dilatation to go back to the original shape or reducing noise inside the shape by
performing a Dilatation and then an Erosion, can be performed by processing with these
operations.
The size of SE is crucial and it should be according to the shape and size of the noise we want to
suppress, or we could have the remaining noise (if shape is too small) or degrade the image too
much (shape is too big).
10

6. IMAGE RESTORATION:

BLURRING AND DEBLURRING (Linear):
If Y is the image we aim to restore by reducing the blur, the operation can be given by the
following equation:

Here, I is the non blurred image, H is the linear filter and B is the noise.
Applying an Invert Filter G, where

The restored image is given by:

Starting from the initial model,



BLURRING AND DEBLURRING ON A SIMPLE GRAY SCALED IMAGE:
Blurring is applied on an image of Toulouse here and the Kernel used consists of an N
dimensioned Matrix of ones and noise is ignored for simplification. (Refer Appendix). The result
of applying a linear filter in the frequency domain can be seen in the figure below:
11


Figure 7 : Blurring and FTT
There is an appearance of null lines and shaping squares in frequency domain, which is an
equivalent of a sinus cardinal in one dimension as a squared filter was applied that is equivalent
to a door function in one dimension and has a sine cardinal representation in frequency domain.
For deblurring also, the same described process if followed based on the result of Fourier
Transform.


12

MOTION BLURRING:
Motion blur is the apparent streaking of rapidly moving objects in a still image or a sequence of
images such as a movie or animation. It results when the image being recorded changes during
the recording of a single frame, either due to rapid movement or long exposure.
We will work here on motion blurring by taking a photo of a walking person which is blurred due
to motion.
We use the Wiener Filtering technique. It minimizes the mean square error between the initial
image and the estimated restored image.

But,

So,

This function admits a minimum and in this case:

G can thus be given by:

On Fourier Transforming our image (Refer Appendix) we observe lines (but not squared). The
origin of the blurring is not the same as the linear filter applied previously and the image cannot
be restored with the method of invert filtering presented in previous section.
13


Figure 8 : Motion Blur and FTT

7. DATA PROCESSING:

Data processing is, broadly, the collection and manipulation of items of data to produce
meaningful information. It consists of 3 phases, viz. preprocessing, modeling and classification.
Preprocessing phase consists of detecting inconsistent data, the modeling phase compares a
model to the data and shows differences and classification phase consists of processing data with
their common points and data processing objectives.

CLASSIFICATION: Classification varies according to the context. Some types are discussed
here:

The kNN (k- Nearest Neighbor): It has the simplest algorithm. The principle is to find the
closest element in the database and to attribute the class of the neighbors to the current element.

Bayesian: It is based on probabilities.

Linear: It is the simplest classification; it consists of finding a hyperplan that separates the space
in two regions.

Unsupervised: For complex case, it can be done by clustering data, reducing data, to regression
(based on the minimization of the distance between data and its projection on a line/polynomial).






14

COLOR CLASSIFICATION ON A THREE COLOR PICTURE (Example case):

A three color picture of red, black and white as shown in the figure below is applied with simple
color classification. On the three matrices obtained from each color kNN classification, it can be
observed that each color is easily separable from the other because the exact three data elements
could be identified. (An image containing more than 3 colors would be difficult to classify..)


Figure 9 : Classification of 3 Different Colors



15

EXAMPLE CASE OF A MORE ADVANCED IMAGE PROCESSING:

In this example we will use a satellite image with many different colors, the objective being
isolation of the beach from the image.
We could either take the beach pixels color samples & calculate a mean value which will be used
as a threshold to evaluate distance in order to apply kNN classification (See Appendix), or
because of the presence of white waves, we can pre-process or re-process the image and replace
the waves pixels. White pixels from waves are saturated in colors and so are easy to replace with
a high RGB threshold value. As the result shown in the figure below, we observe a lot of
unwanted pixels. Their presence is because they matched our classification, and so are kept after
the pixels selection.


Figure 10 : Isolation of the Beach with waves (Left) and without Waves (Right)


8. CONCLUSIONS:

Computer vision with the help of image processing helps us to do what we cannot, with just the
human eye vision. We can save the images as data, transfer them, process them, observe objects
in varying frequencies of the spectrum of light and so on.
Mathematical methods like the Fourier Transforms and the Convolution products help us in
bettering our image processing quite reliably. Damaged or unsatisfactory images can be
16

processed to make them usable using the filters and various techniques we discussed through this
report. Blurred images due to motion blurring or otherwise could be tackled using simple kernels
to restore the original image. Mathematical Morphology can be used to eliminate noise in the
images. Processing erosion after dilatation on a noised image, most of the small noise outside an
object can be suppressed.
Isolating a specific color or a set of colors in a given image is another useful method we saw that
helps in data analysis.


9. APPENDIX:

PROGRAMS:

Human Perception
%% Human Perception
% In this program we will learn to build a grey scaled image and show how
% human perception can be wrong
clear all;close all;clc;
%% Parameters
n = 1000; m = 2000;
bar = 1000;
barwidth = 100;
I=zeros(n,m);
%% Building Image
for i=1:n
for j=1:m
I(i,j)=j; %Grey gradiant
end
end
for i=n/2-barwidth/2:n/2+barwidth/2
for j=1:m
I(i,j)=bar; %Unicolor bar
end
end
%% Display
figure, imagesc(I), colormap('gray')

HSV Circle
%% HSV use
% In thise program we will take advantage of the HSV color space to create
% a colored disc with all colors and shadowing gradient
clear all; close all; clc;
%% Parameters
cote=400;
17

taille = ones(cote,cote);
% initialisations
I = taille; I2 = taille; I3 = taille;
teinte=0;
tempI=0; tempI2=0; tempI3=0;
%% Image Creation
for i=1:cote;
for j=1:cote;
it=i-cote/2;
jt=j-cote/2;
if sqrt((it)^2+(jt)^2) < cote/2
d = sqrt((it)^2+(jt)^2);
tempI2 = d/(cote/2);
tempI3 = d/(cote/2);
z = complex(it,jt);
tempI = angle(z)/(2*pi)+0.5;
else
tempI = 0;
tempI2 = 0;
tempI3 = 1;
end
I(i,j)=tempI;
I2(i,j)=tempI2;
I3(i,j)=tempI3;
end
end
%% Creation matrice HSV & Conversion to RGB
Ihsv(:,:,1) = I; Ihsv(:,:,2) = I2; Ihsv(:,:,3) = I3;
%convertion HSV vers RGB
Irgb = hsv2rgb(Ihsv);
%% Display
figure, image(Irgb);

Filtering with HSV
%% HSV filtering
%In this program we will filter the green mousepads wiht HSV color space
clear all; close all; format long;
%% Image importation and transformation to HSV
Irgb = imread('HSV_filtering_1.jpg');
Ihsv = rgb2hsv(Irgb);
%% Image Processing
hue = Ihsv(:,:,1);sat = Ihsv(:,:,2);val = Ihsv(:,:,3);
taille = size(Ihsv);taillex = taille(1);tailley = taille(2);
%Mouse pads Hue value
18

h_t = [0.30 0.50];
s_t = [0.40 0.70];
v_t = [0.40 0.60];
for i=1:taillex
for j=1:tailley
if hue(i,j) > h_t(1) && hue(i,j) < h_t(2) && ...
sat(i,j) > s_t(1) && hue(i,j) < s_t(2) && ...
val(i,j) > v_t(1) && hue(i,j) < v_t(2)
hue(i,j)=1;
end
end
end
Ihsv_t(:,:,1) = hue;Ihsv_t(:,:,2) = sat;Ihsv_t(:,:,3) = val;
Irgb_t = hsv2rgb(Ihsv_t);
%% Display
figure, image(Irgb)
figure, image(Irgb_t)

Earth Filtering
%% Earth Filtering, convolution
% The goal is to show the impact of different kernel on the image
clear all;close all;clc;
%% Parameters
N = 10; % kernel of ones size
I = imread('Terre.jpg');
[x,y,z] = size(I);
%% Filtering
% Kernel Creation
k1 = ones(N)/(N*N); % Ones Kernel (Blur)
k2 = [0 -1 0; -1 5 -1;0 -1 0]; % Sharpen
k3 = (1/9)*[-1 0 1; -2 0 2;-1 0 1]; % Sobel filter (Edge Detection)
%% Applying Kernel and Treshold on image
J1 = convn(I,k1,'full');J1=uint8(J1);
J2 = convn(I,k2,'full');J2=uint8(J2);
J3 = convn(I,k3,'full');J3=uint8(J3);
%% Display
figure
subplot(2,2,1), imagesc(I), title('Original')
subplot(2,2,2), imagesc(J1), title('Blur : Ones Kernel')
subplot(2,2,3), imagesc(J2), title('Sharpened')
subplot(2,2,4), imagesc(J3), title('Edge : Sobel Filter')

Fourier: Filtering within frequency domain
%% Fourier Transformation for filtering
19

%We want to extract a specific field on a picture
clear all;close all;clc;
%% Parameters
I = imread('FFT_vergers.bmp');
[x,y,z]=size(I);
Y4=ones(x,y,z);
%bar 1 parameters
a=1/1.32; %slope
b=63;
bar=6; %width
%bar 2 parameters
a2=-1/0.8; b2=575; bar2=6;
d=10; %hidding middle disc size
%% FFT operations
Y=fftn(double(I));
Ys=fftshift(Y);
Y2=fftshift(abs(Y));
%% Cuting power spectrum
for j=1:x
for k=1:y
jc=j-x/2; kc=k-x/2; %getting to center of relative frame
if (j <= k*a+b+bar) && (j >= k*a+b-bar) %bar 1 condition
Y4(j,k,1)=Ys(j,k,1);
Y4(j,k,2)=Ys(j,k,2);
Y4(j,k,3)=Ys(j,k,3);
end
if (j <= k*a2+b2+bar2) && (j >= k*a2+b2-bar2) %bar 2 condition
Y4(j,k,1)=Ys(j,k,1);
Y4(j,k,2)=Ys(j,k,2);
Y4(j,k,3)=Ys(j,k,3);
end
if sqrt(jc*jc+kc*kc)<=d %disc condition
Y4(j,k,1)=1;
Y4(j,k,2)=1;
Y4(j,k,3)=1;
end
end
end
%% Conversion and turning back to spatial
Y3=abs(Y4); Y5=ifftn(Y4);
%log10 transformation
Y2=log10(Y2); Y3=log10(Y3); Y5=abs(Y5);
%Norm to 1
for i=1:3
20

Y2(:,:,i) = Y2(:,:,i)/max(max(Y2(:,:,i)));
Y3(:,:,i) = Y3(:,:,i)/max(max(Y3(:,:,i)));
Y5(:,:,i) = Y5(:,:,i)/max(max(Y5(:,:,i)));
end
%% Display
figure
subplot(2,2,1),imagesc(Y2), title('Image 2D FFT')
subplot(2,2,2),imagesc(Y3), title('Phase we choose to keep')
subplot(2,2,3),imagesc(I), title('Original Image')
subplot(2,2,4),imagesc(Y5), title('Image created from kept phase')

MorphoMat
%% MorphoMat
% showing impact of Errosion and Dilatation on Image
clear all; close all; clc;
%% Importation
I = imread('Diplo1.gif');
I = 255 - I; % Negative to display as original image
%% Definition of Structuring Element
SE = [1 1 1 ; 1 1 1 ; 1 1 1];
%% Erosion & Dilatation
D=AX_6_MyDilatation(I,SE);
E=AX_6_MyErode(I,SE);
%% Display
figure, imagesc(I),colormap('gray'), title('Original Image')
figure, imagesc(D),colormap('gray'), title('Dilated Image')
figure, imagesc(E),colormap('gray'), title('Erroded Image')
function J=AX_6_MyDilatation(I,SE)
% I: Greylevel image
% SE : Structuring Element (Matrix)
% SE : de taille IMPAIRE
[m,n] = size(I) ;
[k,l] = size(SE) ;
kk = (k-1)/2 ;
ll = (l-1)/2 ;
J=I;
for u = kk+1 : m-kk-1
for v = ll+1 : n-ll-1
valmin=I(u,v) ;
for i=-kk:kk
for j=-ll:ll
if SE(kk+i+1,ll+j+1)==1
if(I(u+i,v+j)<valmin)
valmin=I(u+i,v+j) ;
21

end
end
end
end
J(u,v)=valmin ;
end
end
function J=AX_6_MyErode(I,SE)
% I: Greylevel image
% SE : Structuring Element (Matrix)
% SE : de taille IMPAIRE
[m,n] = size(I) ;
[k,l] = size(SE) ;
kk = (k-1)/2 ;
ll = (l-1)/2 ;
J=I;
for u = kk+1 : m-kk-1
for v = ll+1 : n-ll-1
valmax=I(u,v) ;
for i=-kk:kk
for j=-ll:ll
if SE(kk+i+1,ll+j+1)==1
if(I(u+i,v+j)>valmax)
valmax=I(u+i,v+j) ;
end
end
end
end
J(u,v)=valmax;
end
end

Grey Scale Image Bluring
%% Grey scale Image Bluring
% We will blurr a greyscale image using a simple ones kernel an show FFT
clc;close all;clear all;
%% Parameters
I = imread('toulouse.bmp');
[x y] = size(I);
N=5;
K=ones(N)/(N*N);
%% Blurring
B = conv2(double(I),K,'full'); %set 'same' to keep same dimension def :full
%% FFT
22

I2=fft2(double(I));
I3=fftshift(abs(I2));
B2=fft2(double(B));
B3=fftshift(abs(B2));
%normalization
for i=1:x
for j=1:y
if I3(i,j) <= 1
I3(i,j)=1;
end
if B3(i,j) <= 1
B3(i,j)=1;
end
end
end
I3=log10(I3);
B3=log10(B3);
%% Display
figure,
subplot(2,2,1);imagesc(I);colormap('gray');title('Original image');
subplot(2,2,2);imagesc(B);title('Blurred Image');
subplot(2,2,3);imagesc(I3);colormap('gray');title('Original image FFT');
subplot(2,2,4);imagesc(B3);title('Blurred Image FFT');

Motion Blurring
%% Color Image Motion Bluring
% We will study the bluring of this color image
clc;close all;clear all;close all;
%% Parameters
I = imread('marcheur.jpg');
[x y z] = size(I);
%% FFT
I2=fft2(double(I));
I3=fftshift(abs(I2));
%conversion to log10 scale and normalization
for i=1:x
for j=1:y
for k=1:z
if I3(i,j,k) <= 1
I3(i,j,k)=1;
end
end
end
end
23

I3=log10(I3);
for l=1:3
I3(:,:,l) = I3(:,:,l)/max(max(I3(:,:,l)));
end
%% Display
figure
subplot(1,2,1);image(I);title('Image');
subplot(1,2,2);imagesc(I3);title('Image FFT');

Data Processing Three Color
%% Data Processing
% We want to isolate the three colors in differents displays
clear all; close all; clc;
%% Parameters & Importation
O = imread('stade_toulousain.jpg');
S = size(O);
I = double(O/255);
%% Taking Samples
Red = [1,0,0];
Black = [0,0,0];
White = [1,1,1];
Ir = zeros(S(1),S(2));
Ib = zeros(S(1),S(2));
Iw = zeros(S(1),S(2));
for i=1:S(1)
for j=1:S(2)
J = [I(i,j,1) I(i,j,2) I(i,j,3)];
dr = norm(J-Red);
db = norm(J-Black);
dw = norm(J-White);
[val,position] = min([dr,db,dw]);
if position == 1
Ir(i,j) = 1;
end
if position == 2
Ib(i,j) = 1;
end
if position == 3
Iw(i,j) = 1;
end
end
end
%% Display
figure, image(O), title('Original')
24

figure, imagesc(Ir), colormap('gray'), title('Red')
figure, imagesc(Ib), colormap('gray'), title('Black')
figure, imagesc(Iw), colormap('gray'), title('White')

Data Processing Spain Beach
%% Data Processing of beach
%The goal is to isolate the beach
clear all; close all; clc;
%% Parameters & Importation
O = imread('SpainBeach.jpg');
S = size(O);
I = double(O/255);
%% Taking Samples
% Beach samples
bs_1 = [243 217 161];
bs_2 = [118 89 81];
beach = [bs_1(1)+bs_2(1),...
bs_1(2)+bs_2(2),...
bs_1(3)+bs_2(3)]/(255*2);
Ib = zeros(S(1),S(2));
disp = zeros(S);
for i=1:S(1)
for j=1:S(2)
J = [I(i,j,1) I(i,j,2) I(i,j,3)];
white = mean(J); % supress white waves
db = norm(J-beach); % keep beach
if db <= 0.93 %0.9 suppress more unwanted pixels but beach part too
Ib(i,j) = 1;
disp(i,j,1) = O(i,j,1);
disp(i,j,2) = O(i,j,2);
disp(i,j,3) = O(i,j,3);
end
if white >= 0.995
disp(i,j,1) = 0;
disp(i,j,2) = 0;
disp(i,j,3) = 0;
end
end
end
disp = disp/255;
%% Display
figure, image(O), colormap('default'), title('Original')
figure, imagesc(Ib), colormap('gray'), title('Sampling still with waves')
figure, image(disp), colormap('default'), title('Beach without waves')
25

You might also like