Tải bản đầy đủ (.pdf) (769 trang)

Matlab image processing toolbox user's guide (copyright mathworks)

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (19.19 MB, 769 trang )

Computation
Visualization
Programming
For Use with MATLAB
®
Image Processing
Toolbox
User’s Guide
Version 3
How to Contact The MathWorks:
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
Technical support
Product enhancement suggestions
Bug reports
Documentation error reports
Order status, license renewals, passcodes
Sales, pricing, and general information
508-647-7000 Phone
508-647-7001 Fax
The MathWorks, Inc. Mail
3AppleHillDrive
Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
Image Processing Toolbox User’s Guide
 COPYRIGHT 1993 - 2001 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or repro-
duced in any form without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by
or for the federal government of the United States. By accepting delivery of the Program, the government


hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR
Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part
252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertain
to the government’s use and disclosure of the Program and Documentation, and shall supersede any
conflicting contractual terms or conditions. If this license fails to meet the government’s minimum needs or
is inconsistent in any respect with federal procurement law, the government agrees to return the Program
and Documentation, unused, to MathWorks.
MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and
Target Language Compiler is a trademark of The MathWorks, Inc.
Other product or brand names are trademarks or registered trademarks of their respective holders.
Printing History: August 1993 First printing Version 1
May 1997 Second printing Version 2
January 1998 Revised for Version 2.1 (Online only)
January 1999 Revised for Version 2.2 (Release 11) (Online only)
September 2000 Revised for Version 2.2.2 (Release 12) (Online only)
April 2001 Third Printing Version 3.0
Image Credits
moon Copyright Michael Myers. Used with permission.
cameraman Copyright Massachusetts Institute of Technology. Used with
permission.
trees Trees with a View, watercolor and ink on paper, copyright
Susan Cohen. Used with permission.
forest Photograph of Carmanah Ancient Forest, British Columbia,
Canada, courtesy of Susan Cohen.
circuit Micrograph of 16-bit A/D converter circuit, courtesy of Steve
Decker and Shujaat Nadeem, MIT, 1993.
m83 M83 spiral galaxy astronomical image courtesy of
Anglo-Australian Observatory, photography by David Malin.
cell Cancer cellfrom a rat’s prostate, courtesy of Alan W. Partin,
M.D., Ph.D., Johns Hopkins University School of Medicine.

LAN files Permission to use Landsat™ data sets provided by Space
Imaging, LLC, Denver, Colorado.
concordorthophoto and
westconcordorthophoto
Orthoregistered photographs courtesy of Massachusetts Exec-
utive Office of Environmental Affairs, MassGIS.
concordaerial and
westconcordaerial
Visible color aerial photographs courtesy of mPower3/Emerge.
alumgrns
bacteria
blood1
bonemarr
circles
circlesm
debye1
enamel
flowers
ic
lily
ngc4024l
ngc4024m
ngc4024s
rice
saturn
shot1
testpat1
testpat2
text
tire

Copyright J. C. Russ, The Image Processing Handbook, Second Edition,
1994, CRC Press, Boca Raton, ISBN 0-8493-2516-1. Used with permission.
vi
Contents
Getting Started
Preface
What Is the Image Processing Toolbox? xxv
R12 Related Products List xxvi
Configuration Notes xxviii
About This Manual xxix
WordsYouNeedtoKnow xxx
Typographical Conventions xxxi
Image Processing Demos xxxiii
MATLAB Newsgroup xxxvii
1
Getting Started
Overview 1-2
Exercise 1 — Some Basic Topics 1-3
1.ReadandDisplayanImage 1-3
2.ChecktheImageinMemory 1-3
3.PerformHistogramEqualization 1-4
4.WritetheImage 1-7
5.ChecktheContentsoftheNewlyWrittenFile 1-8
vii Contents
Exercise 2 — Advanced Topics 1-10
1.ReadandDisplayanImage 1-10
2. Use Morphological Opening to Estimate the Background . . 1-10
3. Display the Background Approximation as a Surface . . . . . 1-11

4. Subtract the Background Image from the Original Image . 1-13
5.AdjusttheImageContrast 1-14
6.ApplyThresholdingtotheImage 1-15
7. Determining the Number of Objects in the Image . . . . . . . . 1-16
8.ExamineanObject 1-19
9.MeasureObjectPropertiesintheImage 1-20
10. Compute Statistical Properties of Objects in the Image . . 1-22
Where to Go from Here 1-25
OnlineHelp 1-25
ToolboxDemos 1-25
Using the Image Processing Toolbox
2
Introduction
Overview 2-2
WordsYouNeedtoKnow 2-2
Images in MATLAB and the Image Processing Toolbox 2-4
StorageClassesintheToolbox 2-4
Image Types in the Toolbox 2-5
IndexedImages 2-5
IntensityImages 2-7
BinaryImages 2-8
RGBImages 2-9
MultiframeImageArrays 2-12
Summary of Image Types and Numeric Classes 2-13
ConvertingImageTypes 2-14
viii
Working with Image Data 2-17
ReadingaGraphicsImage 2-18
WritingaGraphicsImage 2-19
QueryingaGraphicsFile 2-20

