CIS 601 Spring 2007
Homework 2
Use MATLAB to build a little image database, consisting of 4 classes of gray level images with 2 images in
each class.
The class is defined by terms of histogram similarity (i.e. the 2 images in each class have a similar histogram
that differs from the histogram of the remaining 6 images). To show the functionality, you should query the database
with these 8 images, and plot the top 2 responses.
The information given in a histogram is insufficient to build a general purpose image database, your main task
besides the programming is therefore to think about the image selection.
Your task in steps:
- select 8 images with the property defined above.
- program a function 'sim = histogramSimilarity (im1,im2)' that takes 2 images as input and returns
the scalar value 'sim', the quantitative measure of similarity.
- program a function '[im1,im2]=query(img)' that compares img to the database using the histogram similarity
function and returns the top 2 results.
- plot the top 2 result for each of the 8 images, creating a plot with 3 rows, 8 columns (use subplot(8,3,i)).
Top row: query, second row: best result, third row: 2nd best result (top row should show the same image as 2nd
row, since the best best result to the query should be the image itself).
Since we didn't talk about histograms in class yet, here's some more help:
- There's a lot about histograms in my slides. It might help to take a look.
- The command to create a histogram from images in MATLAB is 'imhist(image,bins)', where 'bins' is the number of bins
used for the histogram. Please use a value of 256 (which is also the default value if you use uint8 - images).
- A histogram is simply a vector. Use the euclidean distance between 2 histograms h1,h2 (MATLAB: 'norm(h1-h2)') to determine
the dissimilarity. You may want to experiment with different measures, some are given in my slides.
- The function 'sim = histogramSimilarity (im1,im2)' described above is actually a single line in MATLAB, don't be confused, it's that simple.
- You retrieve the top 2 results by first comparing all 8 images to the query, collecting the results in an 8 dimensional vector. Sorting
this vector using the MATLAB 'sort' command conveniently gives you the order of indices (see documentation of 'sort').
Task #2:
Use 8 randomly picked images (e.g. from the web or from your last vacation) and query the database.
Same output as in task #1. Is this kind of image data base of any use (don't be too negative... it actually is)?
enjoy!
Score: 10 points