gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

140
Two day Workshop on Matlab

description

Matlab

Transcript of gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Page 1: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Two day Workshop on Matlab

Page 2: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Introduction

Cleve molar in 1984, Mathworks inc Introduced as a simulation toolSupports Graphical ProgrammingCan be interfaced with other High

Level languages

Page 3: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Applications

• Aerospace• Biometrics• Medical• Finance• Control System• Signal,Image,Audio and Video• Neural networks,Fuzzy logic• Animation

Page 4: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

List of Companies

• ADOBE (Photoshop)• NASA• GE• L&T• ROBERT BOSCH• PEPSI , COCACOLA (Neuro Marketing)

Page 5: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

File Extensions.fig MATLAB Figure .m MATLAB function, script, or class .mat MATLAB binary file for storing variables.mex MATLAB executable (platform specific, e.g. ".mexmac" for the Mac

, ".mexglx" for Linux, etc.) .p

MATLAB content-obscured .m file (result of pcode() )

Page 6: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Difference between C and Matlab

• Matlab is Proprietary compiler,C has open source.• Inbuilt Functions in Matlab(Application Oriented).• User friendly syntax.• Fourth generation Programming Language tool.

Page 7: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Desktop Tools • Command Window

– type commands

• Workspace– view program variables– clear to clear – double click on a variable to see it in the Array Editor

• Command History– view past commands– save a whole session using diary

• Launch Pad– access tools, demos and documentation

Page 8: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Command window

Page 9: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Change the current working directory

Page 10: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Arithmetic operators

1) plus - Plus + 2) uplus - Unary plus + 3) minus - Minus - 4) uminus - Unary minus - 5) mtimes - Matrix multiply * 6) times - Array multiply .* 7) mpower - Matrix power ^ 8) power - Array power .^ 9) mldivide - Backslash or left matrix divide \ 10) mrdivide - Slash or right matrix divide / 11) ldivide - Left array divide .\ 12) rdivide - Right array divide ./

Page 11: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Relational operators1) eq - Equal == 2) ne - Not equal ~= 3) lt - Less than < 4) gt - Greater than > 5) le - Less than or equal <= 6) ge - Greater than or equal >=

Page 12: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Logical operators

1) Short-circuit logical AND && 2) Short-circuit logical OR || 3) and - Element-wise logical AND & 4) or - Element-wise logical OR | 5) not - Logical NOT ~ 6) xor - Logical EXCLUSIVE OR7) any - True if any element of vector is nonzero8) all - True if all elements of vector are nonzero

Page 13: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

BITWISE OPERATORS

1) bitand - Bit-wise AND.2) bitcmp - Complement bits.3) bitor - Bit-wise OR.4) bitmax - Maximum floating point

integer.5) bitxor - Bit-wise XOR.6) bitset - Set bit.7) bitget - Get bit.8) bitshift - Bit-wise shift.

Page 14: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Vectors a = [1 2 3 4 5 6 9 8 7] ;

t = 0:2:20t = 0 2 4 6 8 10 12 14 16 18 20

b = a + 2

b = 3 4 5 6 7 8 11 10 9

c = a + b c = 4 6 8 10 12 14 20 18 16

Page 15: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Matrices B = [1 2 3 4;5 6 7 8;9 10 11 12] ;

B = 1 2 3 4 5 6 7 8

9 10 11 12

C = B'

C = 1 5 9 2 6 103 7 11

4 8 12

Page 16: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Basic matrix operatorsX = inv(E) ;%INVERSE OF THE MATRIX[A,H] = eig(E) %eigen value &vectorp = poly(E) %polynomialc = abs(y) ;D=min(a);D=max(a);

• Convolutionx = [1 2]; y = [1 4 8]; z = conv(x,y) [xx, R] = deconv(z,y)

Page 17: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

PLOT

