function DIPtutor() % a very simple script illustrating the basic image processing commands % it uses 'lena.bmp' and 'lenasave.jpg' image examples % used in EE E4830 and EE E6882 by Prof. Chang a = figure; b = figure; c = figure; figure(a), xptext( 'DIP Tutorial on Matlab Image Processing Toolbox','', ' 1. Image I/O, Display, Image Matrix',' 2. Format Conversion',' 3. Basic Image Operation'); pause; % Image I/O display figure(a), xptext('','','',' I. Image I/O, Display, Image storage'); pause; figure(a), xptext( 'Image Read and display','','>> img = imread(''lena.bmp'',''BMP'');','>> imshow(img);'); img = imread('lena.bmp','BMP'); figure(b), imshow(img); pause; figure(a), xptext('Image Storage in Matrix ','', '>> img2 = zeros(100,100);','>> img2(1:20,1:10) = 1;','>> img2(90:100,1:10) = 0.75;','>> img2(1:10,90:100) = 0.5;','>> img2(90:100,90:100) = 0.25;','>> imshow(img2);'); % Image storage in Matrix img2 = zeros(100,100); img2(1:20,1:10) = 1; img2(90:100,1:10) = 0.75; img2(1:10,90:100) = 0.5; img2(90:100,90:100) = 0.25; figure(b), imshow(img2); pause; % storage figure(a), xptext('>> img2(1,1)','ans =',' 1'); img2(1,1) pause; figure(a), xptext('>> img2(1,100)','ans =',' 0.5'); img2(1,100) pause; figure(a), xptext('>> img2(100,1)','ans =',' 0.75'); img2(100,1) pause; figure(a), xptext('>> img2(100,100)','ans =',' 0.25'); img2(100,100) pause; figure(a), xptext( 'Image write','', '>> imwrite(img,''lenasave.jpg'',''JPEG'',''quality'',5);','>> imgjpg = imread(''lenasave.jpg'',''JPEG'');','>> imshow(imgjpg);'); imwrite(img,'lenasave.jpg','JPEG','quality',5); imgjpg = imread('lenasave.jpg','JPEG'); figure(b), imshow(imgjpg); pause; figure(a), xptext( 'Image write','', '>> imwrite(img,''lenasave.jpg'',''JPEG'',''quality'',20);','>> imgjpg = imread(''lenasave.jpg'',''JPEG'');','>> imshow(imgjpg);'); imwrite(img,'lenasave.jpg','JPEG','quality',20); imgjpg = imread('lenasave.jpg','JPEG'); figure(b), imshow(imgjpg); pause; figure(a), xptext('','','',' II. Image Conversion'); pause; % Format conversion % rgb to gray figure(a), xptext('convert color image to gray image','','>> imggray = rgb2gray(img);','>> imshow(imggray);'); imggray = rgb2gray(img); figure(b), imshow(imggray); pause; % gray to B/W figure(a), xptext('Convert Gray image to black white image','','>> imgbw = im2bw(imggray);','>> imshow(imgbw);'); imgbw = im2bw(imggray); figure(b), imshow(imgbw); pause; % rgb to hsv figure(a), xptext('Convert RGB image to HSV image','','>> imghsv = rgb2hsv(img);'); imghsv = rgb2hsv(img); pause; figure(a), xptext('Luminance Image:',' >> imshow(imghsv(:,:,3))'); figure(b), imshow(imghsv(:,:,3)); pause; figure(a), xptext('Saturation Image:',' >> imshow(imghsv(:,:,2))'); figure(b), imshow(imghsv(:,:,2)); pause; figure(a), xptext('Hue Image:',' >> imshow(imghsv(:,:,1))'); figure(b), imshow(imghsv(:,:,1)); pause; %% Basic Image Operation figure(a), xptext('','','',' III. Basic Image Operation'); pause; % Basic Image Operation % edge figure(a), xptext('Edge detection in gray image','','>> imgedge = edge(imggray,''canny'');','>> imshow(imgedge);'); imgedge = edge(imggray,'canny'); figure(b), imshow(imggray); pause; figure(c), imshow(imgedge); pause; close(c); % add noise figure(a), xptext('Add noise in gray image','','>> imgns = imnoise(imggray,''Gaussian'');','>> imshow(imgns);'); imgns = imnoise(imggray,'Gaussian'); figure(b), imshow(imggray); figure(c), imshow(imgns); pause; close(c); % Resize image figure(a), xptext('Resize Image','','>> imgrs = imresize(imggray,[128 128],''bicubic'');','>> imshow(imgrs);','','You can also use other interpolation method', 'such as bilinear or nearest neighbor'); pause; imgrs = imresize(imggray,[128 128],'bicubic'); figure(c), imshow(imgrs); pause; close(c); % Rotate image figure(a), xptext('Rotate Image','','>> imgrt = imrotate(imggray,45,''bicubic'');','>> imshow(imgrt);','','You can also use other interpolation method','such as bilinear or nearest neighbor'); figure(b), imshow(imggray); pause; imgrt = imrotate(imggray,45,'bicubic'); figure(c), imshow(imgrt); pause; close(c); % Crop image figure(a), xptext('Crop Image','','>> imgcrop = imcrop(imggray,[1 1 100 100]);','>> imshow(imgcrop);'); figure(b), imshow(imggray); pause; imgcrop = imcrop(imggray,[1 1 100 100]); figure(c), imshow(imgcrop); pause; % Zoom image figure(a), xptext('Zoom Image','','>> imshow(img);','>> zoom on;'); figure(b), imshow(img); zoom on; pause; %% 2D image processing figure(a), xptext('','','',' IV. Others: 2D image processing; M File Editting'); pause; % 2D image processing % 2D filter figure(a), xptext('2D filtering using convolution','','smooth = [1 1 1; 1 1 1; 1 1 1]/9;','>> imgsmooth = conv2(imggray,smooth);','>> imshow(imgsmooth/255);'); smooth = [1 1 1; 1 1 1; 1 1 1]/9; imgsmooth = conv2(imggray,smooth); figure(b), imshow(imggray); pause; figure(c), imshow(imgsmooth/255); pause; close(c); % image manipulation % image warping figure(a), xptext('image warping','','[x,y,z] = cylinder;','warp(x,y,z,img);'); [x,y,z] = cylinder; figure(b), warp(x,y,z,img); pause; % M File Editting figure(a), xptext('Editting M File','','>> edit imcrop.m'); edit imcrop.m