ConvertingImageStorageClasses 2-21
ConvertingGraphicsFileFormats 2-22
Image Arithmetic 2-23
Summary of Image Arithmetic Functions . . . . . 2-24
ImageArithmeticTruncationRules 2-24
AddingImages 2-25
SubtractingImages 2-26
MultiplyingImages 2-28
DividingImages 2-29
NestingCallstoImageArithmeticFunctions 2-30
Coordinate Systems 2-31
PixelCoordinates 2-31
SpatialCoordinates 2-32
3
Displaying and Printing Images
Overview 3-2
WordsYouNeedtoKnow 3-2
Displaying Images with imshow 3-3
DisplayingIndexedImages 3-3
DisplayingIntensityImages 3-4
DisplayingBinaryImages 3-6
DisplayingRGBImages 3-11
DisplayingImagesDirectlyfromDisk 3-13
Special Display Techniques 3-14
AddingaColorbar 3-14
DisplayingMultiframeImages 3-15
DisplayingMultipleImages 3-19
ix Contents
SettingthePreferencesforimshow 3-24
ZoominginonaRegionofanImage 3-26

TextureMapping 3-28
Printing Images 3-29
Troubleshooting 3-30
4
Spatial Transformations
Overview 4-2
WordsYouNeedtoKnow 4-2
Interpolation 4-4
ImageTypes 4-5
Image Resizing 4-6
Image Rotation 4-8
Image Cropping 4-9
Performing General Spatial Transformations 4-11
SpecifyingtheTransformationType 4-11
PerformingtheTransformation 4-13
AdvancedSpatialTransformationTechniques 4-14
5
Image Registration
Overview 5-2
WordsYouNeedtoKnow 5-3
x
Registering an Image 5-5
Example:RegisteringtoaDigitalOrthophoto 5-6
Types of Supported Transformations 5-13
Selecting Control Points 5-15
UsingtheControlPointSelectionTool 5-15
StartingtheControlPointSelectionTool 5-16
ViewingtheImages 5-18
SpecifyingMatchingControlPointPairs 5-22
SavingControlPoints 5-29

Using Correlation to Improve Control Points 5-32
6
Neighborhood and Block Operations
Overview 6-2
WordsYouNeedtoKnow 6-2
TypesofBlockProcessingOperations 6-3
Sliding Neighborhood Operations 6-4
PaddingofBorders 6-5
LinearandNonlinearFiltering 6-5
Distinct Block Operations 6-8
Overlap 6-9
Column Processing 6-11
SlidingNeighborhoods 6-11
DistinctBlocks 6-12
xi Contents
7
Linear Filtering and Filter Design
Overview 7-2
WordsYouNeedtoKnow 7-2
Linear Filtering 7-4
Convolution 7-4
Correlation 7-6
FilteringUsingimfilter 7-7
UsingPredefinedFilterTypes 7-14
Filter Design 7-16
FIRFilters 7-16
FrequencyTransformationMethod 7-17
FrequencySamplingMethod 7-18
WindowingMethod 7-19
Creating the Desired Frequency Response Matrix . . . . . . . . . 7-20

ComputingtheFrequencyResponseofaFilter 7-21
8
Transforms
Overview 8-2
WordsYouNeedtoKnow 8-2
Fourier Transform 8-4
DefinitionofFourierTransform 8-4
TheDiscreteFourierTransform 8-9
Applications 8-12
Discrete Cosine Transform 8-17
TheDCTTransformMatrix 8-18
TheDCTandImageCompression 8-19
Radon Transform 8-21
UsingtheRadonTransformtoDetectLines 8-25
xii
TheInverseRadonTransform 8-27
9
Morphological Operations
Overview 9-2
WordsYouNeedtoKnow 9-2
Dilation and Erosion 9-5
Understanding Dilation and Erosion . . . . . . . . . 9-5
StructuringElements 9-8
DilatinganImage 9-12
ErodinganImage 9-13
Combining Dilation and Erosion . . . . . . . . . . . . . 9-15
Dilation-andErosion-BasedFunctions 9-17
Morphological Reconstruction 9-20
MarkerandMask 9-20
PixelConnectivity 9-24

