Sie sind auf Seite 1von 1

# CSCI 510/EGGN 510

## Image and Multidimensional Signal Processing

Fall 2014

In Class Exercise 1
Start up Matlab from the start menu. Tutorials and examples can be found under the menu item Help>MATLAB Help. For help on the Image Processing Toolbox, look under Image Processing Toolbox in
the Help Navigator. You can get help on specific commands using the Help Navigator, or from the
Matlab command line (using help commandname).
The image coins.png is in the Matlab folder with other sample images. Read in the image using
Display it using the function imshow or imtool1. The empty brackets in this command tell Matlab to
stretch the values so that they occupy the entire grayscale range; ie, the lowest value is displayed as black
and the highest value is displayed as white.
1. What is the size of the image (#rows, #columns)? What is the storage class? (You can see the list of
all workspace variables using whos.)
2. Does the pixel at (row=100, column=50) belong to a coin or the background? What is the pixel
value? You can inspect the pixel values interactively using the mouse, using impixelinfo.
Alternatively, you can display the image using imtool and use the pixel region tool.
3. View the histogram of the image using imhist(I). This will show the count, or frequency, of
each gray level. What is the range of gray levels for this image, and which gray level (approximately)
has the largest count?
4. Threshold the image, to separate the coins from the background. In other words, create a second
image such that pixels above a certain value are mapped to white (or 1), and pixels below that value
are mapped to black (or 0). You can use the greater-than expression, as in B = (I > t). Here,
t is a value between 0 and 255. Find the value for t that best appears to segment the coins from the
background.
Type in the following code and save it in a file with a .m extension. You can then run the program by
typing the name of the file on the command line.
clear all
close all

## % This clears all workspace variables

% This closes all figures (except those opened with imtool)

I2 = zeros(size(I1)); % Not necessary to preallocate arrays, but is faster
for r=1:size(I1,1)
for c=1:size(I1,2)
if (c>size(I1,2)/2)
I2(r,c) = 20;
end
end
end

5. Fuse the image from the previous step with the original coins image by adding them (you can do this
with a single command). Note you will have to first convert the images to type double. Display
the fused image, and show it to the instructor.
1

imshow is faster than imtool, but imtool presents a graphical user interface environment for
performing some common image processing tasks. Usually imshow (with impixelinfo) is good
enough for most things.