Laboratory 1: DIP Spring 2015: Introduction To The MATLAB Image Processing Toolbox
Laboratory 1: DIP Spring 2015: Introduction To The MATLAB Image Processing Toolbox
Laboratory 1: DIP Spring 2015: Introduction To The MATLAB Image Processing Toolbox
ABSTRACT
The purpose of this lab is to familiarize students with the MATLAB image processing
toolbox, and to understand how digital sampling and quantization impact the quality
of images
Basic
The image matrix which contains elements corresponding to the pixel intensities.
The elements take on values from between 1 and infinity.
The colormap matrix is G x 3 matrix, with each row containing the Red, Blue and
Green components for each level of intensity. For a monochromatic gray-level
image, this matrix starts with [0 0 0] for black and ends with [1 1 1] for white.
Each row inbetween contains equal numbers between 0 and 1 for various shades
of gray.
An image matrix element with a value of, say 5, will be displayed with the graylevel corresponding to the 5th row of the colormap matrix.
3. Grayscale Images: A grayscale image M pixels tall and N pixels wide is represented
as a matrix of double datatype of size MN. Element values denote the pixel
grayscale intensities.
4. Binary Image: A binary image is represented by an MN logical matrix where pixel
values are 1 (true) or 0 (false)
To export an image matrix [x] and a colormap matrix [map] in a specified format,
use:
>> imwrite (x, map, 'filename.fmt');
Occasionally, data may be in other formats; I will provide commands and m-files to
read them.
Image Conversion
Image Display
1. Indexed Images: If [x] is the image matrix and [map] is the colormap matrix,
>> imshow (x, map);
2. Intensity Images: If [x] is the image matrix and G is the no. of gray levels,
>> imshow(x, G);
3. Binary Images: If [x] is the image matrix,
>> imshow(x, 2);
Method
Description
'nearest'
Nearest-neighbor interpolation; the output pixel is assigned the value of the pixel that the point
falls within. No other pixels are considered.
'bilinear' Bilinear interpolation; the output pixel value is a weighted average of pixels in the nearest 2-by-2
neighborhood
'bicubic'
Bicubic interpolation (the default); the output pixel value is a weighted average of pixels in the
nearest 4-by-4 neighborhood
'box'
Box-shaped kernel
Quantize Images
Lab Assignment
Part I
1. Download a true-color (RGB) image off the web. Import this image into MATLAB
and display it. Save the image to a file; open with any other imaging software and
display it.
>> imread, >> imshow and >> imwrite commands.
DIP Lab 1 Spring 2015
2. Convert this image into a gray-level image and display it. Save the image to a file;
open with any other imaging software and display it.
>> rgb2gray, >> imshow and >> imwrite commands.
3. Convert the indexed image into an intensity image and display it. Save the image to a
file; open with any other imaging software and display it.
>> rgb2ind, >>ind2gray, >> imshow and >> imwrite commands.
4. Convert the intensity image into a binary image and display it. Save the image to a
file; open with any other imaging software and display it.
>> im2bw, >> imshow and >> imwrite commands.
5. Generate a 256x256 matrix of numbers; convert this to an intensity image and display
it. Save the image to a file; open with any other imaging software and display it.
>> mat2gray, >> imshow and >> imwrite commands.
6. Convert the indexed image you have downloaded earlier into an intensity matrix.
Save this matrix in MATLAB's native format (.mat file). Read this file and display
image.
>> mat2gray, >> imshow and >> save and >> load commands.
7. Download the image lena.jpg off the web. Down sampling it by a factor of 2, 4, 8
and 16 using the first downsampling method explained above, display and save the
results into jpg files
8. Repeat the step 7, but using imresize function with any two interpolation methods of
your choice, display and save the results into jpg files
9. Compare the results from Steps 7 and 8, and analyze the differences you observe.
10. Quantize the image lena.jpg by 20, 18, 10, 6 levels, display and save the results into
jpg files
Deliverables
A comprehensive report on the experiments conducted in the lab. In order to achieve a
maximum grade on your lab report, it must be typed and appropriately organized
covering at least all the topics identified in the Laboratory Report Format.