The document describes the Image Processing Toolbox in MATLAB. It provides functions for reading, displaying, manipulating and writing images. Some key functions include imread to read an image, imshow to display it, imhist for histograms, imadjust for contrast adjustment, and imwrite to write the image. Operations like morphological opening, thresholding, labeling connected components and measuring object properties are also covered.
2. Introduction
Collection of functions (MATLAB
files) that supports a wide range of image
processing operations
Documentation
www.mathworks.com
3. Read an Image
Read in an image
Validates the graphic format
(bmp, hdf, jpeg, pcx, png, tiff, xwd)
Store it in an array
clear, close all
I = imread(‘pout.tif`);
[X, map] = imread(‘pout.tif’);
5. Check the Image in Memory
< Name, Size, Bytes, Class >
whos
Name
Size
Bytes Class
ans 291x240
69840 uint8 array
Grand total is 69840 elements using 69840 bytes
uint8
uint16
double
[0, 255]
[0, 65535]
[0, 1]
9. Write the Image
Validates the extension
Writes the image to disk
imwrite(I2, ’pout2.png’);
imwrite(I2, ‘pout2.png’, ‘BitDepth’, 4);
10. Morphological Opening
Remove objects that cannot completely
contain a structuring element
Estimate background illumination
clear, close all
I = imread(‘rice.tif’);
imshow(I)
background = imopen(I, strel(‘disk’, 15));
imshow(background)
16. Labeling Connected
Components
Determine the number of objects in the
image
Accuracy
(size of objects, approximated background,
connectivity parameter, touching objects)
[labeled, numObjects] = bwlabel(bw, 4);
numObjects
{= 80}
max(labeled(:))
17. Select and Display
Pixels in a Region
Interactive selection
grain = imcrop(labeled)
Colormap creation function
RGB_label = label2rgb(labeled,
@spring, ‘c’, ‘shuffle’);
imshow(RGB_label);
rect = [15 25 10 10];
roi = imcrop(labeled, rect)
18. Object Properties
Measure object or region properties
graindata = regionprops(labeled, ‘basic’)
graindata(51).Area
{296}
graindata(51).BoundingBox
{142.5 89.5 24.0 26.0}
graindata(51).Centroid
{155.3953 102.1791}
Create a vector which holds just one property for
each object
allgrains = [graindata.Area];
whos
19. Statistical Properties
of Objects
max(allgrains)
{ 695 }
Return the component label of a grain size
biggrain = find(allgrains == 695) { 68 }
Mean grain size
mean(allgrains)
Histogram (#bins)
hist(allgrains, 20)
{ 249 }
21. Storage Classes
double (64-bit), uint8 (8-bit), and uint16
(16-bit)
Converting (rescale or offset)
double
im2double (automatic rescale and offsetting)
RGB2 = im2uint8(RGB1);
im2uint16
imapprox (reduce number of colors: indexed images)
22. Image Types
Index
Data
matrix (uint8, uint16, double)
Colormap matrix (m x 3 array of double [0 1])
Intensity (black = 0, white = ∞)
Binary (0, 1)
B = logical(uint8(round(A))); (logical flag on)
B = +A; (logical flag off)
RGB (m x n x 3 of truecolor)
33. Dividing Images (Ratioing)
I = imread(‘rice.tif’);
background = imopen(I, strel(‘disk’, 15));
Ip = imdivide(I, background);
imshow(Ip, [])
Linear combination only truncates the final
result
K = imlincomb(.5, I, .5, I2);