Introduction to Image Processing in Matlab & Binary Image Analysis
Welcome to your first Computer Vision Lab. This lab will introduce you to writing
image processing software using Matlab and the Matlab Image Processing Toolbox. You will learn how to load, view and manipulate images, convert between image formats, threshold images, and you will write a function that calculates the moments and orientation of a binary object.
Deliverable:
To gain the marks for this lab you will need to show me your Lab1 function running
during the lab. The specification for this function is towards the end of this document.
To get started quickly work through the Getting Started and Introduction to Image
Processing in Matlab sections.
Getting Started
1. Make a new directory in which to do your work for this course.
2. Download the image ‘text.tiff’ from
http://www.syseng.anu.edu.au/~luke/cvcourse_files/images/text.tiff
Save this image in your new directory.
3. Open Matlab from the Start>Programs menu.
4. Change to your new directory (use cd).
5. Type edit to open a new script file, and you are ready to start work.
I suggest you do all your work in your script file.
Did you know:
• You can write multiple Matlab functions in the same file? This is helpful to keep your work together especially when working on large projects, to do this you will have to make the file a function.
• You can use the debugging features in the Matlab editor to jump between the local variable spaces when debugging your functions. Check 'Stop if Error' in the Breakpoints menu of the Matlab editor to activate the debugger on the next error. Note the different cursor in debugging mode.
• dbquit exits debugging mode. Remember to quit debugging mode before
rerunning your code.
Introduction to Image Processing in Matlab
You can get help on any Matlab function by typing help <function> or to get help
specifically on the Image P rocessing Toolbox type help images, typing just help
will show you all the available help topics.
Load the image into im_rgb with
im_rgb = imread(‘text.tiff’);
convert to type double
im_rgb = double(im_rgb);
convert to grey-scale
im_grey = (im_rgb(:,:,1)+im_rgb(:,:,2)+im_rgb(:,:,3))/3;
or you can use rgb2gray which gives a slightly different result since it converts to a
luminance rather than an intensity image, you'll learn about this in the lecture on colour imaging. For this lab it doesn't matter which one you use.
convert from [0,255] to [0,1]
im_grey = im_grey/255;
to view an image use either imshow(im) or imagesc(im), note the difference. You
can use imagesc and then set the axis for an image with
axis image ;
Axis labelling can be turned on and off by
axis on;
axis off;
You can interactively crop an image using imcrop(im_grey); Try this. For this lab
exercise I would like you to crop the image to a specified region containing only the 2nd letter. Do this with
im_grey = im_grey(150:270, 280:400);
Examine the intensity profile of im_grey
improfile(im_grey);
Threshold im_grey
im_bin = imgrey>0.5;
The object we are interest in is the text, since we have defined binary objects to be 1’s and the background to be zero we need to invert the image
im_bin = 1 – im_bin; % inverts the binary image.
You can find the coordinates of the points in this object using find. Type help find
to learn about this function. Write a line of code using find that returns the x and y
values of all the points in the object.
2 comments:
sir, i am working on the project of text extraction from images using globally matched wavelets and MRF post processing using MATLAB. I would be greatful to you if you could help me out with matlab codes for this project,especially the database part which we would have to create to train the system. My email id is rahulsharma.s04@gmail.com
hi there
how to make an imge object of 256x256 pixels with three values like background 0 , and other two values as 0.5 and 1 . i could only do this
image1 = ones([256 256]); % setting elements to 1
imshow(image);
how to introduce third value background 0 into this or i have to use some other function...which one and how?
Post a Comment