Flood-FillOperations 9-27
FindingPeaksandValleys 9-30
Distance Transform 9-39
Example: Marker-Controlled Watershed Segmentation 9-42
Step1:ReadinImages 9-42
Step2:CreatetheStructuringElement 9-43
Step3:EnhancetheImageContrast 9-43
Step4:ExaggeratetheGapsBetweenObjects 9-44
Step5:ConvertObjectsofInterest 9-45
Step 6: Detect Intensity Valleys . . . . . . . . . . . . . 9-46
Step7:WatershedSegmentation 9-47
Step8:ExtractFeaturesfromLabelMatrix 9-48
Objects, Regions, and Feature Measurement 9-50
Connected-ComponentLabeling 9-50
SelectingObjectsinaBinaryImage 9-52
xiii Contents
FindingtheAreaofBinaryImages 9-52
FindingtheEulerNumberofaBinaryImage 9-53
Lookup Table Operations 9-54
10
Analyzing and Enhancing Images
Overview 10-2
WordsYouNeedtoKnow 10-2
Pixel Values and Statistics 10-4
PixelSelection 10-4
IntensityProfile 10-5
ImageContours 10-9
ImageHistogram 10-9
Summary Statistics . . . . . . . 10-10
RegionPropertyMeasurement 10-10

Image Analysis 10-11
EdgeDetection 10-11
QuadtreeDecomposition 10-12
Image Enhancement 10-15
IntensityAdjustment 10-15
NoiseRemoval 10-21
11
Region-Based Processing
Overview 11-2
WordsYouNeedtoKnow 11-2
Specifying a Region of Interest 11-4
xiv
SelectingaPolygon 11-4
OtherSelectionMethods 11-5
Filtering a Region 11-7
Filling a Region 11-9
12
Image Deblurring
Overview 12-2
WordsYouNeedtoKnow 12-2
Understanding Deblurring 12-3
CausesofBlurring 12-3
DeblurringModel 12-3
Using the Deblurring Functions 12-5
DeblurringwiththeWienerFilter 12-6
DeblurringwithaRegularizedFilter 12-8
DeblurringwiththeLucy-RichardsonAlgorithm 12-10
CreatingYourOwnDeblurringFunctions 12-12
Avoiding Ringing in Deblurred Images 12-13
13

Color
Overview 13-2
WordsYouNeedtoKnow 13-2
Working with Different Screen Bit Depths 13-4
DeterminingYourSystemsScreenBitDepth 13-4
ChoosingaScreenBitDepth 13-5
xv Contents
Reducing the Number of Colors in an Image 13-7
Usingrgb2ind 13-8
Usingimapprox 13-13
Dithering 13-14
Converting to Other Color Spaces 13-16
NTSCColorSpace 13-16
YCbCrColorSpace 13-17
HSVColorSpace 13-17
Reference
14
Reference
Functions by Category 14-2
applylut 14-20
bestblk 14-22
blkproc 14-23
brighten 14-26
bwarea 14-27
bwareaopen 14-29
bwdist 14-32
bweuler 14-38
bwfill 14-40
bwhitmiss 14-43
bwlabel 14-45

bwlabeln 14-48
bwmorph 14-51
bwpack 14-55
bwperim 14-57
bwselect 14-59
bwulterode 14-61
bwunpack 14-63
checkerboard 14-64
xvi
circshift 14-66
cmpermute 14-67
cmunique 14-68
col2im 14-69
colfilt 14-70
colorbar 14-72
conndef 14-74
conv2 14-76
convmtx2 14-78
convn 14-79
corr2 14-80
cp2tform 14-81
cpcorr 14-85
cpselect 14-87
cpstruct2pairs 14-88
dct2 14-89
dctmtx 14-92
deconvlucy 14-93
deconvreg 14-96
deconvwnr 14-98
dicominfo 14-100

dicomread 14-101
dilate 14-104
dither 14-106
double 14-107
edge 14-108
edgetaper 14-113
erode 14-114
fft2 14-116
fftn 14-118
fftshift 14-119
filter2 14-120
findbounds 14-122
fliptform 14-123
freqspace 14-124
freqz2 14-125
fsamp2 14-127
fspecial 14-130
ftrans2 14-135
fwind1 14-138
xvii Contents
fwind2 14-142
getheight 14-146
getimage 14-147
getneighbors 14-149
getnhood 14-150
getsequence 14-151
gray2ind 14-152
grayslice 14-153
graythresh 14-154
histeq 14-155

