You are on page 1of 2

Tutorial 2

1. Getting started with matlab


imread()

Read an image into a matrix

481 : image height


321: image width
3: 3 RGB channels
imshow()

Display the image

impixel() Used for getting value of a pixel

imwrite() Save an image with a specified name and format

imhist() Show the histogram for an image


To set n number of bins, not the default value use imhist(I,n)

HashMaps
>> m = containers.Map('KeyType','int32','ValueType','double');
>> m(1) = 3.14;

For example used in representing the words frequencies in text document


classification

2. Assignment
1. Write code to find the distance between two string patterns.
(Implement Levenshtein distance; the cheapest way to transform one
string to another)
2. Given an image, it is required to extract the pixels as 3D feature vectors
with features specified by the R, G, and B values.
You should then label each pixel with a class label based on the two
methods described below, such that each pixel belongs to one of 3
classes: Red, Green or Blue.
Plot the image again with each pixel having the R, G, and B values set to
(255, 0, 0), (0, 255, 0), and (0, 0,255) for the Red, Green and Blue
classes respectively.
Plot the histogram of the image using your own function.
Methods of classifying the pixels are as follows:

Method 1: The pixel belongs to the class of max color value. e.g.
pixel (123, 45, 221) belongs to class B, pixel (98, 21, 80)
belongs to class R

Method 2: Average of each feature (R, G, and B) is calculated.


Then, the pixel belongs to the class whose color value closest to
the average of this feature

Which of the above methods gives more accurate results?


(Hint: this can be done by visualizing images after coloring pixels with
the colors of their classes, for example (255,0,0) is the color for all
pixels in R)

You might also like