Matlab Image Processing Toolbox Documentation pdf download
Matlab Image Processing Toolbox Documentation pdf download
download
https://ebookbell.com/product/matlab-image-processing-toolbox-
documentation-6741908
https://ebookbell.com/product/matlab-image-processing-toolbox-users-
guide-unknown-48950730
https://ebookbell.com/product/matlab-image-processing-toolbox-users-
guide-r2021a-mathwork-36128440
https://ebookbell.com/product/matlab-image-processing-toolbox-users-
guide-r2020a-the-mathworks-11236248
https://ebookbell.com/product/biosignal-and-medical-image-processing-
matlabbased-applications-signal-processing-and-communications-1st-
edition-john-l-semmlow-2355206
Biosignal And Biomedical Image Processing Matlab Based Applications
John L Semmlow
https://ebookbell.com/product/biosignal-and-biomedical-image-
processing-matlab-based-applications-john-l-semmlow-5911026
https://ebookbell.com/product/digital-image-processing-using-
matlab-4th-edition-rafael-c-gonzalez-34385212
https://ebookbell.com/product/digital-image-processing-using-
matlab-2nd-edition-rafael-c-gonzalez-4072380
https://ebookbell.com/product/digital-image-processing-using-matlab-
rafael-c-gonzalez-richard-ewoods-50195688
https://ebookbell.com/product/digital-image-processing-using-
matlab-2nd-edition-rafael-c-gonzalez-10945078
Image Processing Toolbox™
User's Guide
R2016a
How to Contact MathWorks
Phone: 508-647-7000
Getting Started
1
Image Processing Toolbox Product Description . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Compilability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25
Introduction
2
Images in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
v
Image Types in the Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Overview of Image Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Binary Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Indexed Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
Grayscale Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13
Truecolor Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-14
vi Contents
Nesting Calls to Image Arithmetic Functions . . . . . . . . . . . 2-60
vii
Interfile Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23
viii Contents
Reduced Resolution Data Set for Very Large Images . . . . . 4-24
ix
Convert Multiframe Image to Movie . . . . . . . . . . . . . . . . . . . 4-74
x Contents
Create Your Own Modular Tools . . . . . . . . . . . . . . . . . . . . . . 5-35
Geometric Transformations
6
Resize an Image with imresize Function . . . . . . . . . . . . . . . . 6-2
Image Registration
7
Image Registration Techniques . . . . . . . . . . . . . . . . . . . . . . . . 7-2
xi
Control Point Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
xii Contents
Designing and Implementing Linear Filters for
Image Data
8
What Is Image Filtering in the Spatial Domain? . . . . . . . . . . 8-2
Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Correlation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
xiii
Transforms
9
Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Definition of Fourier Transform . . . . . . . . . . . . . . . . . . . . . . 9-2
Discrete Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7
Applications of the Fourier Transform . . . . . . . . . . . . . . . . 9-10
Morphological Operations
10
Morphological Dilation and Erosion . . . . . . . . . . . . . . . . . . . 10-2
Processing Pixels at Image Borders (Padding Behavior) . . . 10-3
xiv Contents
Erode an Image Using imerode . . . . . . . . . . . . . . . . . . . . . . 10-12
Skeletonization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-18
xv
Contour Plot of Image Data . . . . . . . . . . . . . . . . . . . . . . . . . . 11-9
Create Contour Plot of Image Data . . . . . . . . . . . . . . . . . . . 11-9
xvi Contents
Gamma Correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-47
Specify Gamma when Adjusting Contrast . . . . . . . . . . . . . 11-47
xvii
Image Segmentation Using the Image Segmenter App . . 11-114
Open Image Segmenter App . . . . . . . . . . . . . . . . . . . . . . 11-114
Segment the Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-117
Refine the Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . 11-122
ROI-Based Processing
12
ROI Processing in Image Processing Toolbox . . . . . . . . . . . 12-2
xviii Contents
Image Deblurring
13
Image Deblurring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
Deblurring Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-4
Color
14
Displaying Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2
xix
Convert from YIQ to RGB Color Space . . . . . . . . . . . . . . . . 14-12
xx Contents
Choosing Block Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-11
xxi
GPU Computing with Image Processing Toolbox
Functions
17
Image Processing on a GPU . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2
xxii Contents
1
Getting Started
This chapter contains two examples to get you started doing image processing using
MATLAB® and the Image Processing Toolbox software. The examples contain cross-
references to other sections in the documentation manual that have in-depth discussions
on the concepts presented in the examples.
Image Processing Toolbox supports a diverse set of image types, including high dynamic
range, gigapixel resolution, embedded ICC profile, and tomographic. Visualization
functions and apps let you explore images and videos, examine a region of pixels, adjust
color and contrast, create contours or histograms, and manipulate regions of interest
(ROIs). The toolbox supports workflows for processing, displaying, and navigating large
images.
Key Features
• Image analysis, including segmentation, morphology, statistics, and measurement
• Image enhancement, filtering, and deblurring
• Geometric transformations and intensity-based image registration methods
• Image transforms, including FFT, DCT, Radon, and fan-beam projection
• Large image workflows, including block processing, tiling, and multiresolution display
• Visualization apps, including Image Viewer and Video Viewer
• Multicore- and GPU-enabled functions, and C-code generation support
1-2
Configuration Notes
Configuration Notes
To determine if the Image Processing Toolbox software is installed on your system, type
this command at the MATLAB prompt.
ver
When you enter this command, MATLAB displays information about the version of
MATLAB you are running, including a list of all toolboxes installed on your system and
their version numbers. For a list of the new features in this version of the toolbox, see the
Release Notes documentation.
Many of the toolbox functions are MATLAB files with a series of MATLAB statements
that implement specialized image processing algorithms. You can view the MATLAB
code for these functions using the statement
type function_name
You can extend the capabilities of the toolbox by writing your own files, or by using the
toolbox in combination with other toolboxes, such as the Signal Processing Toolbox™
software and the Wavelet Toolbox™ software.
For information about installing the toolbox, see the installation guide.
For the most up-to-date information about system requirements, see the system
requirements page, available in the products area at the MathWorks Web site
(www.mathworks.com).
1-3
1 Getting Started
Related Products
MathWorks provides several products that are relevant to the kinds of tasks you can
perform with the Image Processing Toolbox software and that extend the capabilities
of MATLAB. For information about these related products, see www.mathworks.com/
products/image/related.html.
1-4
Compilability
Compilability
The Image Processing Toolbox software is compilable with the MATLAB Compiler™
except for the following functions that launch GUIs:
• cpselect
• implay
• imtool
1-5
1 Getting Started
Read an image into the workspace, using the imread command. The example reads one
of the sample images included with the toolbox, an image of a young girl in a file named
pout.tif , and stores it in an array named I . imread infers from the file that the
graphics file format is Tagged Image File Format (TIFF).
I = imread('pout.tif');
Display the image, using the imshow function. You can also view an image in the Image
Viewer app. The imtool function opens the Image Viewer app which presents an
integrated environment for displaying images and performing some common image
processing tasks. The Image Viewer app provides all the image display capabilities
of imshow but also provides access to several other tools for navigating and exploring
images, such as scroll bars, the Pixel Region tool, Image Information tool, and the
Contrast Adjustment tool.
imshow(I)
1-6
Basic Image Import, Processing, and Export
Check how the imread function stores the image data in the workspace, using the whos
command. You can also check the variable in the Workspace Browser. The imread
function returns the image data in the variable I , which is a 291-by-240 element array of
uint8 data.
whos I
1-7
1 Getting Started
View the distribution of image pixel intensities. The image pout.tif is a somewhat low
contrast image. To see the distribution of intensities in the image, create a histogram
by calling the imhist function. (Precede the call to imhist with the figure command so
that the histogram does not overwrite the display of the image I in the current figure
window.) Notice how the histogram indicates that the intensity range of the image is
rather narrow. The range does not cover the potential range of [0, 255], and is missing
the high and low values that would result in good contrast.
figure
imhist(I)
1-8
Basic Image Import, Processing, and Export
Improve the contrast in an image, using the histeq function. Histogram equalization
spreads the intensity values over the full range of the image. Display the image. (The
toolbox includes several other functions that perform contrast adjustment, including
imadjust and adapthisteq, and interactive tools such as the Adjust Contrast tool,
available in the Image Viewer.)
I2 = histeq(I);
figure
imshow(I2)
Call the imhist function again to create a histogram of the equalized image I2 . If you
compare the two histograms, you can see that the histogram of I2 is more spread out
over the entire range than the histogram of I .
figure
imhist(I2)
1-9
1 Getting Started
Write the newly adjusted image I2 to a disk file, using the imwrite function. This
example includes the filename extension '.png' in the file name, so the imwrite
function writes the image to a file in Portable Network Graphics (PNG) format, but you
can specify other formats.
imwrite (I2, 'pout2.png');
View what imwrite wrote to the disk file, using the imfinfo function. The imfinfo
function returns information about the image in the file, such as its format, size, width,
and height.
1-10
Basic Image Import, Processing, and Export
imfinfo('pout2.png')
ans =
Filename: 'C:\TEMP\Bdoc16a_342494_2988\tp11049ca1_a4a7_4...'
FileModDate: '15-Feb-2016 15:02:34'
FileSize: 36938
Format: 'png'
FormatVersion: []
Width: 240
Height: 291
BitDepth: 8
ColorType: 'grayscale'
FormatSignature: [137 80 78 71 13 10 26 10]
Colormap: []
Histogram: []
InterlaceType: 'none'
Transparency: 'none'
SimpleTransparencyData: []
BackgroundColor: []
RenderingIntent: []
Chromaticities: []
Gamma: []
XResolution: []
YResolution: []
ResolutionUnit: []
XOffset: []
YOffset: []
OffsetUnit: []
SignificantBits: []
ImageModTime: '15 Feb 2016 20:02:34 +0000'
Title: []
Author: []
Description: []
Copyright: []
CreationTime: []
Software: []
Disclaimer: []
Warning: []
Source: []
Comment: []
OtherText: []
1-11
1 Getting Started
I = imread('rice.png');
imshow(I)
In the sample image, the background illumination is brighter in the center of the image
than at the bottom. As a preprocessing step before analysis, make the background
1-12
Basic Image Enhancement and Analysis Techniques
uniform and then convert the image into a binary image. To make the background
illumination more uniform, create an approximation of the background as a separate
image and then subtract this approximation from the original image.
As a first step to creating a background approximation image, remove all the foreground
(rice grains) using morphological opening. The opening operation has the effect of
removing objects that cannot completely contain the structuring element. To remove the
rice grains from the image, the structuring element must be sized so that it cannot fit
entirely inside a single grain of rice. The example calls the strel function to create a
disk-shaped structuring element with a radius of 15.
background = imopen(I,strel('disk',15));
figure
surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
1-13
1 Getting Started
Subtract the background approximation image, background, from the original image, I,
and view the resulting image. After subtracting the adjusted background image from the
original image, the resulting image has a uniform background but is now a bit dark for
analysis
I2 = I - background;
imshow(I2)
1-14
Basic Image Enhancement and Analysis Techniques
I3 = imadjust(I2);
imshow(I3);
1-15
1 Getting Started
Create a binary version of the processed image so you can use toolbox functions for
analysis. Use the im2bw function to convert the grayscale image into a binary image by
using thresholding. The function graythresh automatically computes an appropriate
threshold to use to convert the grayscale image to binary. Remove background noise with
the bwareaopen function.
level = graythresh(I3);
bw = im2bw(I3,level);
bw = bwareaopen(bw, 50);
imshow(bw)
1-16
Basic Image Enhancement and Analysis Techniques
Now that you have created a binary version of the original image you can perform
analysis of objects in the image.
Find all the connected components (objects) in the binary image. The accuracy of your
results depends on the size of the objects, the connectivity parameter (4, 8, or arbitrary),
and whether or not any objects are touching (in which case they could be labeled as one
object). Some of the rice grains in the binary image bw are touching.
cc = bwconncomp(bw, 4)
cc.NumObjects
cc =
Connectivity: 4
ImageSize: [256 256]
1-17
1 Getting Started
NumObjects: 95
PixelIdxList: {1x95 cell}
ans =
95
grain = false(size(bw));
grain(cc.PixelIdxList{50}) = true;
imshow(grain);
Visualize all the connected components in the image. First, create a label matrix, and
then display the label matrix as a pseudocolor indexed image. Use labelmatrix to
create a label matrix from the output of bwconncomp . Note that labelmatrix stores
1-18
Basic Image Enhancement and Analysis Techniques
the label matrix in the smallest numeric class necessary for the number of objects. Since
bw contains only 95 objects, the label matrix can be stored as uint8 . In the pseudocolor
image, the label identifying each object in the label matrix maps to a different color in
an associated colormap matrix. Use label2rgb to choose the colormap, the background
color, and how objects in the label matrix map to colors in the colormap.
labeled = labelmatrix(cc);
RGB_label = label2rgb(labeled, @spring, 'c', 'shuffle');
imshow(RGB_label)
Compute the area of each object in the image using regionprops. Each rice grain is one
connected component in the cc structure.
graindata =
1-19
1 Getting Started
Area
Centroid
BoundingBox
Find the area of the 50th component, using dot notation to access the Area field in the
50th element of graindata .
graindata(50).Area
ans =
194
Create a vector grain_areas to hold the area measurement of each object (rice grain).
grain_areas = [graindata.Area];
min_area =
61
idx =
16
1-20
Basic Image Enhancement and Analysis Techniques
nbins = 20;
figure, hist(grain_areas, nbins)
title('Histogram of Rice Grain Area');
1-21
1 Getting Started
1-22
Getting Help
Getting Help
In this section...
“Product Documentation” on page 1-23
“Image Processing Examples” on page 1-23
“MATLAB Newsgroup” on page 1-24
Product Documentation
The Image Processing Toolbox documentation is available online in both HTML and
PDF formats. To access the HTML help, select Help from the menu bar of the MATLAB
desktop. In the Help Navigator pane, click the Contents tab and expand the Image
Processing Toolbox topic in the list.
To access the PDF help, click Image Processing Toolbox in the Contents tab of the
Help browser and go to the link under Printable (PDF) Documentation on the Web. (Note
that to view the PDF help, you must have Adobe® Acrobat® Reader installed.)
For reference information about any of the Image Processing Toolbox functions, type in
the MATLAB command window
help functionname
For example,
help imtool
To view all the examples, call the iptdemos function. This displays an HTML page in
the MATLAB Help browser that lists all the examples.
1-23
1 Getting Started
matlabroot\toolbox\images\imdata
MATLAB Newsgroup
If you read newsgroups on the Internet, you might be interested in the MATLAB
newsgroup (comp.soft-sys.matlab). This newsgroup gives you access to an active
MATLAB user community. It is an excellent way to seek advice and to share algorithms,
sample code, and MATLAB files with other MATLAB users.
1-24
Acknowledgments
Acknowledgments
This table lists the copyright owners of the images used in the Image Processing Toolbox
documentation.
Image Source
cameraman Copyright Massachusetts Institute of Technology. Used
with permission.
cell Cancer cell from a rat's prostate, courtesy of Alan W.
Partin, M.D., Ph.D., Johns Hopkins University School of
Medicine.
circuit Micrograph of 16-bit A/D converter circuit, courtesy of
Steve Decker and Shujaat Nadeem, MIT, 1993.
concordaerial and Visible color aerial photographs courtesy of mPower3/
westconcordaerial Emerge.
concordorthophoto and Orthoregistered photographs courtesy of Massachusetts
westconcordorthophoto Executive Office of Environmental Affairs, MassGIS.
forest Photograph of Carmanah Ancient Forest, British
Columbia, Canada, courtesy of Susan Cohen.
LAN files Permission to use Landsat data sets provided by Space
Imaging, LLC, Denver, Colorado.
liftingbody Picture of M2-F1 lifting body in tow, courtesy of NASA
(Image number E-10962).
m83 M83 spiral galaxy astronomical image courtesy of Anglo-
Australian Observatory, photography by David Malin.
moon Copyright Michael Myers. Used with permission.
saturn Voyager 2 image, 1981-08-24, NASA catalog #PIA01364.
solarspectra Courtesy of Ann Walker. Used with permission.
tissue Courtesy of Alan W. Partin, M.D., PhD., Johns Hopkins
University School of Medicine.
trees Trees with a View, watercolor and ink on paper,
copyright Susan Cohen. Used with permission.
1-25
2
Introduction
This chapter introduces you to the fundamentals of image processing using MATLAB and
the Image Processing Toolbox software.
Images in MATLAB
The basic data structure in MATLAB is the array, an ordered set of real or complex
elements. This object is naturally suited to the representation of images, real-valued
ordered sets of color or intensity data.
MATLAB stores most images as two-dimensional arrays (i.e., matrices), in which each
element of the matrix corresponds to a single pixel in the displayed image. (Pixel is
derived from picture element and usually denotes a single dot on a computer display.)
For example, an image composed of 200 rows and 300 columns of different colored dots
would be stored in MATLAB as a 200-by-300 matrix. Some images, such as truecolor
images, require a three-dimensional array, where the first plane in the third dimension
represents the red pixel intensities, the second plane represents the green pixel
intensities, and the third plane represents the blue pixel intensities. This convention
makes working with images in MATLAB similar to working with any other type of
matrix data, and makes the full power of MATLAB available for image processing
applications.
2-2
Exploring the Variety of Random
Documents with Different Content
excused for non-attendance three parts of the year, having but half
as far to go; but in the lonely parts of Scotland they make little of a
journey of nine or ten miles to a preaching. They have not perhaps
an opportunity of going more than once in a quarter of a year, and,
setting piety aside, have other motives to attend: they hear the
news, public and private, and see their friends and neighbours; for
though the people who meet at these times may be gathered
together from a circle of twenty miles' diameter, a sort of
neighbourly connexion must be so brought about. There is
something exceedingly pleasing to my imagination in this gathering
together of the inhabitants of these secluded districts—for instance,
the borderers of these two large lakes meeting at the deserted
garrison which I have described. The manner of their travelling is on
foot, on horseback, and in boats across the waters,—young and old,
rich and poor, all in their best dress.
If it were not for these Sabbath-day meetings one summer month
would be like another summer month, one winter month like another
—detached from the goings-on of the world, and solitary
throughout; from the time of earliest childhood they will be like
landing-places in the memory of a person who has passed his life in
these thinly peopled regions; they must generally leave distinct
impressions, differing from each other so much as they do in
circumstances, in time and place, etc.,—some in the open fields,
upon hills, in houses, under large rocks, in storms, and in fine
weather.
But I have forgotten the fireside of our hut. After long waiting,
the girls, who had been on the look-out, informed us that the boat
was coming. I went to the water-side, and saw a cluster of people
on the opposite shore; but being yet at a distance, they looked more
like soldiers surrounding a carriage than a group of men and
women; red and green were the distinguishable colours. We
hastened to get ourselves ready as soon as we saw the party
approach, but had longer to wait than we expected, the lake being
wider than it appears to be. As they drew near we could distinguish
men in tartan plaids, women in scarlet cloaks, and green umbrellas
by the half-dozen. The landing was as pretty a sight as ever I saw.
The bay, which had been so quiet two days before, was all in motion
with small waves, while the swoln waterfall roared in our ears. The
boat came steadily up, being pressed almost to the water's edge by
the weight of its cargo; perhaps twenty people landed, one after
another. It did not rain much, but the women held up their
umbrellas; they were dressed in all the colours of the rainbow, and,
with their scarlet cardinals, the tartan plaids of the men, and Scotch
bonnets, made a gay appearance. There was a joyous bustle
surrounding the boat, which even imparted something of the same
character to the waterfall in its tumult, and the restless grey waves;
the young men laughed and shouted, the lasses laughed, and the
elder folks seemed to be in a bustle to be away. I remember well
with what haste the mistress of the house where we were ran up to
seek after her child, and seeing us, how anxiously and kindly she
inquired how we had fared, if we had had a good fire, had been well
waited upon, etc. etc. All this in three minutes—for the boatman had
another party to bring from the other side and hurried us off.
The hospitality we had met with at the two cottages and Mr.
Macfarlane's gave us very favourable impressions on this our first
entrance into the Highlands, and at this day the innocent merriment
of the girls, with their kindness to us, and the beautiful figure and
face of the elder, come to my mind whenever I think of the ferry-
house and waterfall of Loch Lomond, and I never think of the two
girls but the whole image of that romantic spot is before me, a living
image, as it will be to my dying day. The following poem2 was
written by William not long after our return from Scotland:—
We walked up the hill again, and, looking down the vale, had a
fine view of the lake and islands, resembling the views down
Windermere, though much less rich. Our walk to Dalmally was
pleasant: the vale makes a turn to the right, beyond the head of the
lake, and the village of Dalmally, which is, in fact, only a few huts,
the manse or minister's house, the chapel, and the inn, stands near
the river, which flows into the head of the lake. The whole vale is
very pleasing, the lower part of the hill-sides being sprinkled with
thatched cottages, cultivated ground in small patches near them,
which evidently belonged to the cottages.
We were overtaken by a gentleman who rode on a beautiful white
pony, like Lilly, and was followed by his servant, a Highland boy, on
another pony, a little creature, not much bigger than a large mastiff,
on which were slung a pair of crutches and a tartan plaid. The
gentleman entered into conversation with us, and on our telling him
that we were going to Glen Coe, he advised us, instead of
proceeding directly to Tyndrum, the next stage, to go round by the
outlet of Loch Awe to Loch Etive, and thence to Glen Coe. We were
glad to change our plan, for we wanted much to see more of Loch
Awe, and he told us that the whole of the way by Loch Etive was
pleasant, and the road to Tyndrum as dreary as possible; indeed, we
could see it at that time several miles before us upon the side of a
bleak mountain; and he said that there was nothing but moors and
mountains all the way. We reached the inn a little before sunset,
ordered supper, and I walked out. Crossed a bridge to look more
nearly at the parsonage-house and the chapel, which stands upon a
bank close to the river, a pretty stream overhung in some parts by
trees. The vale is very pleasing; but, like all the other Scotch vales
we had yet seen, it told of its kinship with the mountains and of
poverty or some neglect on the part of man.
A stately speech,
Such as grave livers do in Scotland use.11
ebookbell.com