Professional Documents
Culture Documents
Matlab: Image Processing Toolbox
Matlab: Image Processing Toolbox
Matlab: Image Processing Toolbox
Introduction
Collection of functions (MATLAB files) that supports a wide range of image processing operations Documentation
www.mathworks.com
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);
Display an Image
imshow(I)
Histogram Equalization
Histogram: distribution of intensities
figure, imhist(I)
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)
Subtract Images
Create a more uniform background
I2 = imsubtract(I, background); figure, imshow(I2)
Compute a threshold to convert the intensity image to binary Perform thresholding creating a logical matrix (binary image) level = graythresh(I3); bw = im2bw(I3, level); figure, imshow(bw)
(size of objects, approximated background, connectivity parameter, touching objects) [labeled, numObjects] = bwlabel(bw, 4); numObjects max(labeled(:))
{= 80}
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
max(allgrains)
{ 695 }
Histogram (#bins)
hist(allgrains, 20)
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)
Image Types
Index
Data matrix (uint8, uint16, double) Colormap matrix (m x 3 array of double [0 1])
RGB (m x n x 3 of truecolor)
imshow(MULTI(:, :, :, 7))
Image Arithmetic
imabsdiff imadd imcomplement imdivide imlincomb immultiply imsubtract
Adding Images
I = imread(rice.tif); J = imread(cameraman.tif); K = imadd(I, J); imshow(K)
Subtracting Images
Background of a scene
rice = imread(rice.tif); background = imopen(rice, strel(disk, 15)); rice2 = imsubtract(rice, background); imshow(rice), figure, imshow(rice2);
Negative values
imabsdiff
Multiplying Images
Scaling: multiply by a constant
Coordinate Systems
Pixel Coordinates
Spatial Coordinates
Spatial Transformations
Map pixel locations in an input image to new locations in an output image
Resizing Images
Change the size of an image
I = imread(ic.tif); J = imresize(I, 1.25); K = imresize(I, [100 150]); figure, imshow(J) figure, imshow(K)
Rotating Images
Rotate an image by an angle in degrees
I = imread(ic.tif); J = imrotate(I, 35, bilinear); imshow(I) figure, imshow(J)
Cropping Images
Extract a rectangular portion of an image
imshow ic.tif I = imcrop;