0% found this document useful (0 votes)
15 views

MatlabIntroduction_06

The document provides an introduction to MATLAB, focusing on its capabilities for data analysis, matrix operations, and image processing. It covers the MATLAB environment, variable types, matrix processes, and image types, including grayscale, RGB, and indexed images. Additionally, it discusses image I/O, type conversions, displaying images, and basic image arithmetic and transformations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

MatlabIntroduction_06

The document provides an introduction to MATLAB, focusing on its capabilities for data analysis, matrix operations, and image processing. It covers the MATLAB environment, variable types, matrix processes, and image types, including grayscale, RGB, and indexed images. Additionally, it discusses image I/O, type conversions, displaying images, and basic image arithmetic and transformations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Matlab: An Introduction

Digital Image
Processing I – 2006

Esin Guldogan
Matlab Basics

z MATLAB is a data analysis and visualization


tool that has been design with powerful
support for matrices and matrix operations.
z Interesting and very complete tutorials in:
http://www.mathworks.com/academia/student_center
/tutorials/launchpad.html
z Quick help can be obtained in MATLAB:
help, lookfor, helpwin, helpdesk.
ƒ A good feel about what Matlab is capable of can be
obtained from: demos.
2 Digital Image Processing I - 2006
Matlab Environment

Workspace Variables
(memory)

Commands are
entered here

Command History

3 Digital Image Processing I - 2006


Matlab Workspace

z Matlab variable types: int8, uint8, int16, uint16,


double.
– All numerical operations need to be performed on
double precision, takes 8 bytes per value.
– Other types are efficient for storage (<= 2 bytes)
Who, whos – current variables in workspace
Save, load – save or load variables to *.mat file
Clear all – clear all variables

4 Digital Image Processing I - 2006


Matrix Processes in Matlab

z How to build a matrix?


>>A=[1 2 3; 4 5 6; 7 8 9]; 3x3 matrix
z Special matrices:
zeros(r,c), ones(r,c), eye(r,c),
rand(r,c) …
z Access matrix elements:
A(2,3) = 6
using one number to index: A(8) = 6
matrix is written out as a single column.
A(:,2) – obtains second column of the matrix
5 Digital Image Processing I - 2006
Matrix Processes in Matlab (2)

z Basic Operations defined on matrices:


– +,-,*,/,^,’,sqrt,sin,cos, etc.
– Element-wise : .*, ./, .^ etc.
z size(A) – size vector
z sum(A) – columns sum vector
z sum(sum(A)) – sum of all elements
z Type help elmat for more instructions

6 Digital Image Processing I - 2006


Image Processing Toolbox

z Matlab contains many collections of functions


grouped in toolboxes.
z Image Processing Toolbox.
>>help images
– http://www.mathworks.com/access/helpdesk/help/
toolbox/images/
z Images are considered as matrices whose
elements are the pixel values of the image

7 Digital Image Processing I - 2006


Image Types

z Grayscale Image
(row x col)
z Binary Image
(row x col)
z Intensity Image

8 Digital Image Processing I - 2006


RGB Images

z RGB Image
(row X col X 3)

9 Digital Image Processing I - 2006


Indexed Images

z Indexed Image
(2 matrices:
colormap and
index)
z The numbers in
the first matrix is
an instruction of
what number to
use in the color
map

10 Digital Image Processing I - 2006


Image I/O

z Reading an Image and storing it in matrix I:


I = imread(‘pout.tif’);
[I,map] = imread(‘pout.tif’);
For indexed images
z Deals with many formats
– … more can be
JPEG, TIFF, GIF, BMP, PNG, PCX,
added from Mathworks Central File Exchange
z http://www.mathworks.com/matlabcentral/fileexchange

11 Digital Image Processing I - 2006


Image Type Conversion

z When you store an image, you should store it as a


uint8 image since this requires far less memory than
double.
z When you are processing an image you should
convert it into a double. Converting back and forth
between these classes is easy.
z I=im2double(I)
– converts an image named I from uint8 to double.
z I=im2uint8(I)
– converts an image named I from double to uint8.

12 Digital Image Processing I - 2006


Image Type Conversions
Operation Matlab Command
Convert between intensity/indexed/RGB dither()
format to binary format.
Convert between intensity format to gray2ind()
indexed format.
Convert between indexed format to ind2gray()
intensity format.
Convert between indexed format to RGB ind2rgb()
format.
Convert a regular matrix to intensity mat2gray()
format by scaling.
Convert between RGB format to intensity rgb2gray()
format.
Convert between RGB format to indexed rgb2ind()
13 format. Digital Image Processing I - 2006
Display an Image

z Pixel values are accessed as matrix


elements.
– 2D Image with intensity values: I(row,col)
– 2D RGB images I(row,col,color)
z Color : Red = 1; Green = 2 ; Blue = 3
z Displaying images
- >>figure, imshow(I)
z Displaying pixel position and intensity
information
- pixval on
14 Digital Image Processing I - 2006
Write Image

z After processing, an image matrix can be


written to an output image file with the
imwrite function
imwrite(I,map,’filename’,’fmt’)
z Validate the extension
z Without the map argument, image data is
assumed to be grayscale or RGB.

15 Digital Image Processing I - 2006


Image Arithmetic

z Adding
– ‘imadd’: Brighten an image
z Subtracting
– ‘imsubtract’
z Multiplying
– ‘immultiply’:
z Multiply two images
z multiply image by constant: brightens > 1, darkens < 1
z Dividing
– ‘imdivide’
16 Digital Image Processing I - 2006
Spatial Transformations

z Resizing
– ‘imresize’: changes the size of the image
z Rotation
– ‘imrotate’: rotates the image by given angle
z Cropping
– ‘imcrop’: Extract a rectangular part of the image

17 Digital Image Processing I - 2006

You might also like