gulsah tumuklu ozyer matlab image processing toolbox

24
Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Upload: timothy-price

Post on 01-Jan-2016

264 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Gulsah Tumuklu Ozyer

MATLABIMAGE PROCESSING TOOLBOX

Page 2: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

IntroductionMatLab : Matrix LaboratoryA high-level language for matrix calculations,

numerical analysis, & scientific computingProgramming

Can type on command line, or use a program file (“m”-file)

Semicolon at end of line is optional (suppresses printing)

Control flow (if, for, while, switch,etc) similar to CDifferences from C: no variable declarations, no

pointers

Page 3: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

MATLAB’s Workspace

who,whos - current variables in workspacesave - save workspace variables to *.mat fileload - load variables from *.mat fileclear all - clear workspace variables

Page 4: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Matlab BasicsEverything is a matrix

a variable is a 1x1 matrix

Initializing a matrix:Example: my_matrix = [1 2 3; 4 5 6; 7 8 9];

Accessing a matrix (row, column):my_matrix(1,2) has the value 2

Colon operator generates a rangeExample: 1:10 = [1 2 3 4 5 6 7 8 9 10]mytest(1, 2:4) is equivalent to mytest(1,[2 3 4])mytest(3, :) refers to all elements of row 3

my_matrix =

1 2 34 5 67 8 9

Page 5: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Basic Operations on Matrices

All the operators in MATLAB defined on matrices : +, -, *, /, ^, sqrt, sin, cos etc.

Element wise operators defined with preceding dot : .*, ./, .^ .size(A) - size vectorsum(A) - columns sums vectorsum(sum(A)) - all the elements sum

Page 6: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Logical Conditions

== , < , > , (not equal)~= ,(not)~

find(‘condition’) - Returns indexes of A’s elements that satisfies the condition.

Page 7: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Logical Conditions(cont.)Example:>> A = [1 2; 3 4], I = find(A<4)

A =

1 2 3 4

I =

1 2 3

Page 8: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Flow Control

MATLAB has five flow control constructs: if statementsswitch statementsfor loops while loops break statements

Page 9: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Scripts and Functions

There are two kinds of M-files: Scripts, which do not accept input

arguments or return output arguments. They operate on data in the workspace.

Functions, which can accept input arguments and return output arguments. Internal variables are local to the function.

Page 10: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Visualization and Graphicsplot(x,y), plot(x,sin(x)) - plot 1-D functionfigure , figure(k) - open a new figurehold on, hold off - refreshingmesh(x_ax,y_ax,z_mat) - view surfacecontour(z_mat) - view z as top. mapsubplot(3,1,2) - locate several plots in

figureaxis([xmin xmax ymin ymax]) - change

axes title(‘figure title’) - add title to figure

Page 11: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

The Image Processing Toolbox

The Image Processing Toolbox is a collection of functions that extend the capability of the MATLAB ® numeric computing environment. The toolbox supports a wide range of image processing operations, including:Geometric operationsNeighborhood and block operationsLinear filtering and filter designTransformsImage analysis and enhancementBinary image operations

Page 12: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

MATLAB Image Types

Indexed images : m-by-3 color mapIntensity images : [0,1] or uint8Binary images : {0,1}RGB images : m-by-n-by-3

Page 13: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Read and Write ImagesI = imread(‘colors.jpg'); imshow(I);Indexed Image:

[x,map] = imread(‘color.png'); imwrite(I, ‘newim.jpg’)

Page 14: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Image Displayimage - create and display image objectimagesc - scale and display as imageimshow - display imagecolorbar - display colorbargetimage- get image data from axestruesize - adjust display size of imagezoom - zoom in and zoom out of 2D plot

Page 15: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Image Conversion

gray2ind - intensity image to index imageim2bw - image to binaryim2double - image to double precisionim2uint8 - image to 8-bit unsigned integersim2uint16 - image to 16-bit unsigned integersind2gray - indexed image to intensity imagemat2gray - matrix to intensity imagergb2gray - RGB image to grayscalergb2ind - RGB image to indexed image

Page 16: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Geometric OperationsImage resizing: imresize(I,[x y],’method’).

Method is bilinear, bicubic or nearest neighbours.

Image rotation: imrotate(I,angle,’method’) method is same as before. Zero padding in the rotated image.

Image cropping: J=imcrop;

Page 17: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

17

Neighbourhood ProcessingTo speed up neighbourhood processing

transform every neighbourhood to column vector and perform vector operations.

The borders are usually padded with zeros for the computations of the edges neighborhoods.

Linear filtering can be done with convolution - conv2(Img, h) or correlation - filter2(Img, h). Nonlinear filtering: nlfilter(I,[sx sy],’func’) where

func is a function that recieves the windows and returns scalars.

Page 18: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

18

TransformsFourier and inverse Fourier transform:

F=fftshift(fft2(f)); F is a complex matrixFreal=real(F);Fimag=imag(F);Fabs=abs(F);Fphs=angle(F);imshow(Freal)f=ifft2(F);

DCT and compression I=imread(‘cameraman.tif’);I=im2double(I);T=dctmtx(8);B=blkproc(I,[8 8], ‘P1*x*P2’,T,T’);mask=[1 1 1 0 0 …];B2=blkproc(B,[8 8],’P1*x’,mask);I2=blkproc(B2,[8 8],’P1*x*P2,T’,T);It is also possible to use dct2 and idct2.

Page 19: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

19

Analyzing and Enhancing Images

pixval returns the value of a pointed pixel and the distance between two pointed pixels.

impixel returns the data value for a selected set of pixels. The set can be pointed by the mouse or by coordinates.

imcontour plots the contours of the image.

imhist(I,n) plots the histogram of I with n bins.

Page 20: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

20

Edge detection:edge(I,’sobel’);edge(I,’canny’);Or by fspecial(‘sobel’) and conv2. Image Enhancement:

Histogram stretching:imadjust(I,[low high],[bottom top]);

Gamma correction:imadjust(I,[],[],gamma_coef);

Histogram Equalizationhisteq(I)

Page 21: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

21

Noise removalTo add noise to an image:

imnoise(I,’type’,coef); type can be ‘salt n pepper’, ‘speckle’, ‘gaussian’ for S&P, multiplicative and additive noise.

Averaging or gaussian filtering:F=filter2(fspecial(‘average’,3),J);

Median filtering:F=medfilt(J,[3 3]);

Page 22: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

22

Morphological Operations

Dilation : imdilate()Erosion: imerode()Closing: imclose()Opening: imopen()

Page 23: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

23

ColorThe available colorspaces:RGB, NTSC (US televisions), YCbCr (Digital video),

HSV.Transformations between the spaces:rgb2ntsc, hsv2rgb, …

Page 24: Gulsah Tumuklu Ozyer MATLAB IMAGE PROCESSING TOOLBOX

Questions?