IVR Practical Four: Introduction to Vision 2 (Week 4)
The purpose of this practical is to:
- Try automatic and adaptive thresholding to segment an object from
background
- Use moments to produce descriptive vectors for a segmented image
- Build a probability model from several images and use it to do
classification
As before you can download matlab programs corresponding to those used
in the lectures from:
http://www.inf.ed.ac.uk/teaching/courses/ivr/MATLAB/FLATPARTRECOG/
There are also some versions that avoid licence problems in that folder.
If, last week, you did not get up to using a threshold to segment an
image, you should look at doing this first. The image
processing toolbox provides a function you could use called im2bw (but
be careful because this assumes the image is still in uint format). It
is probably good practice in matlab coding to write your own version
anyway.
You should note that some of the following code assumes that you have
re-coded the image as 0 for the background and 1 for the object, so
make sure the output of your function does this (n.b. a convenient
operator here might be the not operator '~' which changes 1 to 0 and
vice versa).
Feature vectors
For the following you can either use the images of simple shapes
provided at the above website (but check the labelling), or capture
your own set of images, using three different shaped objects seen at
various orientations.
Use your preferred thresholding method to convert your images to binary
images, i.e. with values either 0 for background or 1 for the object.
Try finding a compactness value for your images (see the lecture notes).
Using complexmoment.m
try calculating various central moments of the different images.
The m-file getproperties.m
calculates compactness, scaled central moments and
rotation invariants for an image. Try this on various images and
see whether the same shape, from different views, produces more
similar feature vectors than different shapes. (N.B. you should edit
the final lines of this m-file if you want to see all the
calculated features rather than just the first three).
Building a model for recognizing images
Look at the m-file buildmodel.m
This assumes you have a matrix of feature vectors (Vecs) for a
set of images, and a corresponding vector (Classes) providing the
correct classification for each image. You should be able to construct
these from what you did in the previous section, and try running the buildmodel
function. N.B. you also need to specify the number
of feature vectors (N) the number of classes (Numclass) and the
dimension of the feature vectors (Dim). The dimension should be less
than the number of example images in each class (e.g. with four
examples, use 3 features).
The result is the mean and covariance matrix for each class, which can
be used to calculate the probability that a particular image belongs to
each class (e.g. assuming multivariate gaussion distributions as
discussed in the lecture, as shown in the function multivariate.m)
The function classify.m
does this for all the classes in a model to come up with a best
classification.
For more information on thresholding see
this page
Main IVR Page