t=0:0.25:7; y = sin(t); plot(t,y) ; xlabel('x axis'); ylabel('y axis'); title('Heading'); grid on; gtext('text');

Page 18: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

IF LOOPa=6;

if a > 6 disp('a is greater'); elseif a==0 disp('a is zero'); else disp('a is smaller'); end

Page 19: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

FOR LOOPa=5;

for i=1:5 a=a+1 end

disp(a);

ANS a =10

Page 20: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

While Loop

a=5;

while a < 10a=a+1; end

disp(a);

Ans a =10

Page 21: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Function

function c=add(a,b);c=a+b;return

Maina=5;b=6;c=add(a,b);disp(c);d=mul(a,b);disp(d);

function c=mul(a,b);c=a*b;return

Page 22: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

SWITCH CASE method = 'Bilinear'; switch lower(METHOD) case {'linear','bilinear'} disp('Method is linear') case 'cubic' disp('Method is cubic') case 'nearest' disp('Method is nearest') otherwise disp('Unknown method.') end

Ans Method is linear

Page 23: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

SWITCH (NUMERICAL)a=input('enter---->');switch a case 1 fprintf('one'); case 2 fprintf('two'); case 3 fprintf('three'); case 4 fprintf('four'); otherwise fprintf('otherwise');end

Page 24: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

How to read an imagea =imread('cameraman.tif');imshow(a);pixval on;

a =imread('flowers.tif');imshow(a);pixval on;

Page 25: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

How to read an audio file

a =wavread('test.wav');wavplay(a,44100);Plot(a);

Page 26: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

How to read an video file

a=aviread('movie.avi');movie(a);

Page 27: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Add two images

I = imread('rice.tif');J = imread('cameraman.tif');K = imadd(I,J,'uint16');imshow(K,[])

I = imread('rice.tif'); J = imadd(I,50); subplot(1,2,1), imshow(I) subplot(1,2,2), imshow(J)

Page 28: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Subtract two images

I = imread('rice.tif'); Iq = imsubtract(I,50); subplot(1,2,1), imshow(I)subplot(1,2,2), imshow(Iq)

Page 29: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Convert image to gray and binaryclc;clear;close alla= imread('flowers.tif');subplot(2,2,1);imshow(a);subplot(2,2,2);b=imresize(a,[256 256]);imshow(b);subplot(2,2,3);c=rgb2gray(b);imshow(c);subplot(2,2,4);d=im2bw(c);imshow(d);

Page 30: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RGB componenta=imread('flowers.tif');subplot(2,2,1);imshow(a);R=a;G=a;B=a;R(:,:,2:3)=0;subplot(2,2,2);imshow(R);G(:,:,1)=0;G(:,:,3)=0;subplot(2,2,3);imshow(G);B(:,:,1)=0;B(:,:,2)=0;subplot(2,2,4);imshow(B);

Page 31: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Convert Image into One dimensional

a = imread('cameraman.tif');

[r c]=size(a);

Len=r*c;

b=reshape(a,[1 Len]);

Page 32: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CONVER MOVIE TO FRAMES

file=aviinfo('movie1.avi'); % to get inforamtaion abt video filefrm_cnt=file.NumFrames % No.of frames in the video file str2='.bmp' h = waitbar(0,'Please wait...');for i=1:frm_cnt frm(i)=aviread(filename,i); % read the Video file frm_name=frame2im(frm(i)); % Convert Frame to image file frm_name=rgb2gray(frm_name);%convert gray filename1=strcat(strcat(num2str(i)),str2); imwrite(frm_name,filename1); % Write image file waitbar(i/frm_cnt,h)endclose(h)

Page 33: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CONVERT FRAMES TO MOVIESfrm_cnt=5;number_of_frames=frm_cnt;filetype='.bmp';display_time_of_frame=1;mov = avifile('MOVIE.avi');count=0;for i=1:number_of_frames name1=strcat(num2str(i),filetype); a=imread(name1); while count<display_time_of_frame count=count+1; imshow(a); F=getframe(gca); mov=addframe(mov,F); end count=0;endmov=close(mov);

