# Image Processing Tutorial

Τεχνίτη Νοημοσύνη και Ρομποτική

5 Νοε 2013 (πριν από 4 χρόνια και 6 μήνες)

112 εμφανίσεις

Image Processing Tutorial

Tutorial 1: Introduction to Image Processing

Introduction

Image processing is the application of computer processing techniques on the images or stream
of images (i.e. video) made available to it through relevant Input mechanisms
. After processing
the Image, various kinds of outputs can be generated which range widely depending upon the
use which the user wants. Even though, there are various applications of Image Processing and
equally wide ranged outputs can be utilized, but the

basic principle remains the same in most of
the cases, and this fundamental similarity allows us to cover the basics in these tutorials which
will ultimately help in developing complex programs as well.

Basic Image Parameters

Image:

An Image can be thou
ght of a two

dimensional
light intensity function f(x,y) , where x
and y represent the Cartesian coordinates and the value of the function f at any point (x,y)
depends on the brightness and gray level (in black and white image) or RGB value(in colored
imag
e) at that point. In common scenarios now a days we encounter digital images and videos
in which everything is essentially discrete, so this means that the function f(x,y) has been made
discrete both in terms of the coordinates and the value of f at any p
oint. Keeping this in mind,
an image can essentially be treated as 2
-
Dimensional array of Pixels or the picture elements
which have been arranged in rows and columns, and their combination is what we see on the
screen as an image.

Pixel:
A pixel, short for
m of Picture Element, is the smallest Independent Unit of an Image. Any
image is defined by the placement of pixels in it in any particular fashion. Any Image pixel has
two important characters, and these are position of the pixel and the value of the pixe
l. Now, if
the pixel belongs to that of a black and white image, then its value will be either 0 or 255,
where 0 means black and 255 means white. If the image is Grayscale Image then the value of
pixel can range from 0 to 255
, with brightness level increas
ing from 0 to 255. For a colored
image pixel, the pixel value is somewhat treated differently which shall be discussed shortly.

Image Resolution
:
Image Resolution is a very common term.
The resolution refers to the number
of pixels

comprising the image. For example, if an image has a resolution [n * m], then that means there
are n pixels in the horizontal direction and m in the vertical direction and the size of the image is n * m
pixels or (n * m) * 10^
-
6 MP [Mega Pixels]. Now, ea
ch Pixel corresponds to piece of information, so
more is the number of pixels, more will be the information stored in the image and more is going to be
its clarity when scaled to the same width and height. This shall become clearer in the below example:

Channels:
A typical pixel does not contain only single value, i.e. value of a pixel at given
coordinates might not be a single number, but a collection of numbers as well. Thus, the
number of values a pixel has for a given (x,y) is called the chan
nel of the pixel.

Single Channel:

If each pixel of image can store only one value, it is called a Single
Channel pixel. Usually, this value in digital systems ranges from 0 to 255, with brightness
increasing from 0 to 255.

Here, the value of the pixel is
also called its intensity. Images made up
of such pixels are commonly called Black and White images, but more appropriate term to
describe such images would be Gray Scale Images.

1*1

4*4

8*8

25*25

50*50

75*75

100*100

0 45 90 135 180 225 255

Now consider a situation, where the pixel can store only one value but
that value is restricted
to be 0 or 255, in that case there are only two types of pixels in the image (black and white) and
in such cases the image is
Black and White
, also called
Binary Image
.

Multi
-
Channel Image:
Consider the case when each Pix
el can store more than one
values. Hence each pixel can store more information. Going by the typical case of three
channels per pixel, in which each pixel stores three numbers. These three
-
channel Pixels are
commonly used in modern day digital Images. The
two
important

ty
pes of three channel pixels,
BGR (Blue, Green, and Red
) and HSV (Hue
-
Saturation Value
), but more commonly used is BGR
.

BGR:
It is the more commonly coloring system in which each pixel of the Image has
three channels, and the three channels store intensity values corresponding to Blue, Green and
Red colo
rs.

Image Processing

It has been explained above that how an Image is represented digitally as an assortment of
pixels, like an Array. Hence, Image Processing includes:

1.

Acquiring Input associated with a digital Image
.

2.

Changing the Im
age to suit our needs.

3.

Acquiring information from the Image which is relevant to us.

4.

Producing a desired output.

B
lack and White Chess
Board

Blue Channel Only

Green Channel Only

Red Channel Only

Complete Image

This all can be d
one through computer
programming in various languages, and with the help of
certain defined libraries o
f code.

For these tutorials, we will be using
C+
+
as

our coding
language,
and image processing library
OPEN CV.

Alternatively, software
MATLAB

can also be
used.

Tutorials for the same will be uploaded soon).We will write programs that t
ake images as
input and manipulate them to meet the desired ends, and in the process learn about certain
basic techniques associated with digital image processing
.

Usage
of

OpenCV

F
or OpenCV to be used, it must first be associated with our IDE (Integrated D
evelopment
Environment) which we shall utilize for writing our image processing programs, which in this
case will be
Microsoft’s Visual Studio
, which is a very powerful and versatile tool for
programming in multiple language
s. The steps outlined here are i
dentical in the
free Visual C++
Express Edition
.

The steps to integrate OpenCV 2.4.0 with Visual Studio 2010/2012 are:
-

1.

Install Microsoft Visual Studio

2.

http://sourceforge.net/projects/opencvlibrary/files/opencv
-
win
/2.4.0/ 3.
Extract the file to C:
\

such that all OpenCV files are now in C:
\
opencv

4.

Open a new project (Win32 Console Application) in Visual Studio and give it a name.

5.

Go to Project
-
> Properties (the last option)

6.

Choose “All Configurations” in the
drop
-

7.

On the left, under Configuration Properties, click Debugging
-
> Environment and copy
paste:

PATH=C:
\
opencv
\
build
\
x86
\
vc10
\
bin;C:
\
opencv
\
build
\
common
\
tbb
\
ia32
\
vc10

8.

Click on VC++ Directories
-
> Include directories and add the entries:

C:
\
o
pencv
\
build
\
common
\
tbb
\
ia32
\
vc10;C:
\
opencv
\
buil
d
\
include;C:
\
opencv
\
build
\
inclu
de
\
ope
ncv;C:
\
opencv
\
build
\
include
\
opencv2

9.

Click VC++ Directories
-
> Library directories and add the entries:

C:
\
opencv
\
build
\
x86
\
vc10
\
lib

9.

-
> Input
-
Dependencies and add the following: (don’t replace)

opencv_calib3d240.lib
;opencv
_contrib240.lib
;opencv
_core240.lib;opencv_features2d24

0.lib;opencv_flann240.lib;

opencv_gpu240.lib;opencv_haartraining_engine.lib;opencv_nonfree240.lib;opencv_high
gui240.li
b;opencv_imgproc240.lib;

opencv_legacy240.lib;opencv_ml240.lib;opencv_objdetect240.lib;opencv_ts240.lib;ope
ncv_video240.lib;

(Note that you'll need to rename the OpenCV files of format opencv_file240.lib etc to
opencv_file242.lib for OpenCV 2.4.2 and so

on.)

10.

Test your OpenCV installation with the following code. Include the given header files for

#include "stdafx.h"

#include <stdio.h>

#include <highgui.h>

#include <cv.h>

#include <cxcore.h>

int

main() {

printf(
"
\
nOpenCV is correctly installed! Press any key to
exit!
\
n"
);

cvWaitKey(
0
);

return
0
;

}