You are on page 1of 24

Digital Image Processing

using MATLAB

Introduction
1
What is Digital Image processing

• Digital image processing refers to


processing digital images by means of
a digital computer .
• It encompasses a wide and varied field
of applications, which are computer
vision, image analysis.
• Three types of computerized processes
– Low, mid, and high level.
• It is used in exceptional social and
economic value.
2
Background on MATLAB and Image Processing toolbox

• MATLAB stands Matrix Laboratory.


• Typical uses include the following
 Math and computation
 Algorithm development
 Data acquisition
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics
 Application development, including building
graphical user interfaces .
• collection of MATLAB functions
3
The MATLAP Desktop

4
Digital Image Representation
• Digital image is a representation of 2D image
using binary value.
• Digitizing the coordinates values is called
sampling; Digitizing amplitude values is called
quantization.
• Coordinate conventions

5
Images as Matrices

6
Reading images
• The syntax of reading image in MATLAB is
imread(‘file name’)
• The function size gives the row & column dimensions of
image
size(filename)
• The whos function displays additional information about an
array
whos file name

7
Writing images
• The syntax of writing image
imwrite(f, ‘filename’)
• Example
imwrite(f, ‘garden’, ‘tiff’)
imwrite(f, ‘garden.tif’)
• The image file details of syntax
imfinfo filename

8
Classes in MATLAB
• Data types in MATLAB
– Double (64-bit double-precision floating point)
– Single (32-bit single-precision floating point)
– Int32 (32-bit signed integer)
– Int16 (16-bit signed integer)
– Int8 (8-bit signed integer)
– Uint32 (32-bit unsigned integer)
– Uint16 (16-bit unsigned integer)
– Uint8 (8-bit unsigned integer)
– char (2 bytes per element).
– Logical Values are 0 or 1 (1 byte per element).

9
Image types
• The toolbox supports four types of images:
o Intensity images : [0,1] or uint8, double etc.
o Binary images : {0,1}
o Indexed images : m-by-3 color map
o RGB images : m-by-n-by-3

10
Image Types – Intensity Image
• MATLAB stores an intensity image as a single matrix,
with each element of the matrix corresponding to one
image pixel.
• The matrix can be of class double, in which case it
contains values in the range [0,1], or of class uint8, in
which case the data range is [0,255] (0 – black, 255 –
white).

11
Image Types – Binary Images
• In a binary image, each pixel assumes one of only two
discrete values.
• Essentially, these two values correspond to on and off.
• A binary image is stored as a two-dimensional matrix of
0’s (off pixels) and 1’s (on pixels).
• Example

12
Image Types - Indexed Images
• The colormap is an m-by-3 matrix of class double. Each
row of the colormap matrix specifies the red, green, and
blue (RGB) values for a single color:
– color = [R G B]
Example

13
Image Types – RGB Images
• Like an indexed image, an RGB image represents each
pixel color as a set of three values, representing the red,
green, and blue intensities that make up the color.
• Unlike an indexed image, however, these intensity
values are stored directly in the image array, not
indirectly in a colormap
• Example

14
Converting between Classes
• gray2ind - intensity image to index image
• im2bw - image to binary
• im2double - image to double precision
• im2uint8 - image to 8-bit unsigned integers
• im2uint16 - image to 16-bit unsigned integers
• ind2gray - indexed image to intensity image
• mat2gray - matrix to intensity image
• rgb2gray - RGB image to grayscale
• rgb2ind - RGB image to indexed image
15
Array Indexing
• MATLAB supports a number of powerful indexing
schemes that simplify array manipulation and
improve the efficiency of programs
• Two type of indexing –vectors and matrices
• Indexing vectors
>> v=[1 2 3 4 5]
Indexing matrices
>> m=[1 2 3;4 5 6;7 8 9]

16
Some Important Standard Arrays
• Zeros(M, N) generates an M * N matrix of 0s of class double.
• Ones(M, N) generates an M * N matrix of 1s of class double.
• True(M, N) generates an M * N logical matrix of 1s.
• False(M, N) generates an M * N logical matrix of 0s.
• Magic(M) generates an M * M “magic square.” This is a square array in
which the sum along any row, column, or main diagonal, is the same. Magic
squares are useful arrays for testing purposes because they are easy to
generate and their numbers are integers.
• Eye(M) generates an M * M identity matrix.
• Rand(M, N) generates an M * N matrix whose entries are uniformly
distributed random numbers in the interval [0, 1].
• Randn(M, N) generates an M * N matrix whose numbers are normally
distributed (i.e., Gaussian) random numbers with mean 0 and variance 1.

17
Introduction to M-Function Programming

• The components of a function M-file are


The function definition line
function [outputs] = name(inputs)
The H1 line
Help text
The function body
Comments

18
0perators
MATLAB operators are grouped into three main
categories:
• Arithmetic operators that perform numeric
computations
• Relational operators that compare operands
quantitatively
• Logical operators that perform the functions AND,
OR, and NOT

19
Arithmetic operators
• Operator Name Comments and Examples
• + Array and matrix addition a + b, A + B, or a + A.
• − Array and matrix subtraction a − b, A − B, A − a, or a − A.
• .* Array multiplication v= A.*B, C(I, J) = A(I, J)*B(I, J).
• * Matrix multiplication A*B, standard matrix multiplication, or a*A, multiplication of
a scalar times all elements of A.
• ./ Array right division C = A./B, C(I, J) = A(I, J)/B(I, J).
• .\ Array left division C = A.\B, C(I, J) = B(I, J)/A(I, J).
• / Matrix right division A/B is the preferred way to compute A*inv(B).
• \ Matrix left division A\B is the preferred way to compute inv(A)*B.
• .^ Array power If C = A.^B, then C(I, J) = A(I, J)^B(I, J).
• ^ Matrix power See help for a discussion of this operator.
• .' Vector and matrix transpose A.', standard vector and matrix transpose.
• ' Vector and matrix complex conjugate transpose A', standard vector and matrix conjugate transpose.
When A is real A.' = A'.
• + Unary plus +A is the same as 0 + A.
• − Unary minus −A is the same as 0 − A or −1*A.
• : Colon

20
Logical Function

21
Logical Function(cont)

22
Flow Control

23
Interactive I/O
• It used for display information and instructions
to users and accept inputs from the keyboard.
• Display syntax is
disp(argument)
• Inputs syntax is
t=input(‘message’)

24

You might also like