Page 34: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

How to read a text file

fid = fopen('message.txt','r');ice1= fread(fid);s = char(ice1');fclose(fid);disp(s);

Ans hello

Page 35: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

How to write a text file

txt=[65 67 68 69];fid = fopen('output.txt','wb'); fwrite(fid,char(txt),'char');fclose(fid);

ANS =ACDE

Page 36: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Store an Image,Audio

a =imread('cameraman.tif');imwrite(a,'new.bmp');

a=wavread('test.wav');wavwrite(d,44100,16,'nTEST.WAV');

Page 37: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

SAVE AND LOAD THE VARIABLE

A=5;save A A;

load A

B=1;C=A+B;disp(C);

Page 38: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Wavelet transform

a =imread('cameraman.tif');

[LL LH HL HH]=dwt2(a,'haar');

Dec=[... LL,LH HL,HH ... ];

imshow(Dec,[]);

Page 39: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

DCT transform

a=imread('cameraman.tif');subplot(1,3,1);imshow(a,[]);b=dct2(a);subplot(1,3,2);imshow(b,[]);title('DCT');c=idct2(b);subplot(1,3,3);imshow(c,[]);title('IDCT');

Page 40: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

NOISE AND FILTER

I = imread('eight.tif'); J = imnoise(I,'salt & pepper',0.02); K = medfilt2(J); subplot(1,2,1);imshow(J)subplot(1,2,2);imshow(K)

Page 41: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

GUI

Page 42: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

DIALOG BOX

warndlg('hello'); helpdlg('hello'); errordlg('hello');

msgbox('hello');

Page 43: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

ButtonName=questdlg('What is your wish?', ... 'Genie Question', ... 'Food','Clothing','Money','Money'); switch ButtonName, case 'Food', disp('Food is delivered'); case 'Clothing', disp('The Emperor''s new clothes have arrived.') case 'Money', disp('A ton of money falls out the sky.'); end % switch

Page 44: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

USER INTERFACE GET FILE

[filename, pathname] = uigetfile('*.m', 'Pick an M-file'); if isequal(filename,0) | isequal(pathname,0) disp('User pressed cancel') else disp(['User selected ', fullfile(pathname, filename)]) end

Page 45: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

USER INTERFACE PUT FILE

[filename, pathname] = uiputfile('*.m', 'Pick an M-file'); if isequal(filename,0) | isequal(pathname,0) disp('User pressed cancel') else disp(['User selected ', fullfile(pathname, filename)]) end

Page 46: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

GUI

Page 47: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

GUI…

Page 48: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

MENU BAR

Page 49: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

PUSH BUTTON

Page 50: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

TOGGLE BUTTON

Page 51: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RADIO BUTTON

Page 52: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHECKBOX

Page 53: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

EDIT TEXT

Page 54: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

STATIC TEXT

Page 55: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

SLIDER

Page 56: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

FRAME

Page 57: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

LISTBOX

Page 58: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

POPUP MENU

Page 59: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

AXES

Page 60: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

ALIGN OBJECTS

Page 61: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

MENU EDITOR

Page 62: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

M FILE EDITOR

Page 63: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

PROPERTY INSPECTOR

Page 64: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Page 65: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN

Page 66: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

EMPTY GUI

Page 67: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

GENERATED M FILE

Page 68: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

PUSH BUTTON

Page 69: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK PUSH BUTTON & GO FOR PROPERTY INSPECTOR

Page 70: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHANGE THE STRING AND TAG VALUE

Page 71: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHANGE THE STRING AND TAG VALUE

Page 72: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK PUSH BUTTON & GO FOR M FILE EDITOR

Page 73: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

GO FOR CALLBACK

Page 74: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

a =imread('cameraman.tif');

imshow(a);

Page 75: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN THE PROGRAM OR PRESS F5

Page 76: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHOOSE AXES

Page 77: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHOOSE AXES

Page 78: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK AXES & GO FOR PROPERTY INSPECTOR

Page 79: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHANGE THE STRING AND TAG VALUE

Page 80: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

a =imread('cameraman.tif');

axes(handles.one);

imshow(a);

Page 81: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN THE PROGRAM

Page 82: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CODE

a =imread('cameraman.tif');

axes(handles.one);

imshow(a);

Page 83: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

TOGGLE BUTTON

Page 84: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK TOGGLE & GO FOR PROPERTY INSPECTOR

Page 85: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHANGE THE STRING AND TAG VALUE

Page 86: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK TOGGLE & GO FOR M FILE EDITOR

Page 87: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

a=get(hObject,'Value');

if a ==1 a =imread('cameraman.tif');

axes(handles.one);

imshow(a); else a =imread('greens.jpg');

axes(handles.one);

imshow(a); end

Page 88: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN THE PROGRAM

Page 89: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK RADIO BUTTON & GO FOR PROPERTY INSPECTOR

Page 90: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHANGE THE STRING AND TAG VALUE

Page 91: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK CHECK BOX & GO FOR MFILE EDITOR

Page 92: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

Page 93: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN THE PROGRAM

Page 94: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK CHECK BOX & GO FOR PROPERTY INSPECTOR

Page 95: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHANGE THE STRING AND TAG VALUE

Page 96: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK CHECK BOX & GO FOR M FILE EDITOR

Page 97: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

Page 98: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN THE PROGRAM

Page 99: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK FRAME & SEND TO BACK

Page 100: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN THE PROGRAM

Page 101: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK LIST BOX & GO FOR PROPERTY INSPECTOR

Page 102: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

EDIT THE STRING OPTIONS

Page 103: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK LIST BOX & GO FOR M FILE EDITOR

Page 104: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

contents = get(hObject,'Value')

switch contents case 1 a =imread('cameraman.tif'); axes(handles.one); imshow(a); case 2 a =imread('flowers.tif'); axes(handles.one); imshow(a); case 3 a =imread('rice.tif'); axes(handles.one); imshow(a); otherwise a =imread('mri.tif'); axes(handles.one); imshow(a); end

Page 105: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHOOSE POPUPMENU

Page 106: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK POPUP MENU & GO FOR PROPERTY INSPECTOR

Page 107: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

EDIT THE STRING OPTIONS

Page 108: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODEcontents = get(hObject,'Value')

switch contents case 1 a =imread('cameraman.tif'); axes(handles.one); imshow(a); case 2 a =imread('flowers.tif'); axes(handles.one); imshow(a); case 3 a =imread('rice.tif'); axes(handles.one); imshow(a); otherwise a =imread('mri.tif'); axes(handles.one); imshow(a); end

Page 109: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK EDIT TEXT & GO FOR PROPERTY INSPECTOR

Page 110: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

EDIT STRING AND TAG

Page 111: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK EDIT TEXT & GO FOR M FILE EDITOR

Page 112: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK AXES & GO FOR PROPERTY INSPECTOR

Page 113: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Page 114: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

Page 115: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

a=get(hObject,'String') ;b=char(a);c=imread(b);axes(handles.one);imshow(c);

Page 116: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK STATIC TEXT & GO FOR PROPERTY INSPECTOR

Page 117: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHANGE THE STRING AND TAG VALUE

Page 118: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

a=get(hObject,'String') ;set(handles.t1,'String',a);b=char(a);c=imread(b);axes(handles.one);imshow(c);

Page 119: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

SLIDER

Page 120: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK SLIDER & GO FOR PROPERTY INSPECTOR

Page 121: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

DROP TWO AXES

Page 122: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

DROP PUSH BUTTON

Page 123: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

CHANGE THE STRING AND TAG VALUE

Page 124: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

GO FOR CALLBACK

Page 125: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

[filename, pathname] = uigetfile('*.bmp', 'Pick an Image');

if isequal(filename,0) | isequal(pathname,0) warndlg('User pressed cancel') else a=imread(filename); axes(handles.axes1); imshow(a); handles.filename=filename; guidata(hObject, handles); end

Page 126: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RIGHT CLICK SLIDER & GO FOR M FILE EDITOR

Page 127: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Page 128: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

WRITE THE CODE BELOW THE CALLBACK

Page 129: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN THE PROGRAM

a=get(hObject,'Value');filename =handles.filename;I = imread(filename);J = imadd(I,50);axes(handles.axes2);imshow(J)

Page 130: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

MENU EDITOR

Page 131: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Page 132: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

EDIT STRING AND TAG

Page 133: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

RUN

Page 134: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Counting the Number of Objects in an Image

clc;clear;close all;InputImage=imread('eight.tif');subplot(2,2,1);imshow(InputImage);title('InputImage');BinaryImage=im2bw(InputImage);subplot(2,2,2);imshow(BinaryImage);ComplementImage=imcomplement(BinaryImage);subplot(2,2,3);imshow(ComplementImage);HolesClearedImage = imfill(ComplementImage,'holes');subplot(2,2,4);imshow(HolesClearedImage);title('HolesClearedImage');[L,Num] = bwlabel(HolesClearedImage) for i=1:Num figure; imshow(L==i); pause(1)end

Page 135: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Thresholding Based Segmentation-Con 1

• clc;• clear;• close all;• InputImage=imread('34.bmp');• figure;• imshow(InputImage);• ColourSpaceConversion=rgb2hsv(InputImage);• imshow(ColourSpaceConversion);• %GrayScaleImage=rgb2gray(ColourSpaceConversion);• GrayScaleImage=ColourSpaceConversion(:,:,1);• [rows columns planes]=size(GrayScaleImage);• BinaryMask= GrayScaleImage > 0.5;• figure;• imshow(BinaryMask);• Impixelinfo• h = waitbar(0,'Please wait...');• SegmentedImage=[];

Page 136: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Cont 2for i=1:rows for j=1:columns if BinaryMask(i,j) == 1 SegmentedImage(i,j,1)=InputImage(i,j,1); SegmentedImage(i,j,2)=InputImage(i,j,2); SegmentedImage(i,j,3)=InputImage(i,j,3); else SegmentedImage(i,j,1)=0; SegmentedImage(i,j,2)=0; SegmentedImage(i,j,3)=0; end end waitbar(i/rows,h)end SegmentedImage=uint8(SegmentedImage);figure;imshow(SegmentedImage);impixelinfo;

Page 137: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Image Fusionclc;clear;close all;M1=imread('mri.jpg');M2=imread('ct.jpg');subplot(2,2,1);imshow(M1);title('MRI');subplot(2,2,2);imshow(M2);title('CT');[R C P]=size(M1);for i=1:R for j=1:C if M1(i,j)>M2(i,j) FusedImage(i,j)=M1(i,j); else FusedImage(i,j)=M2(i,j); end endend

Page 138: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Image fusion-Cont 2subplot(2,2,3);imshow(FusedImage);title('Max');for i=1:R for j=1:C if M1(i,j)>M2(i,j) FusedImage(i,j)=M2(i,j); else FusedImage(i,j)=M1(i,j); end endendsubplot(2,2,4);imshow(FusedImage);title('Min');

Page 139: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

Page 140: gettingstartedwithmatlabimageprocessing-120101100110-phpapp02

Technology beyond the Dreams™ Copyright © 2006 Pantech Solutions Pvt Ltd.

For more details

– www.pantechsolutions.net– http://www.slideshare.net/pantechsolutions– http://www.scribd.com/pantechsolutions– http://www.youtube.com/pantechsolutions