Robot Vision Matlab Exercises

0 downloads 0 Views 225KB Size Report
Resize the background image. ▫ >>backApprox256 = imresize(backApprox, [256,256],. 'bilinear');. ▫ >>figure, imshow(backApprox256). Show resized image ...
Robot Vision Matlab Exercises  

  

1. Read an image and display it. >>clear, close all >>I=imread(‘pout.tif’); >>imshow(I) >>whos

Read an image, compute and plot its histogram >>figure, imhist(I) %Display a histogram of I in a new figure >>I2=histeq(I); %Equalize the histogram >>figure, imshow(I2) % Display the equalized image Did it enhance it? >>figure, imhist(I2)

Store an image in a file and verify it >>imwrite(I2, ‘pout2.png’); Now check it >>imfinfo(‘pout2.png’) What does Matlab tell you?

Read an image and display it >>clear, close all >>I=imread(‘rice.tif’); >>Imshow(I)

Non-uniform illumination correction >>backApprox = blkproc(I,[32,32],’min(x(:)’); See the result >>backApprox Display the surface >>backApprox=double(backApprox)/255; %Convert to double >>figure, surf(backApprox); >>set(gca,’ydir’,’reverse’); %Reverse the y –axis Rotate surface with toolbar

Resize the background image 



>>backApprox256 = imresize(backApprox, [256,256], ‘bilinear’); >>figure, imshow(backApprox256) Show resized image

Subtract the background  



 



>>I=im2double(I); %Convert to double >>I2=I-backApprox256 ; %Subtract the background >>I2=max(min(I2,1),0); %Clip to range >>figure, imshow(I2) Look at demo on subtraction >>ipss003

Adjust the contrast 

 

>>I3=imadjust(I2, [0 max(I2(:))],[0 1]); % Adjust contract Display the new image >>figure, imshow(I3);

Apply threshold to detect edge points >>bw = I3>0.2; % Make I3 a binary image with all points >0.2 white  >>figure, imshow(bw)  >>whos See the new characteristics 

Count the objects >>[labeled,numObjects] = bwlabel(bw,4); %Label components  Show the number of objects found by bwlabel  >>numObjects The answer should be 80 grains of rice. 

Check by displaying color image 



 



>>map=hot(numObjects+1);%Create color map >>imshow(labeled+1,map); %Offset indices to colormap by 1 to avoid index 0 Count again >>max(labeled(:)) Again the answer should be 80

Examine an object 

 

>>grain = imcrop(labeled) % Crop a portion of the image Look at values >>grain

Region of interest  

 

>>rect= [ 15 25 10 10]; Roi = imcrop(labeled, rect) This shows the numbers starting at ((15,25) and of width 10 by 10

Compute image features  

  



>>grain = imfeature(labeled, ‘basic’) Find the area of grain 51 >>grain(51).area Should be 323 pixels Find the smallest possible bounding box and the centroid of grain 51 >>grain(51).BoundingBox >>grain(51).Centroid

Look at all areas  

 

>>allgrains=[grain.Area]; >> whos allgrains >>allgrains(51) Is it still 323?

Statistical properties  

  

>>max(allgrains) >>biggrain = find(allgrains ==749) Should return 68 >>mean(allgrains) >>hist(allgrains,20)

Where to go next  

    

Read Chapter 2 Look at Tutorials, Chapters 4 and 5 All functions are defined in Chapter 12 Help is available using >> help functionname Online Help Toolbox Demos as Templates

Theory and Practice 

Next we will start reviewing some theory and see if we can put in in practice

Image Processing Toolbox User Manual 



http://www.mathworks.com/access/hel pdesk/help/pdf_doc/images/images_tb. pdf Let’s try the exercises in this user guide