hsv2rgb 14-158
idct2 14-159
ifft2 14-160
ifftn 14-161
im2bw 14-162
im2col 14-164
im2double 14-165
im2mis 14-166
im2uint8 14-167
im2uint16 14-168
imabsdiff 14-169
imadd 14-170
imadjust 14-171
imapprox 14-174
imbothat 14-175
imclearborder 14-177
imclose 14-180
imcomplement 14-184
imcontour 14-186
imcrop 14-188
imdilate . . . . 14-191
imdivide 14-195
imerode 14-196
imextendedmax 14-199
imextendedmin 14-201
imfeature 14-203
imfill 14-209
imfilter 14-212
imfinfo 14-215
imhist 14-218

xviii
imhmax . . . . 14-220
imhmin . . . . 14-222
imimposemin 14-224
imlincomb 14-228
immovie 14-230
immultiply . 14-231
imnoise 14-232
imopen 14-234
impixel 14-237
improfile 14-240
imread 14-243
imreconstruct 14-249
imregionalmax 14-251
imregionalmin 14-253
imresize 14-255
imrotate 14-257
imshow 14-259
imsubtract 14-261
imtophat 14-262
imtransform 14-264
imwrite 14-270
ind2gray 14-277
ind2rgb 14-278
iptgetpref 14-279
iptsetpref 14-280
iradon 14-282
isbw 14-285
isflat 14-286
isgray 14-287

isind 14-288
isrgb 14-289
makelut 14-290
makeresampler 14-292
maketform 14-296
mat2gray 14-299
mean2 14-300
medfilt2 14-301
montage 14-303
nlfilter 14-305
normxcorr2 14-306
xix Contents
ntsc2rgb 14-307
ordfilt2 14-308
otf2psf 14-310
padarray 14-311
phantom 14-314
pixval 14-317
psf2otf 14-318
qtdecomp 14-319
qtgetblk 14-322
qtsetblk 14-324
radon 14-325
reflect 14-327
regionprops 14-328
rgb2gray 14-334
rgb2hsv 14-335
rgb2ind 14-336
rgb2ntsc 14-338
rgb2ycbcr 14-339

rgbplot 14-340
roicolor 14-341
roifill 14-342
roifilt2 14-344
roipoly 14-346
std2 14-348
strel 14-349
stretchlim 14-355
subimage 14-357
tformarray 14-359
tformfwd 14-363
tforminv 14-364
translate 14-365
truesize 14-366
uint8 14-367
uint16 14-369
warp 14-371
watershed 14-373
wiener2 14-376
ycbcr2rgb 14-378
zoom 14-379
xx
A
Working with Function Functions
Passing a Function Handle to a Function Function . . . . . . . . . A-3
PassinganInlineObjecttoaFunctionFunction A-4
PassingaStringtoaFunctionFunction A-4
xxi Contents
Preface
What Is the Image Processing Toolbox? xii

R12 Related Products List xiii
Configuration Notes xv
About This Manual xvi
WordsYouNeedtoKnow xvii
Typographical Conventions xviii
Image Processing Demos xx
MATLAB Newsgroup xxiv
Preface
xxv
What Is the Image Processing Toolbox?
The Image Processing Toolbox is a collection of functions that extend the
capability of the MATLAB
®
numeric computing environment. The toolbox
supports a wide range of image processing operations, including:
• Spatial image transformations
• Morphological operations
• Neighborhood and block operations
• Linear filtering and filter design
• Transforms
• Image analysis and enhancement
• Image registration
• Deblurring
• Region of interest operations
Many of the toolbox functions are MATLAB M-files, 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 Image Processing Toolbox by writing
your own M-files, or by using the toolbox in combination with other toolboxes,

such as the Signal Processing Toolbox and the Wavelet Toolbox.
For a list of the new features in version 3.0, see the Release Notes.
R12 Related Products List
xxvi
R12 Related Products List
The Image Processing Toolbox requires MATLAB 6.0 (Release 12).
Additionally, The MathWorks provides several products that are especially
relevant to the kinds of tasks you can perform with the Image Processing
Toolbox.
For more information about any of these products, see either:
• The online documentation for that product, if it is installed or if you are
reading the documentation from the CD
• The MathWorks Web site, at
www.mathworks.com; see the “products” section
Note The toolboxes listed below all include functions that extend MATLAB’s
capabilities. The blocksets all include blocks that extend Simulink’s
capabilities.
.
Product Description
DSP Blockset Simulink block libraries for the design,
simulation, and prototyping of digital signal
processing systems
Mapping Toolbox Tool for analyzing and displaying
geographically based information from within
MATLAB
MATLAB Integrated technical computing environment
that combines numeric computation, advanced
graphics and visualization, and a high-level
programming language
Preface

xxvii
Signal Processing
Toolbox
Tool for algorithm development, signal and
linear system analysis, and time-series data
modeling
Wavelet Toolbox Tool for signal and image analysis,
compression, and de-noising
Product Description

×