0% found this document useful (0 votes)
3 views

Matlab Image Processing Toolbox Documentation pdf download

The document provides comprehensive information on the MATLAB Image Processing Toolbox, including user guides, features, and related products. It covers various topics such as image types, processing techniques, and batch processing methods. Additionally, it includes contact information for MathWorks and details about software licensing and trademarks.

Uploaded by

fahmimeleoyc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Matlab Image Processing Toolbox Documentation pdf download

The document provides comprehensive information on the MATLAB Image Processing Toolbox, including user guides, features, and related products. It covers various topics such as image types, processing techniques, and batch processing methods. Additionally, it includes contact information for MathWorks and details about software licensing and trademarks.

Uploaded by

fahmimeleoyc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

Matlab Image Processing Toolbox Documentation

download

https://ebookbell.com/product/matlab-image-processing-toolbox-
documentation-6741908

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Matlab Image Processing Toolbox Users Guide Unknown

https://ebookbell.com/product/matlab-image-processing-toolbox-users-
guide-unknown-48950730

Matlab Image Processing Toolbox Users Guide R2021a Mathwork

https://ebookbell.com/product/matlab-image-processing-toolbox-users-
guide-r2021a-mathwork-36128440

Matlab Image Processing Toolbox Users Guide R2020a The Mathworks

https://ebookbell.com/product/matlab-image-processing-toolbox-users-
guide-r2020a-the-mathworks-11236248

Biosignal And Medical Image Processing Matlabbased Applications Signal


Processing And Communications 1st Edition John L Semmlow

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

Digital Image Processing Using Matlab 4th Edition Rafael C Gonzalez

https://ebookbell.com/product/digital-image-processing-using-
matlab-4th-edition-rafael-c-gonzalez-34385212

Digital Image Processing Using Matlab 2nd Edition Rafael C Gonzalez

https://ebookbell.com/product/digital-image-processing-using-
matlab-2nd-edition-rafael-c-gonzalez-4072380

Digital Image Processing Using Matlab Rafael C Gonzalez Richard Ewoods

https://ebookbell.com/product/digital-image-processing-using-matlab-
rafael-c-gonzalez-richard-ewoods-50195688

Digital Image Processing Using Matlab 2nd Edition Rafael C Gonzalez

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

Latest news: www.mathworks.com

Sales and services: www.mathworks.com/sales_and_services

User community: www.mathworks.com/matlabcentral

Technical support: www.mathworks.com/support/contact_us

Phone: 508-647-7000

The MathWorks, Inc.


3 Apple Hill Drive
Natick, MA 01760-2098
Image Processing Toolbox™ User's Guide
© COPYRIGHT 1993–2016 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
reproduced 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, for, or through the federal government of the United States. By accepting delivery of the Program
or Documentation, the government hereby agrees that this software or documentation qualifies as
commercial computer software or commercial computer software documentation as such terms are used
or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and
conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and
govern the use, modification, reproduction, release, performance, display, and disclosure of the Program
and Documentation by the federal government (or other entity acquiring for or through the federal
government) and shall supersede any conflicting contractual terms or conditions. If this License fails
to meet the government's needs or is inconsistent in any respect with federal procurement law, the
government agrees to return the Program and Documentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
August 1993 First printing Version 1
May 1997 Second printing Version 2
April 2001 Third printing Revised for Version 3.0
June 2001 Online only Revised for Version 3.1 (Release 12.1)
July 2002 Online only Revised for Version 3.2 (Release 13)
May 2003 Fourth printing Revised for Version 4.0 (Release 13.0.1)
September 2003 Online only Revised for Version 4.1 (Release 13.SP1)
June 2004 Online only Revised for Version 4.2 (Release 14)
August 2004 Online only Revised for Version 5.0 (Release 14+)
October 2004 Fifth printing Revised for Version 5.0.1 (Release 14SP1)
March 2005 Online only Revised for Version 5.0.2 (Release 14SP2)
September 2005 Online only Revised for Version 5.1 (Release 14SP3)
March 2006 Online only Revised for Version 5.2 (Release 2006a)
September 2006 Online only Revised for Version 5.3 (Release 2006b)
March 2007 Online only Revised for Version 5.4 (Release 2007a)
September 2007 Online only Revised for Version 6.0 (Release 2007b)
March 2008 Online only Revised for Version 6.1 (Release 2008a)
October 2008 Online only Revised for Version 6.2 (Release 2008b)
March 2009 Online only Revised for Version 6.3 (Release 2009a)
September 2009 Online only Revised for Version 6.4 (Release 2009b)
March 2010 Online only Revised for Version 7.0 (Release 2010a)
September 2010 Online only Revised for Version 7.1 (Release 2010b)
April 2011 Online only Revised for Version 7.2 (Release 2011a)
September 2011 Online only Revised for Version 7.3 (Release 2011b)
March 2012 Online only Revised for Version 8.0 (Release 2012a)
September 2012 Online only Revised for Version 8.1 (Release 2012b)
March 2013 Online only Revised for Version 8.2 (Release 2013a)
September 2013 Online only Revised for Version 8.3 (Release 2013b)
March 2014 Online only Revised for Version 9.0 (Release 2014a)
October 2014 Online only Revised for Version 9.1 (Release 2014b)
March 2015 Online only Revised for Version 9.2 (Release 2015a)
September 2015 Online only Revised for Version 9.3 (Release 2015b)
March 2016 Online only Revised for Version 9.4 (Release 2016a)
Contents

Getting Started
1
Image Processing Toolbox Product Description . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

Configuration Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

Related Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4

Compilability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

Basic Image Import, Processing, and Export . . . . . . . . . . . . . 1-6

Basic Image Enhancement and Analysis Techniques . . . . . 1-12

Getting Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23


Product Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23
Image Processing Examples . . . . . . . . . . . . . . . . . . . . . . . . 1-23
MATLAB Newsgroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-25

Introduction
2
Images in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2

Expressing Image Locations . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3


Pixel Indices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Spatial Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4

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

Converting Between Image Types . . . . . . . . . . . . . . . . . . . . . 2-17

Converting Between Image Classes . . . . . . . . . . . . . . . . . . . 2-19


Overview of Image Class Conversions . . . . . . . . . . . . . . . . . 2-19
Losing Information in Conversions . . . . . . . . . . . . . . . . . . . 2-19
Converting Indexed Images . . . . . . . . . . . . . . . . . . . . . . . . . 2-19

Process Multi-Frame Image Arrays . . . . . . . . . . . . . . . . . . . . 2-21

Perform an Operation on a Sequence of Images . . . . . . . . . 2-22

Batch Processing Using the Image Batch Processor App . . 2-23


Open Image Batch Processor App . . . . . . . . . . . . . . . . . . . . 2-23
Load Images into the Image Batch Processor App . . . . . . . . 2-24
Specify the Batch Processing Function . . . . . . . . . . . . . . . . 2-27
Perform the Operation on the Images . . . . . . . . . . . . . . . . . 2-30
Obtain the Results of the Batch Processing Operation . . . . . 2-34

Process Large Set of Images Using MapReduce Framework


and Hadoop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39
Download Sample Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-39
View Image Files and Test Algorithm . . . . . . . . . . . . . . . . . 2-40
Testing Your MapReduce Framework Locally: Data
Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42
Testing Your MapReduce Framework Locally: Running your
algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-45
Running Your MapReduce Framework on a Hadoop Cluster 2-49

What Is an Image Sequence? . . . . . . . . . . . . . . . . . . . . . . . . . 2-54

Toolbox Functions That Work with Image Sequences . . . . 2-55

Overview of Image Arithmetic Functions . . . . . . . . . . . . . . . 2-58

Image Arithmetic Saturation Rules . . . . . . . . . . . . . . . . . . . 2-59

vi Contents
Nesting Calls to Image Arithmetic Functions . . . . . . . . . . . 2-60

Reading and Writing Image Data


3
Getting Information About Graphics Files . . . . . . . . . . . . . . . 3-2

Read Image Data into the Workspace . . . . . . . . . . . . . . . . . . . 3-3

Read Multiple Images from a Single Graphics File . . . . . . . . 3-5

Read and Write 1-Bit Binary Images . . . . . . . . . . . . . . . . . . . 3-6

Determine Storage Class of Output Files . . . . . . . . . . . . . . . . 3-7

Write Image Data to File in Graphics Format . . . . . . . . . . . . 3-8

Convert Between Graphics File Formats . . . . . . . . . . . . . . . 3-10

DICOM Support in the Image Processing Toolbox . . . . . . . 3-11

Read Metadata from DICOM Files . . . . . . . . . . . . . . . . . . . . 3-12


Private DICOM Metadata . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12
Create Your Own Copy of DICOM Dictionary . . . . . . . . . . . 3-13

Read Image Data from DICOM Files . . . . . . . . . . . . . . . . . . . 3-14


View DICOM Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-14

Write Image Data to DICOM Files . . . . . . . . . . . . . . . . . . . . . 3-15


Include Metadata with Image Data . . . . . . . . . . . . . . . . . . . 3-15

Explicit Versus Implicit VR Attributes . . . . . . . . . . . . . . . . . 3-17

Remove Confidential Information from a DICOM File . . . . 3-18

Create New DICOM Series . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19

Mayo Analyze 7.5 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-22

vii
Interfile Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23

High Dynamic Range Images: An Overview . . . . . . . . . . . . . 3-24

Create High Dynamic Range Image . . . . . . . . . . . . . . . . . . . 3-25

Read High Dynamic Range Image . . . . . . . . . . . . . . . . . . . . . 3-26

Display High Dynamic Range Image . . . . . . . . . . . . . . . . . . . 3-27

Write High Dynamic Range Image to File . . . . . . . . . . . . . . 3-29

Displaying and Exploring Images


4
Image Display and Exploration Overview . . . . . . . . . . . . . . . 4-2

Displaying Images Using the imshow Function . . . . . . . . . . . 4-4


Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Specifying the Initial Image Magnification . . . . . . . . . . . . . . 4-6
Controlling the Appearance of the Figure . . . . . . . . . . . . . . . 4-7

Display Each Image in a Separate Figure . . . . . . . . . . . . . . . 4-9

Display Multiple Images in the Same Figure . . . . . . . . . . . . 4-10


Dividing a Figure Window into Multiple Display Regions . . 4-10
Using the subimage Function to Display Multiple Images . . 4-12

Explore Images with the Image Viewer App . . . . . . . . . . . . 4-14


Open the Image Viewer App . . . . . . . . . . . . . . . . . . . . . . . . 4-15
Initial Image Magnification in the Image Viewer App . . . . . 4-17
Choose the Colormap Used by the Image Viewer App . . . . . 4-18
Import Image Data from the Workspace into the Image Viewer
App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20
Export Image Data from the Image Viewer App to the
Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
Save Image Data Displayed in Image Viewer . . . . . . . . . . . 4-21
Close the Image Viewer App . . . . . . . . . . . . . . . . . . . . . . . . 4-23
Print Images Displayed in Image Viewer App . . . . . . . . . . . 4-23

viii Contents
Reduced Resolution Data Set for Very Large Images . . . . . 4-24

Create a Reduced Resolution File . . . . . . . . . . . . . . . . . . . . . 4-25

Open a Reduced Resolution File . . . . . . . . . . . . . . . . . . . . . . 4-26

Explore Images with the Image Viewer App . . . . . . . . . . . . 4-27


Explore Images Using the Overview Tool . . . . . . . . . . . . . . 4-27
Pan Images Displayed in Image Viewer App . . . . . . . . . . . . 4-30
Zoom Images in the Image Viewer App . . . . . . . . . . . . . . . . 4-31
Specify Image Magnification in Image Viewer . . . . . . . . . . . 4-31

Get Pixel Information in Image Viewer App . . . . . . . . . . . . 4-34


Determine Individual Pixel Values in Image Viewer . . . . . . 4-34
Determine Pixel Values in an Image Region . . . . . . . . . . . . 4-36
Determine Image Display Range in Image Viewer . . . . . . . . 4-39

Measure Distance Between Pixels in Image Viewer . . . . . . 4-42


Determine Distance Between Pixels Using Distance Tool . . 4-42
Export Endpoint and Distance Data . . . . . . . . . . . . . . . . . . 4-44
Customize the Appearance of the Distance Tool . . . . . . . . . 4-44

Get Image Information in Image Viewer App . . . . . . . . . . . 4-46

Adjust Image Contrast In Image Viewer App . . . . . . . . . . . . 4-48


Open the Adjust Contrast Tool . . . . . . . . . . . . . . . . . . . . . . 4-48
Adjust Image Contrast Using the Histogram Window . . . . . 4-50
Adjust Image Contrast Using Window/Level Tool . . . . . . . . 4-51
Make Contrast Adjustments Permanent . . . . . . . . . . . . . . . 4-54

Understanding Contrast Adjustment . . . . . . . . . . . . . . . . . . 4-56

Crop Image Using Image Viewer App . . . . . . . . . . . . . . . . . . 4-58

View Image Sequences in Video Viewer App . . . . . . . . . . . . 4-63


View MRI Sequence Using Video Viewer App . . . . . . . . . . . 4-63
Configure Video Viewer App . . . . . . . . . . . . . . . . . . . . . . . . 4-66
Specifying the Frame Rate . . . . . . . . . . . . . . . . . . . . . . . . . 4-69
Specify Color Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-70
Get Information about an Image Sequence . . . . . . . . . . . . . 4-70

View Image Sequence as Montage . . . . . . . . . . . . . . . . . . . . . 4-72

ix
Convert Multiframe Image to Movie . . . . . . . . . . . . . . . . . . . 4-74

Display Different Image Types . . . . . . . . . . . . . . . . . . . . . . . 4-75


Display Indexed Images . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-75
Display Grayscale Images . . . . . . . . . . . . . . . . . . . . . . . . . . 4-76
Display Binary Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-77
Display Truecolor Images . . . . . . . . . . . . . . . . . . . . . . . . . . 4-79

Add Colorbar to Displayed Image . . . . . . . . . . . . . . . . . . . . . 4-81

Print Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-83


Handle Graphics Properties That Impact Printing . . . . . . . 4-83

Image Processing Toolbox Preferences . . . . . . . . . . . . . . . . 4-84


Retrieve Values of Toolbox Preferences . . . . . . . . . . . . . . . . 4-84
Set Values of Toolbox Preferences . . . . . . . . . . . . . . . . . . . . 4-85

Building GUIs with Modular Tools


5
Modular Interactive Tools for Building Custom Image
Processing Apps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

Interactive Modular Tool Workflow . . . . . . . . . . . . . . . . . . . . 5-8


Display the Target Image in a Figure Window . . . . . . . . . . . 5-9
Associate Modular Tools with the Target Image . . . . . . . . . . 5-9
Associate Modular Tools with a Particular Target Image . . . 5-11
Get Handle to Target Image . . . . . . . . . . . . . . . . . . . . . . . . 5-13
Specify the Parent of a Modular Tool . . . . . . . . . . . . . . . . . 5-16
Position Modular Tools in a GUI . . . . . . . . . . . . . . . . . . . . . 5-20
Adding Navigation Aids to a GUI . . . . . . . . . . . . . . . . . . . . 5-22

Build App To Display Pixel Information . . . . . . . . . . . . . . . 5-26

Build App for Navigating Large Images . . . . . . . . . . . . . . . . 5-28

Customize Modular Tool Interactivity . . . . . . . . . . . . . . . . . 5-30

Build Image Comparison Tool . . . . . . . . . . . . . . . . . . . . . . . . 5-31

x Contents
Create Your Own Modular Tools . . . . . . . . . . . . . . . . . . . . . . 5-35

Create Angle Measurement Tool Using ROI Objects . . . . . . 5-37

Geometric Transformations
6
Resize an Image with imresize Function . . . . . . . . . . . . . . . . 6-2

Rotate an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8

Crop an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9

Translate an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11

2-D Geometric Transformation Process Overview . . . . . . . 6-14


Define Parameters of the Geometric Transformation . . . . . . 6-15
Perform the Geometric Transformation . . . . . . . . . . . . . . . . 6-18

Specify Fill Values in Geometric Transformation Output . 6-20

Understanding What Happens in Geometric


Transformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-23

Perform Simple 2-D Translation Transformation . . . . . . . . 6-24

N-Dimensional Spatial Transformations . . . . . . . . . . . . . . . . 6-28

Register Two Images Using Spatial Referencing to Enhance


Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-30

Image Registration
7
Image Registration Techniques . . . . . . . . . . . . . . . . . . . . . . . . 7-2

xi
Control Point Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4

Using cpselect in a Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6

Register an Aerial Photograph to a Digital Orthophoto . . . . 7-7

Geometric Transformation Types . . . . . . . . . . . . . . . . . . . . . 7-12

Control Point Selection Procedure . . . . . . . . . . . . . . . . . . . . 7-13

Start the Control Point Selection Tool . . . . . . . . . . . . . . . . . 7-15

Find Visual Elements Common to Both Images . . . . . . . . . . 7-17


Using Scroll Bars to View Other Parts of an Image . . . . . . . 7-17
Using the Detail Rectangle to Change the View . . . . . . . . . 7-17
Panning the Image Displayed in the Detail Window . . . . . . 7-19
Zooming In and Out on an Image . . . . . . . . . . . . . . . . . . . . 7-19
Specifying the Magnification of the Images . . . . . . . . . . . . . 7-20
Locking the Relative Magnification of the Moving and Fixed
Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21

Select Matching Control Point Pairs . . . . . . . . . . . . . . . . . . 7-22


Picking Control Point Pairs Manually . . . . . . . . . . . . . . . . . 7-22
Using Control Point Prediction . . . . . . . . . . . . . . . . . . . . . . 7-24
Moving Control Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27
Deleting Control Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-28

Export Control Points to the Workspace . . . . . . . . . . . . . . . 7-29

Save Control Point Selection Session . . . . . . . . . . . . . . . . . . 7-30

Use Cross-Correlation to Improve Control Point


Placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-31

Use Phase Correlation as Preprocessing Step in


Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-32

Intensity-Based Automatic Image Registration . . . . . . . . . . 7-38

Registering Multimodal MRI Images . . . . . . . . . . . . . . . . . . 7-40

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

Integral Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5

Filter Images Using imfilter . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7

How imfilter Handles Data Types . . . . . . . . . . . . . . . . . . . . . . 8-9

imfilter Boundary Padding Options . . . . . . . . . . . . . . . . . . . 8-11

Filter Images Using imfilter with Convolution . . . . . . . . . . 8-15

Filter Images Using Predefined Filters . . . . . . . . . . . . . . . . 8-16

Filter Multidimensional Images with imfilter . . . . . . . . . . . 8-19

What is Guided Image Filtering? . . . . . . . . . . . . . . . . . . . . . . 8-21

Perform Flash/No-flash Denoising with Guided Filter . . . . 8-22

Segment Thermographic Image after Edge-Preserving


Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-27

Apply Multiple Filters to Integral Image . . . . . . . . . . . . . . . 8-32

Reducing Noise in Image Gradients . . . . . . . . . . . . . . . . . . . 8-39

Designing Linear Filters in the Frequency Domain . . . . . . 8-47


Transform 1-D FIR Filter to 2-D FIR Filter . . . . . . . . . . . . 8-48
Frequency Sampling Method . . . . . . . . . . . . . . . . . . . . . . . . 8-51
Windowing Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-52
Creating the Desired Frequency Response Matrix . . . . . . . . 8-53
Computing the Frequency Response of a Filter . . . . . . . . . . 8-54

Two-Dimensional Finite Impulse Response (FIR) Filters . . 8-56

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

Discrete Cosine Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15


DCT Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15
The DCT Transform Matrix . . . . . . . . . . . . . . . . . . . . . . . . 9-17
Image Compression with the Discrete Cosine Transform . . . 9-17

Radon Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-21


Plot the Radon Transform of an Image . . . . . . . . . . . . . . . . 9-23
Viewing the Radon Transform as an Image . . . . . . . . . . . . . 9-26

Detect Lines Using the Radon Transform . . . . . . . . . . . . . . 9-28

The Inverse Radon Transformation . . . . . . . . . . . . . . . . . . . 9-31


Inverse Radon Transform Definition . . . . . . . . . . . . . . . . . . 9-31
Reconstructing an Image from Parallel Projection Data . . . . 9-33

Fan-Beam Projection Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-37


Image Reconstruction from Fan-Beam Projection Data . . . . 9-40
Reconstruct Image using Inverse Fanbeam Projection . . . . . 9-41

Morphological Operations
10
Morphological Dilation and Erosion . . . . . . . . . . . . . . . . . . . 10-2
Processing Pixels at Image Borders (Padding Behavior) . . . 10-3

Structuring Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5


Determine the Origin of a Structuring Element . . . . . . . . . 10-7
Structuring Element Decomposition . . . . . . . . . . . . . . . . . . 10-8

Dilate an Image Using imdilate . . . . . . . . . . . . . . . . . . . . . . 10-10

xiv Contents
Erode an Image Using imerode . . . . . . . . . . . . . . . . . . . . . . 10-12

Operations That Combine Dilation and Erosion . . . . . . . . 10-15


Morphological Opening . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15

Dilation- and Erosion-Based Functions . . . . . . . . . . . . . . . 10-17

Skeletonization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-18

Perimeter Determination . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-19

Understanding Morphological Reconstruction . . . . . . . . . 10-20


Understanding the Marker and Mask . . . . . . . . . . . . . . . . 10-22
Pixel Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-23
Finding Peaks and Valleys . . . . . . . . . . . . . . . . . . . . . . . . 10-26
Flood-Fill Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-33

Distance Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-37

Labeling and Measuring Objects in a Binary Image . . . . . 10-39


Understanding Connected-Component Labeling . . . . . . . . 10-39
Selecting Objects in a Binary Image . . . . . . . . . . . . . . . . . 10-41
Finding the Area of the Foreground of a Binary Image . . . 10-42
Finding the Euler Number of a Binary Image . . . . . . . . . . 10-42

Lookup Table Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-44


Creating a Lookup Table . . . . . . . . . . . . . . . . . . . . . . . . . . 10-44
Using a Lookup Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-44

Analyzing and Enhancing Images


11
Pixel Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3
Determine Values of Individual Pixels in Images . . . . . . . . 11-3

Intensity Profile of Images . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5


Create an Intensity Profile of an Image . . . . . . . . . . . . . . . 11-5
Create Intensity Profile of an RGB Image . . . . . . . . . . . . . . 11-6

xv
Contour Plot of Image Data . . . . . . . . . . . . . . . . . . . . . . . . . . 11-9
Create Contour Plot of Image Data . . . . . . . . . . . . . . . . . . . 11-9

Create Image Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11

Image Mean, Standard Deviation, and Correlation


Coefficient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-13

Edge Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-14


Detect Edges in Images . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-14

Boundary Tracing in Images . . . . . . . . . . . . . . . . . . . . . . . . 11-17


Trace Boundaries of Objects in Images . . . . . . . . . . . . . . . 11-17
Select First Step and Direction for Tracing . . . . . . . . . . . . 11-21

Hough Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-23


Detect Lines in Images Using Hough . . . . . . . . . . . . . . . . 11-23

Quadtree Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-29

Perform Quadtree Decomposition on an Image . . . . . . . . . 11-30

Texture Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-33

Detect Regions of Texture in Images . . . . . . . . . . . . . . . . . 11-35

Texture Analysis Using the Gray-Level Co-Occurrence Matrix


(GLCM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-37

Create a Gray-Level Co-Occurrence Matrix . . . . . . . . . . . . 11-38

Specify Offset Used in GLCM Calculation . . . . . . . . . . . . . 11-40

Derive Statistics from GLCM and Plot Correlation . . . . . . 11-41

Contrast Adjustment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-43

Adjust Image Intensity Values to Specified Range . . . . . . 11-44

Set Image Intensity Adjustment Limits Automatically . . . 11-46

xvi Contents
Gamma Correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-47
Specify Gamma when Adjusting Contrast . . . . . . . . . . . . . 11-47

Specify Adjustment Limits as Range . . . . . . . . . . . . . . . . . . 11-49


............................................. 11-49

Histogram Equalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-50


Adjust Intensity Values Using Histogram Equalization . . . 11-50
Plot Transformation Curve for Histogram Equalization . . . 11-52
Plot Transformation Curve for Histogram Equalization . . . 11-54

Adaptive Histogram Equalization . . . . . . . . . . . . . . . . . . . . 11-56


Adjust Contrast using Adaptive Histogram Equalization . . 11-56

Enhance Color Separation Using Decorrelation


Stretching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-58
Simple Decorrelation Stretching . . . . . . . . . . . . . . . . . . . . 11-58
Adding a Linear Contrast Stretch . . . . . . . . . . . . . . . . . . . 11-60

Apply Gaussian Smoothing Filters to Images . . . . . . . . . . 11-62

Noise Removal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-72


Remove Noise By Linear Filtering . . . . . . . . . . . . . . . . . . . 11-72
Remove Noise Using an Averaging Filter and a Median
Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-72
Remove Noise By Adaptive Filtering . . . . . . . . . . . . . . . . . 11-76

Image Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-78

Texture Segmentation Using Gabor Filters . . . . . . . . . . . . 11-79

Image Segmentation Using the Color Thresholder App . . 11-86


Open Image in Color Thresholder App . . . . . . . . . . . . . . . 11-86
Segment Image Using Color Selector . . . . . . . . . . . . . . . . . 11-91
Segment Image Using Color Component Controls . . . . . . . 11-94
Create an Image Mask . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-98

Acquire Live Images in the Color Thresholder App . . . . 11-104

Image Quality Metrics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-110


Obtain Local Structural Similarity Index . . . . . . . . . . . . 11-110
Compare Image Quality at Various Compression Levels . 11-112

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

Plot Land Classification with Color Features and


Superpixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-126

Image Region Properties . . . . . . . . . . . . . . . . . . . . . . . . . . 11-131

Calculate Region Properties Using Image Region


Analyzer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-132

Filter Images on Region Properties Using Image Region


Analyzer App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-140

ROI-Based Processing
12
ROI Processing in Image Processing Toolbox . . . . . . . . . . . 12-2

Create Binary Mask From Grayscale Image . . . . . . . . . . . . 12-3

Create Binary Mask Using an ROI Object . . . . . . . . . . . . . . 12-4

Create Binary Mask Without an Associated Image . . . . . . . 12-5

Create ROI Based on Color Values . . . . . . . . . . . . . . . . . . . . 12-6

Overview of ROI Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-7

Apply Filter to Region of Interest in an Image . . . . . . . . . . 12-8

Apply Custom Filter to Region of Interest in Image . . . . . 12-11

Fill Region of Interest in an Image . . . . . . . . . . . . . . . . . . . 12-14

xviii Contents
Image Deblurring
13
Image Deblurring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
Deblurring Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-4

Deblurring with the Wiener Filter . . . . . . . . . . . . . . . . . . . . 13-6


Refining the Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-6

Deblurring with a Regularized Filter . . . . . . . . . . . . . . . . . . 13-7


Refining the Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-8

Deblurring with the Lucy-Richardson Algorithm . . . . . . . . 13-9


Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-9
Reducing the Effect of Noise Amplification . . . . . . . . . . . . . 13-9
Accounting for Nonuniform Image Quality . . . . . . . . . . . . 13-10
Handling Camera Read-Out Noise . . . . . . . . . . . . . . . . . . 13-10
Handling Undersampled Images . . . . . . . . . . . . . . . . . . . . 13-10
Example: Using the deconvlucy Function to Deblur an
Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-11
Refining the Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-13

Deblurring with the Blind Deconvolution Algorithm . . . . 13-14


Deblur images using blind deconvolution . . . . . . . . . . . . . 13-14
Refining the Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-22

Creating Your Own Deblurring Functions . . . . . . . . . . . . . 13-24

Avoiding Ringing in Deblurred Images . . . . . . . . . . . . . . . 13-25

Color
14
Displaying Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2

Reducing the Number of Colors in an Image . . . . . . . . . . . . 14-4


Reducing Colors Using Color Approximation . . . . . . . . . . . . 14-4
Reducing Colors Using imapprox . . . . . . . . . . . . . . . . . . . . 14-9
Dithering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-10

xix
Convert from YIQ to RGB Color Space . . . . . . . . . . . . . . . . 14-12

Convert from YCbCr to RGB Color Space . . . . . . . . . . . . . 14-13

Convert from HSV to RGB Color Space . . . . . . . . . . . . . . . 14-14

Profile-Based Color Space Conversions . . . . . . . . . . . . . . . 14-17


Read ICC Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-17
Write ICC Profile Information to a File . . . . . . . . . . . . . . . 14-18
Convert RGB to CMYK Using ICC Profiles . . . . . . . . . . . . 14-18
What is Rendering Intent in Profile-Based Conversions? . . 14-20

Device-Independent Color Spaces . . . . . . . . . . . . . . . . . . . . 14-21


Convert Between Device-Independent Color Spaces . . . . . . 14-21
Color Space Data Encodings . . . . . . . . . . . . . . . . . . . . . . . 14-22

Understanding Color Spaces and Color Space Conversion 14-24

Determine if L*a*b* value is in RGB gamut . . . . . . . . . . . . 14-25

Neighborhood and Block Operations


15
Neighborhood or Block Processing: An Overview . . . . . . . . 15-2

Sliding Neighborhood Operations . . . . . . . . . . . . . . . . . . . . . 15-3


Determine the Center Pixel . . . . . . . . . . . . . . . . . . . . . . . . . 15-4
General Algorithm of Sliding Neighborhood Operations . . . . 15-4
Border Padding Behavior in Sliding Neighborhood
Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-4
Implementing Linear and Nonlinear Filtering as Sliding
Neighborhood Operations . . . . . . . . . . . . . . . . . . . . . . . . 15-5

Distinct Block Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-7


Implementing Block Processing Using the blockproc
Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-7
Applying Padding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-9

Block Size and Performance . . . . . . . . . . . . . . . . . . . . . . . . 15-11


TIFF Image Characteristics . . . . . . . . . . . . . . . . . . . . . . . 15-11

xx Contents
Choosing Block Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-11

Using Parallel Block Processing on Large Image Files . . . 15-14


What is Parallel Block Processing? . . . . . . . . . . . . . . . . . . 15-14
When to Use Parallel Block Processing . . . . . . . . . . . . . . . 15-14
How to Use Parallel Block Processing . . . . . . . . . . . . . . . . 15-15

Read and Write Data in Unsupported Formats Using


blockproc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-16
Learning More About the LAN File Format . . . . . . . . . . . 15-16
Parsing the Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-17
Reading the File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-18
Examining the LanAdapter Class . . . . . . . . . . . . . . . . . . . 15-18
Using the LanAdapter Class with blockproc . . . . . . . . . . . 15-23

Using Columnwise Processing to Speed Up Sliding


Neighborhood or Distinct Block Operations . . . . . . . . . 15-24
Using Column Processing with Sliding Neighborhood
Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-24
Using Column Processing with Distinct Block Operations . 15-25

Code Generation for Image Processing Toolbox


Functions
16
Code Generation for Image Processing . . . . . . . . . . . . . . . . 16-2

List of Supported Functions with Usage Notes . . . . . . . . . . 16-3

Generate Code from Application Containing Image


Processing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-21
Setup Your Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-21
Generate Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-22

Understanding Code Generation with Image Processing


Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-37

xxi
GPU Computing with Image Processing Toolbox
Functions
17
Image Processing on a GPU . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2

List of Supported Functions with Limitations and Other


Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-4

Perform Thresholding and Morphological Operations on a


GPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-7

Perform Element-wise Operations on a GPU . . . . . . . . . . . 17-11

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 Product Description” on page 1-2


• “Configuration Notes” on page 1-3
• “Related Products” on page 1-4
• “Compilability” on page 1-5
• “Basic Image Import, Processing, and Export” on page 1-6
• “Basic Image Enhancement and Analysis Techniques” on page 1-12
• “Getting Help” on page 1-23
• “Acknowledgments” on page 1-25
1 Getting Started

Image Processing Toolbox Product Description


Perform image processing, analysis, and algorithm development

Image Processing Toolbox provides a comprehensive set of reference-standard


algorithms, functions, and apps for image processing, analysis, visualization, and
algorithm development. You can perform image analysis, image segmentation, image
enhancement, noise reduction, geometric transformations, and image registration. Many
toolbox functions support multicore processors, GPUs, and C-code generation.

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

Basic Image Import, Processing, and Export


This example shows how to read an image into the workspace, adjust the contrast in the
image, and then write the adjusted image to a file.

Step 1: Read and Display an Image

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

Step 2: Check How the Image Appears in the Workspace

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

Name Size Bytes Class Attributes

I 291x240 69840 uint8

1-7
1 Getting Started

Step 3: Improve Image Contrast

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

Step 4: Write the Adjusted Image to a Disk File

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');

Step 5: Check the Contents of the Newly Written File

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

Basic Image Enhancement and Analysis Techniques


This example shows how to enhance an image as a preprocessing step before analysis. In
this example, you correct the nonuniform background illumination and convert the image
into a binary image so that you can perform analysis of the image foreground objects.

Step 1: Read the Image into the Workspace

Read and display the grayscale image rice.png.

I = imread('rice.png');
imshow(I)

Step 2: Preprocess the Image to Enable Analysis

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));

View the background approximation image as a surface to see where illumination


varies. The surf command creates colored parametric surfaces that enable you to view
mathematical functions over a rectangular region. Because the surf function requires
data of class double, you first need to convert background using the double command.
The example uses indexing syntax to view only 1 out of 8 pixels in each direction;
otherwise, the surface plot would be too dense. The example also sets the scale of the
plot to better match the range of the uint8 data and reverses the y-axis of the display
to provide a better view of the data. (The pixels at the bottom of the image appear at the
front of the surface plot.) In the surface display, [0, 0] represents the origin, or upper-left
corner of the image. The highest part of the curve indicates that the highest pixel values
of background (and consequently rice.png ) occur near the middle rows of the image.
The lowest pixel values occur at the bottom of the image.

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

Use imadjust to increase the contrast of the processed image I2 by saturating 1% of


the data at both low and high intensities and by stretching the intensity values to fill the
uint8 dynamic range.

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

Step 3: Perform Analysis of Objects in the Image

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

View the rice grain that is labeled 50 in the image.

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 = regionprops(cc, 'basic')

graindata =

1-19
1 Getting Started

95x1 struct array with fields:

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];

Find the rice grain with the smallest area.

[min_area, idx] = min(grain_areas)


grain = false(size(bw));
grain(cc.PixelIdxList{idx}) = true;
imshow(grain);

min_area =

61

idx =

16

1-20
Basic Image Enhancement and Analysis Techniques

Using the hist command to create a histogram of rice grain areas.

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

Image Processing Examples


The Image Processing Toolbox software is supported by a full complement of example
applications. These are very useful as templates for your own end-user applications, or
for seeing how to use and combine your toolbox functions for powerful image analysis and
enhancement.

To view all the examples, call the iptdemos function. This displays an HTML page in
the MATLAB Help browser that lists all the examples.

The toolbox examples are located in the folder

1-23
1 Getting Started

matlabroot\toolbox\images\imdata

where matlabroot represents your MATLAB installation folder.

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” on page 2-2


• “Expressing Image Locations” on page 2-3
• “Image Types in the Toolbox” on page 2-9
• “Converting Between Image Types” on page 2-17
• “Converting Between Image Classes” on page 2-19
• “Process Multi-Frame Image Arrays” on page 2-21
• “Perform an Operation on a Sequence of Images” on page 2-22
• “Batch Processing Using the Image Batch Processor App” on page 2-23
• “Process Large Set of Images Using MapReduce Framework and Hadoop” on page
2-39
• “What Is an Image Sequence?” on page 2-54
• “Toolbox Functions That Work with Image Sequences” on page 2-55
• “Overview of Image Arithmetic Functions” on page 2-58
• “Image Arithmetic Saturation Rules” on page 2-59
• “Nesting Calls to Image Arithmetic Functions” on page 2-60
2 Introduction

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:—

Sweet Highland Girl, a very shower


Of beauty is thy earthly dower!
Twice seven consenting years have shed
Their utmost bounty on thy head:
And these grey rocks; this household lawn;
These trees, a veil just half withdrawn;
This fall of water, that doth make
A murmur near the silent Lake;
This little Bay, a quiet road
That holds in shelter thy abode;
In truth together ye do seem
Like something fashion'd in a dream;
Such forms as from their covert peep
When earthly cares are laid asleep!
Yet, dream and vision as thou art,
I bless thee with a human heart:
God shield thee to thy latest years!
I neither know thee nor thy peers;
And yet my eyes are filled with tears.

With earnest feeling I shall pray


For thee when I am far away:
For never saw I mien or face,
In which more plainly I could trace
Benignity and home-bred sense
Ripening in perfect innocence.
Here, scattered like a random seed,
Remote from men, thou dost not need
Th' embarrass'd look of shy distress
And maidenly shamefacedness;
Thou wear'st upon thy forehead clear
The freedom of a mountaineer:
A face with gladness overspread!
Sweet smiles, by human-kindness bred!
And seemliness complete, that sways
Thy courtesies, about thee plays;
With no restraint but such as springs
From quick and eager visitings
Of thoughts that lie beyond the reach
Of thy few words of English speech:
A bondage sweetly brook'd, a strife
That gives thy gestures grace and life!
So have I, not unmoved in mind,
Seen birds of tempest-loving kind,
Thus beating up against the wind.

What hand but would a garland cull


For thee, who art so beautiful?
O happy pleasure! here to dwell
Beside thee in some heathy dell;
Adopt your homely ways and dress,
A Shepherd, thou a Shepherdess!
But I could frame a wish for thee
More like a grave reality:
Thou art to me but as a wave
Of the wild sea: and I would have
Some claim upon thee, if I could,
Though but of common neighbourhood.
What joy to hear thee and to see!
Thy elder brother I would be,
Thy father—anything to thee.

Now thanks to Heaven! that of its grace


Hath led me to this lonely place!
Joy have I had; and going hence
I bear away my recompence.
In spots like these it is we prize
Our memory, feel that she hath eyes:
Then why should I be loth to stir?
I feel this place is made for her;
To give new pleasure like the past
Continued long as life shall last.
Nor am I loth, though pleased at heart,
Sweet Highland Girl, from thee to part;
For I, methinks, till I grow old,
As fair before me shall behold
As I do now, the Cabin small,
The Lake, the Bay, the Waterfall,
And thee, the Spirit of them all.

We were rowed over speedily by the assistance of two youths,


who went backwards and forwards for their own amusement,
helping at the oars, and pulled as if they had strength and spirits to
spare for a year to come. We noticed that they had uncommonly fine
teeth, and that they and the boatman were very handsome people.
Another merry crew took our place in the boat.
We had three miles to walk to Tarbet. It rained, but not heavily;
the mountains were not concealed from us by the mists, but
appeared larger and more grand; twilight was coming on, and the
obscurity under which we saw the objects, with the sounding of the
torrents, kept our minds alive and wakeful; all was solitary and huge
—sky, water, and mountains mingled together. While we were
walking forward, the road leading us over the top of a brow, we
stopped suddenly at the sound of a half-articulate Gaelic hooting
from the field close to us. It came from a little boy, whom we could
see on the hill between us and the lake, wrapped up in a grey plaid.
He was probably calling home the cattle for the night. His
appearance was in the highest degree moving to the imagination:
mists were on the hillsides, darkness shutting in upon the huge
avenue of mountains, torrents roaring, no house in sight to which
the child might belong; his dress, cry, and appearance all different
from anything we had been accustomed to. It was a text, as William
has since observed to me, containing in itself the whole history of
the Highlander's life—his melancholy, his simplicity, his poverty, his
superstition, and above all, that visionariness which results from a
communion with the unworldliness of nature.
When we reached Tarbet the people of the house were anxious to
know how we had fared, particularly the girl who had waited upon
us. Our praises of Loch Ketterine made her exceedingly happy, and
she ventured to say, of which we had heard not a word before, that
it was "bonnier to her fancy than Loch Lomond." The landlord, who
was not at home when we had set off, told us that if he had known
of our going he would have recommended us to Mr. Macfarlane's or
the other farm-house, adding that they were hospitable people in
that vale. Coleridge and I got tea, and William and the drawing-
master chose supper; they asked to have a broiled fowl, a dish very
common in Scotland, to which the mistress replied, "Would not a
'boiled' one do as well?" They consented, supposing that it would be
more easily cooked; but when the fowl made its appearance, to their
great disappointment it proved a cold one that had been stewed in
the broth at dinner.

Monday, August 29th.—It rained heavily this morning, and, having


heard so much of the long rains since we came into Scotland, as well
as before, we had no hope that it would be over in less than three
weeks at the least, so poor Coleridge, being very unwell, determined
to send his clothes to Edinburgh and make the best of his way
thither, being afraid to face much wet weather in an open carriage.
William and I were unwilling to be confined at Tarbet, so we
resolved to go to Arrochar, a mile and a half on the road to Inverary,
where there is an inn celebrated as a place of good accommodation
for travellers. Coleridge and I set off on foot, and William was to
follow with the car, but a heavy shower coming on, Coleridge left me
to shelter in a hut and wait for William, while he went on before.
This hut was unplastered, and without windows, crowded with beds,
uncomfortable, and not in the simplicity of the ferryman's house. A
number of good clothes were hanging against the walls, and a green
silk umbrella was set up in a corner. I should have been surprised to
see an umbrella in such a place before we came into the Highlands;
but umbrellas are not so common anywhere as there—a plain proof
of the wetness of the climate; even five minutes after this a girl
passed us without shoes and stockings, whose gown and petticoat
were not worth half a crown, holding an umbrella over her bare
head.
We turned at a guide-post, "To the New Inn," and, after
descending a little, and winding round the bottom of a hill, saw, at a
small distance, a white house half hidden by tall trees upon a lawn
that slopes down to the side of Loch Long, a sea-loch, which is here
very narrow. Right before us, across the lake, was the Cobbler,
which appeared to rise directly from the water; but, in fact, it
overtopped another hill, being a considerable way behind. The inn
looked so much like a gentleman's house that we could hardly
believe it was an inn. We drove down the broad gravel walk, and,
making a sweep, stopped at the front door, were shown into a large
parlour with a fire, and my first thought was, How comfortable we
should be! but Coleridge, who had arrived before us, checked my
pleasure: the waiter had shown himself disposed to look coolly upon
us, and there had been a hint that we could not have beds;—a party
was expected, who had engaged all the beds. We conjectured this
might be but a pretence, and ordered dinner in the hope that
matters would clear up a little, and we thought they could not have
the heart to turn us out in so heavy a rain if it were possible to lodge
us. We had a nice dinner, yet would have gladly changed our roasted
lamb and pickles, and the gentleman-waiter with his napkin in his
pocket, for the more homely fare of the smoky hut at Loch Ketterine,
and the good woman's busy attentions, with the certainty of a
hospitable shelter at night. After dinner I spoke to the landlord
himself, but he was not to be moved: he could not even provide one
bed for me, so nothing was to be done but either to return to Tarbet
with Coleridge, or that William and I should push on the next stage,
to Cairndow. We had an interesting close view from the windows of
the room where we sate, looking across the lake, which did not
differ in appearance, as we saw it here, from a fresh-water lake. The
sloping lawn on which the house stood was prettily scattered over
with trees; but we had seen the place to great advantage at our first
approach, owing to the mists upon the mountains, which had made
them seem exceedingly high, while the strange figures on the
Cobbler appeared and disappeared, like living things; but, as the day
cleared we were disappointed in what was more like the permanent
effect of the scene: the mountains were not so lofty as we had
supposed, and the low grounds not so fertile; yet still it is a very
interesting, I may say beautiful, place.
The rain ceased entirely, so we resolved to go on to Cairndow,
and had the satisfaction of seeing that our landlord had not told us
an untruth concerning the expected company; for just before our
departure we saw, on the opposite side of the vale, a coach with
four horses, another carriage, and two or three men on horseback—
a striking procession, as it moved along between the bare mountain
and the lake. Twenty years ago, perhaps, such a sight had not been
seen here except when the Duke of Argyle, or some other Highland
chieftain, might chance to be going with his family to London or
Edinburgh. They had to cross a bridge at the head of the lake, which
we could not see, so, after disappearing about ten minutes, they
drove up to the door—three old ladies, two waiting-women, and
store of men-servants. The old ladies were as gaily dressed as
bullfinches in spring-time. We heard the next day that they were the
renowned Miss Waughs of Carlisle, and that they enjoyed
themselves over a game of cards in the evening.
Left Arrochar at about four o'clock in the afternoon. Coleridge
accompanied us a little way; we portioned out the contents of our
purse before our parting; and, after we had lost sight of him, drove
heavily along. Crossed the bridge, and looked to the right, up the
vale, which is soon terminated by mountains: it was of a yellow
green, with but few trees and few houses; sea-gulls were flying
above it. Our road—the same along which the carriages had come—
was directly under the mountains on our right hand, and the lake
was close to us on our left, the waves breaking among stones
overgrown with yellow sea-weed; fishermen's boats, and other
larger vessels than are seen on fresh-water lakes were lying at
anchor near the opposite shore; sea-birds flying overhead; the noise
of torrents mingled with the beating of the waves, and misty
mountains enclosed the vale;—a melancholy but not a dreary scene.
Often have I, in looking over a map of Scotland, followed the
intricate windings of one of these sea-lochs, till, pleasing myself with
my own imaginations, I have felt a longing, almost painful, to travel
among them by land or by water.
This was the first sea-loch we had seen. We came prepared for a
new and great delight, and the first impression which William and I
received, as we drove rapidly through the rain down the lawn of
Arrochar, the objects dancing before us, was even more delightful
than we had expected. But, as I have said, when we looked through
the window, as the mists disappeared and the objects were seen
more distinctly, there was less of sheltered valley-comfort than we
had fancied to ourselves, and the mountains were not so grand; and
now that we were near to the shore of the lake, and could see that
it was not of fresh water, the wreck, the broken sea-shells, and
scattered sea-weed gave somewhat of a dull and uncleanly look to
the whole lake, and yet the water was clear, and might have
appeared as beautiful as that of Loch Lomond, if with the same pure
pebbly shore. Perhaps, had we been in a more cheerful mood of
mind we might have seen everything with a different eye. The
stillness of the mountains, the motion of the waves, the streaming
torrents, the sea-birds, the fishing-boats were all melancholy; yet
still, occupied as my mind was with other things, I thought of the
long windings through which the waters of the sea had come to this
inland retreat, visiting the inner solitudes of the mountains, and I
could have wished to have mused out a summer's day on the shores
of the lake. From the foot of these mountains whither might not a
little barque carry one away? Though so far inland, it is but a slip of
the great ocean: seamen, fishermen, and shepherds here find a
natural home. We did not travel far down the lake, but, turning to
the right through an opening of the mountains, entered a glen called
Glen Croe.
Our thoughts were full of Coleridge, and when we were enclosed
in the narrow dale, with a length of winding road before us, a road
that seemed to have insinuated itself into the very heart of the
mountains—the brook, the road, bare hills, floating mists, scattered
stones, rocks, and herds of black cattle being all that we could see,
—I shivered at the thought of his being sickly and alone, travelling
from place to place.
The Cobbler, on our right, was pre-eminent above the other hills;
the singular rocks on its summit, seen so near, were like ruins—
castles or watch-towers. After we had passed one reach of the glen,
another opened out, long, narrow, deep, and houseless, with herds
of cattle and large stones; but the third reach was softer and more
beautiful, as if the mountains had there made a warmer shelter, and
there were a more gentle climate. The rocks by the river-side had
dwindled away, the mountains were smooth and green, and towards
the end, where the glen sloped upwards, it was a cradle-like hollow,
and at that point where the slope became a hill, at the very bottom
of the curve of the cradle, stood one cottage, with a few fields and
beds of potatoes. There was also another house near the roadside,
which appeared to be a herdsman's hut. The dwelling in the middle
of the vale was a very pleasing object. I said within myself, How
quietly might a family live in this pensive solitude, cultivating and
loving their own fields! but the herdsman's hut, being the only one
in the vale, had a melancholy face; not being attached to any
particular plot of land, one could not help considering it as just kept
alive and above ground by some dreary connexion with the long
barren tract we had travelled through.
The afternoon had been exceedingly pleasant after we had left
the vale of Arrochar; the sky was often threatening, but the rain
blew off, and the evening was uncommonly fine. The sun had set a
short time before we had dismounted from the car to walk up the
steep hill at the end of the glen. Clouds were moving all over the sky
—some of a brilliant yellow hue, which shed a light like bright
moonlight upon the mountains. We could not have seen the head of
the valley under more favourable circumstances.
The passing away of a storm is always a time of life and
cheerfulness, especially in a mountainous country; but that
afternoon and evening the sky was in an extraordinary degree vivid
and beautiful. We often stopped in ascending the hill to look down
the long reach of the glen. The road, following the course of the
river as far as we could see, the farm and cottage hills, smooth
towards the base and rocky higher up, were the sole objects before
us. This part of Glen Croe reminded us of some of the dales of the
north of England—Grisdale above Ulswater, for instance; but the
length of it, and the broad highway, which is always to be seen at a
great distance, a sort of centre of the vale, a point of reference,
gives to the whole of the glen, and each division of it, a very
different character.
At the top of the hill we came to a seat with the well-known
inscription, "Rest and be thankful." On the same stone it was
recorded that the road had been made by Col. Wade's regiment. The
seat is placed so as to command a full view of the valley, and the
long, long road, which, with the fact recorded, and the exhortation,
makes it an affecting resting-place. We called to mind with pleasure
a seat under the braes of Loch Lomond on which I had rested,
where the traveller is informed by an inscription upon a stone that
the road was made by Col. Lascelles' regiment. There, the spot had
not been chosen merely as a resting-place, for there was no steep
ascent in the highway, but it might be for the sake of a spring of
water and a beautiful rock, or, more probably, because at that point
the labour had been more than usually toilsome in hewing through
the rock. Soon after we had climbed the hill we began to descend
into another glen, called Glen Kinglas. We now saw the western sky,
which had hitherto been hidden from us by the hill—a glorious mass
of clouds uprising from a sea of distant mountains, stretched out in
length before us, towards the west—and close by us was a small
lake or tarn. From the reflection of the crimson clouds the water
appeared of a deep red, like melted rubies, yet with a mixture of a
grey or blackish hue: the gorgeous light of the sky, with the singular
colour of the lake, made the scene exceedingly romantic; yet it was
more melancholy than cheerful. With all the power of light from the
clouds, there was an overcasting of the gloom of evening, a twilight
upon the hills.
We descended rapidly into the glen, which resembles the lower
part of Glen Croe, though it seemed to be inferior in beauty; but
before we had passed through one reach it was quite dark, and I
only know that the steeps were high, and that we had the company
of a foaming stream; and many a vagrant torrent crossed us,
dashing down the hills. The road was bad, and, uncertain how we
should fare, we were eager and somewhat uneasy to get forward;
but when we were out of the close glen, and near to Cairndow, as a
traveller had told us, the moon showed her clear face in the sky,
revealing a spacious vale, with a broad loch and sloping corn fields;
the hills not very high. This cheerful sight put us into spirits, and we
thought it was at least no dismal place to sit up all night in, if they
had no beds, and they could not refuse us a shelter. We were,
however, well received, and sate down in a neat parlour with a good
fire.
Tuesday, August 30th.—Breakfasted before our departure, and
ate a herring, fresh from the water, at our landlord's earnest
recommendation—much superior to the herrings we get in the north
of England.3 Though we rose at seven, could not set off before nine
o'clock; the servants were in bed; the kettle did not boil—indeed, we
were completely out of patience; but it had always been so, and we
resolved to go off in future without breakfast. Cairndow is a single
house by the side of the loch, I believe resorted to by gentlemen in
the fishing season: it is a pleasant place for such a purpose; but the
vale did not look so beautiful as by moonlight—it had a sort of sea-
coldness without mountain grandeur. There is a ferry for foot-
passengers from Cairndow to the other side of the water, and the
road along which all carriages go is carried round the head of the
lake, perhaps a distance of three miles.
After we had passed the landing-place of the ferry opposite to
Cairndow we saw the lake spread out to a great width, more like an
arm of the sea or a great river than one of our lakes; it reminded us
of the Severn at the Chepstow passage; but the shores were less
rich and the hills higher. The sun shone, which made the morning
cheerful, though there was a cold wind. Our road never carried us
far from the lake, and with the beating of the waves, the sparkling
sunshiny water, boats, the opposite hills, and, on the side on which
we travelled, the chance cottages, the coppice woods, and common
business of the fields, the ride could not but be amusing. But what
most excited our attention was, at one particular place, a cluster of
fishing-boats at anchor in a still corner of the lake, a small bay or
harbour by the wayside. They were overshadowed by fishermen's
nets hung out to dry, which formed a dark awning that covered
them like a tent, overhanging the water on each side, and falling in
the most exquisitely graceful folds. There was a monastic
pensiveness, a funereal gloom in the appearance of this little
company of vessels, which was the more interesting from the
general liveliness and glancing motions of the water, they being
perfectly still and silent in their sheltered nook.
When we had travelled about seven miles from Cairndow, winding
round the bottom of a hill, we came in view of a great basin or
elbow of the lake. Completely out of sight of the long track of water
we had coasted, we seemed now to be on the edge of a very large,
almost circular, lake, the town of Inverary before us, a line of white
buildings on a low promontory right opposite, and close to the
water's edge; the whole landscape a showy scene, and bursting
upon us at once. A traveller who was riding by our side called out,
"Can that be the Castle?" Recollecting the prints which we had seen,
we knew it could not; but the mistake is a natural one at that
distance: it is so little like an ordinary town, from the mixture of
regularity and irregularity in the buildings. With the expanse of water
and pleasant mountains, the scattered boats and sloops, and those
gathered together, it had a truly festive appearance. A few steps
more brought us in view of the Castle, a stately turreted mansion,
but with a modern air, standing on a lawn, retired from the water,
and screened behind by woods covering the sides of high hills to the
top, and still beyond, by bare mountains. Our road wound round the
semicircular shore, crossing two bridges of lordly architecture. The
town looked pretty when we drew near to it in connexion with its
situation, different from any place I had ever seen, yet exceedingly
like what I imaged to myself from representations in raree-shows, or
pictures of foreign places—Venice, for example—painted on the
scene of a play-house, which one is apt to fancy are as cleanly and
gay as they look through the magnifying-glass of the raree-show or
in the candle-light dazzle of a theatre. At the door of the inn, though
certainly the buildings had not that delightful outside which they
appeared to have at a distance, yet they looked very pleasant. The
range bordering on the water consisted of little else than the inn,
being a large house, with very large stables, the county gaol, the
opening into the main street into the town, and an arched gateway,
the entrance into the Duke of Argyle's private domain.
We were decently well received at the inn, but it was over-rich in
waiters and large rooms to be exactly to our taste, though quite in
harmony with the neighbourhood. Before dinner we went into the
Duke's pleasure-grounds, which are extensive, and of course
command a variety of lively and interesting views. Walked through
avenues of tall beech-trees, and observed some that we thought
even the tallest we had ever seen; but they were all scantily covered
with leaves, and the leaves exceedingly small—indeed, some of
them, in the most exposed situations, were almost bare, as if it had
been winter. Travellers who wish to view the inside of the Castle
send in their names, and the Duke appoints the time of their going;
but we did not think that what we should see would repay us for the
trouble, there being no pictures, and the house, which I believe has
not been built above half a century, is fitted up in the modern style.
If there had been any reliques of the ancient costume of the castle
of a Highland chieftain, we should have been sorry to have passed
it.
Sate after dinner by the fireside till near sunset, for it was very
cold, though the sun shone all day. At the beginning of this our
second walk we passed through the town, which is but a doleful
example of Scotch filth. The houses are plastered or rough-cast, and
washed yellow—well built, well sized, and sash-windowed,
bespeaking a connexion with the Duke, such a dependence as may
be expected in a small town so near to his mansion; and indeed he
seems to have done his utmost to make them comfortable,
according to our English notions of comfort: they are fit for the
houses of people living decently upon a decent trade; but the
windows and door-steads were as dirty as in a dirty by-street of a
large town, making a most unpleasant contrast with the comely face
of the buildings towards the water, and the ducal grandeur and
natural festivity of the scene. Smoke and blackness are the wild
growth of a Highland hut: the mud floors cannot be washed, the
door-steads are trampled by cattle, and if the inhabitants be not very
cleanly it gives one little pain; but dirty people living in two-storied
stone houses, with dirty sash windows, are a melancholy spectacle
anywhere, giving the notion either of vice or the extreme of
wretchedness.
Returning through the town, we went towards the Castle, and
entered the Duke's grounds by a porter's lodge, following the
carriage-road through the park, which is prettily scattered over with
trees, and slopes gently towards the lake. A great number of lime-
trees were growing singly, not beautiful in their shape, but I mention
them for the resemblance to one of the same kind we had seen in
the morning, which formed a shade as impenetrable as the roof of
any house. The branches did not spread far, nor any one branch
much further than another; on the outside it was like a green bush
shorn with shears, but when we sate upon a bench under it, looking
upwards, in the middle of the tree we could not perceive any green
at all; it was like a hundred thousand magpies' nests clustered and
matted together, the twigs and boughs being so intertwined that
neither the light of the mid-day sun nor showers of hail or rain could
pierce through them. The lime-trees on the lawn resembled this tree
both in shape and in the manner of intertwisting their twigs, but
they were much smaller, and not an impenetrable shade.
The views from the Castle are delightful. Opposite is the lake, girt
with mountains, or rather smooth high hills; to the left appears a
very steep rocky hill, called Duniquoich Hill, on the top of which is a
building like a watch-tower; it rises boldly and almost perpendicular
from the plain, at a little distance from the river Arey, that runs
through the grounds. To the right is the town, overtopped by a sort
of spire or pinnacle of the church, a thing unusual in Scotland,
except in the large towns, and which would often give an elegant
appearance to the villages, which, from the uniformity of the huts,
and the frequent want of tall trees, they seldom exhibit.
In looking at an extensive prospect, or travelling through a large
vale, the Trough of the Clyde for instance, I could not help thinking
that in England there would have been somewhere a tower or spire
to warn us of a village lurking under the covert of a wood or bank,
or to point out some particular spot on the distant hills which we
might look at with kindly feelings. I well remember how we used to
love the little nest of trees out of which Ganton spire rose on the
distant Wolds opposite to the windows at Gallow Hill. The spire of
Inverary is not of so beautiful a shape as those of the English
churches, and, not being one of a class of buildings which is
understood at once, seen near or at a distance, is a less interesting
object; but it suits well with the outlandish trimness of the buildings
bordering on the water; indeed, there is no one thing of the many
gathered together in the extensive circuit of the basin or vale of
Inverary, that is not in harmony with the effect of the whole place.
The Castle is built of a beautiful hewn stone, in colour resembling
our blue slates. The author-tourists have quarrelled with the
architecture of it, but we did not find much that we were disposed to
blame. A castle in a deep glen, overlooking a roaring stream, and
defended by precipitous rocks, is, no doubt, an object far more
interesting; but, dropping all ideas of danger or insecurity, the
natural retinue in our minds of an ancient Highland chieftain,—take a
Duke of Argyle at the end of the eighteenth century, let him have his
house in Grosvenor Square, his London liveries, and daughters
glittering at St. James's, and I think you will be satisfied with his
present mansion in the Highlands, which seems to suit with the
present times and its situation, and that is indeed a noble one for a
modern Duke of the mountainous district of Argyleshire, with its
bare valleys, its rocky coasts, and sea lochs.
There is in the natural endowments of Inverary something akin to
every feature of the general character of the county; yet even the
very mountains and the lake itself have a kind of princely festivity in
their appearance. I do not know how to communicate the feeling,
but it seemed as if it were no insult to the hills to look on them as
the shield and enclosure of the ducal domain, to which the water
might delight in bearing its tribute. The hills near the lake are
smooth, so smooth that they might have been shaven or swept; the
shores, too, had somewhat of the same effect, being bare, and
having no roughness, no woody points; yet the whole circuit being
very large, and the hills so extensive, the scene was not the less
cheerful and festive, rejoicing in the light of heaven. Behind the
Castle the hills are planted to a great height, and the pleasure-
grounds extend far up the valley of Arey. We continued our walk a
short way along the river, and were sorry to see it stripped of its
natural ornaments, after the fashion of Mr. Brown,4 and left to tell its
tale—for it would not be silent like the river at Blenheim—to naked
fields and the planted trees on the hills. We were disgusted with the
stables, out-houses, or farm-houses in different parts of the grounds
behind the Castle: they were broad, out-spreading, fantastic, and
unintelligible buildings.
Sate in the park till the moonlight was perceived more than the
light of day. We then walked near the town by the water-side. I
observed that the children who were playing did not speak Erse, but
a much worse English than is spoken by those Highlanders whose
common language is the Erse. I went into the town to purchase tea
and sugar to carry with us on our journey. We were tired when we
returned to the inn, and went to bed directly after tea. My room was
at the very top of the house—one flight of steps after another!—but
when I drew back the curtains of my window I was repaid for the
trouble of panting up-stairs by one of the most splendid moonlight
prospects that can be conceived: the whole circuit of the hills, the
Castle, the two bridges, the tower on Duniquoich Hill, and the lake
with many boats—fit scene for summer midnight festivities! I should
have liked to have seen a bevy of Scottish ladies sailing, with music,
in a gay barge. William, to whom I have read this, tells me that I
have used the very words of Browne of Ottery, Coleridge's fellow-
townsman:—

As I have seen when on the breast of Thames


A heavenly bevy of sweet English dames,
In some calm evening of delightful May,
With music give a farewell to the day,
Or as they would (with an admired tone)
Greet night's ascension to her ebon throne.
Browne's Britannia's Pastorals.

Wednesday, August 31st.—We had a long day's journey before us,


without a regular baiting-place on the road, so we breakfasted at
Inverary, and did not set off till nine o'clock, having, as usual, to
complain of the laziness of the servants. Our road was up the valley
behind the Castle, the same we had gone along the evening before.
Further up, though the plantations on the hills are noble, the valley
was cold and naked, wanting hedgerows and comfortable houses.
We travelled several miles under the plantations, the vale all along
seeming to belong almost exclusively to the Castle. It might have
been better distinguished and adorned, as we thought, by neater
farm-houses and cottages than are common in Scotland, and
snugger fields with warm hedgerows, at the same time testifying as
boldly its adherence to the chief.
At that point of the valley where the pleasure-grounds appear to
end, we left our horse at a cottage door, and turned a few steps out
of the road to see a waterfall, which roared so loud that we could
not have gone by without looking about for it, even if we had not
known that there was one near Inverary. The waterfall is not
remarkable for anything but the good taste with which it has been
left to itself, though there is a pleasure-road from the Castle to it. As
we went further up the valley the roads died away, and it became an
ordinary Scotch glen, the poor pasturage of the hills creeping down
into the valley, where it was little better for the shelter, I mean little
greener than on the hill-sides; but a man must be of a churlish
nature if, with a mind free to look about, he should not find such a
glen a pleasing place to travel through, though seeing little but the
busy brook, with here and there a bush or tree, and cattle pasturing
near the thinly-scattered dwellings. But we came to one spot which I
cannot forget, a single green field at the junction of another brook
with the Arey, a peninsula surrounded with a close row of trees,
which overhung the streams, and under their branches we could just
see a neat white house that stood in the middle of the field enclosed
by the trees. Before us was nothing but bare hills, and the road
through the bare glen. A person who has not travelled in Scotland
can scarcely imagine the pleasure we have had from a stone house,
though fresh from the workmen's hands, square and sharp; there is
generally such an appearance of equality in poverty through the long
glens of Scotland, giving the notion of savage ignorance—no house
better than another, and barns and houses all alike. This house had,
however, other recommendations of its own; even in the fertile parts
of Somersetshire it would have been a delicious spot; here, "'Mid
mountain wild set like a little nest," it was a resting-place for the
fancy, and to this day I often think of it, the cottage and its green
covert, as an image of romance, a place of which I have the same
sort of knowledge as of some of the retirements, the little valleys,
described so livelily by Spenser in his Fairy Queen.
We travelled on, the glen now becoming entirely bare. Passed a
miserable hut on a naked hill-side, not far from the road, where we
were told by a man who came out of it that we might refresh
ourselves with a dram of whisky. Went over the hill, and saw nothing
remarkable till we came in view of Loch Awe, a large lake far below
us, among high mountains—one very large mountain right opposite,
which we afterwards found was called Cruachan. The day was
pleasant—sunny gleams and a fresh breeze; the lake—we looked
across it—as bright as silver, which made the islands, three or four in
number, appear very green. We descended gladly, invited by the
prospect before us, travelling downwards, along the side of the hill,
above a deep glen, woody towards the lower part near the brook;
the hills on all sides were high and bare, and not very stony: it made
us think of the descent from Newlands into Buttermere, though on a
wider scale, and much inferior in simple majesty.
After walking down the hill a long way we came to a bridge,
under which the water dashed through a dark channel of rocks
among trees, the lake being at a considerable distance below, with
cultivated lands between. Close upon the bridge was a small
hamlet,5 a few houses near together, and huddled up in trees—a
very sweet spot, the only retired village we had yet seen which was
characterized by "beautiful" wildness with sheltering warmth. We
had been told at Inverary that we should come to a place where we
might give our horse a feed of corn, and found on inquiry that there
was a little public-house here, or rather a hut "where they kept a
dram." It was a cottage, like all the rest, without a sign-board. The
woman of the house helped to take the horse out of harness, and,
being hungry, we asked her if she could make us some porridge, to
which she replied that "we should get that," and I followed her into
the house, and sate over her hearth while she was making it. As to
fire, there was little sign of it, save the smoke, for a long time, she
having no fuel but green wood, and no bellows but her breath. My
eyes smarted exceedingly, but the woman seemed so kind and
cheerful that I was willing to endure it for the sake of warming my
feet in the ashes and talking to her. The fire was in the middle of the
room, a crook being suspended from a cross-beam, and a hole left
at the top for the smoke to find its way out by: it was a rude
Highland hut, unadulterated by Lowland fashions, but it had not the
elegant shape of the ferry-house at Loch Ketterine, and the fire,
being in the middle of the room, could not be such a snug place to
draw to on a winter's night.
We had a long afternoon before us, with only eight miles to travel
to Dalmally, and, having been told that a ferry-boat was kept at one
of the islands, we resolved to call for it, and row to the island, so we
went to the top of an eminence, and the man who was with us set
some children to work to gather sticks and withered leaves to make
a smoky fire—a signal for the boatman, whose hut is on a flat green
island, like a sheep pasture, without trees, and of a considerable
size: the man told us it was a rabbit-warren. There were other small
islands, on one of which was a ruined house, fortification, or small
castle: we could not learn anything of its history, only a girl told us
that formerly gentlemen lived in such places. Immediately from the
water's edge rose the mountain Cruachan on the opposite side of
the lake; it is woody near the water and craggy above, with deep
hollows on the surface. We thought it the grandest mountain we had
seen, and on saying to the man who was with us that it was a fine
mountain, "Yes," he replied, "it is an excellent mountain," adding
that it was higher than Ben Lomond, and then told us some wild
stories of the enormous profits it brought to Lord Breadalbane, its
lawful owner. The shape of Loch Awe is very remarkable, its outlet
being at one side, and only about eight miles from the head, and the
whole lake twenty-four miles in length. We looked with longing after
that branch of it opposite to us out of which the water issues: it
seemed almost like a river gliding under steep precipices. What we
saw of the larger branch, or what might be called the body of the
lake, was less promising, the banks being merely gentle slopes, with
not very high mountains behind, and the ground moorish and cold.
The children, after having collected fuel for our fire, began to play
on the green hill where we stood, as heedless as if we had been
trees or stones, and amused us exceedingly with their activity: they
wrestled, rolled down the hill, pushing one another over and over
again, laughing, screaming, and chattering Erse: they were all
without shoes and stockings, which, making them fearless of hurting
or being hurt, gave a freedom to the action of their limbs which I
never saw in English children: they stood upon one another, body,
breast, or face, or any other part; sometimes one was uppermost,
sometimes another, and sometimes they rolled all together, so that
we could not know to which body this leg or that arm belonged. We
waited, watching them, till we were assured that the boatman had
noticed our signal.—By the bye, if we had received proper directions
at Loch Lomond, on our journey to Loch Ketterine, we should have
made our way down the lake till we had come opposite to the
ferryman's house, where there is a hut, and the people who live
there are accustomed to call him by the same signal as here. Luckily
for us we were not so well instructed, for we should have missed the
pleasure of receiving the kindness of Mr. and Mrs. Macfarlane and
their family.
A young woman who wanted to go to the island accompanied us
to the water-side. The walk was pleasant, through fields with
hedgerows, the greenest fields we had seen in Scotland; but we
were obliged to return without going to the island. The poor man
had taken his boat to another place, and the waters were swollen so
that we could not go close to the shore, and show ourselves to him,
nor could we make him hear by shouting. On our return to the
public-house we asked the woman what we should pay her, and
were not a little surprised when she answered, "Three shillings." Our
horse had had a sixpenny feed of miserable corn, not worth
threepence; the rest of the charge was for skimmed milk, oat-bread,
porridge, and blue milk cheese: we told her it was far too much;
and, giving her half-a-crown, departed. I was sorry she had made
this unreasonable demand, because we had liked the woman, and
we had before been so well treated in the Highland cottages; but, on
thinking more about it, I satisfied myself that it was no scheme to
impose upon us, for she was contented with the half-crown, and
would, I daresay, have been so with two shillings, if we had offered
it her at first. Not being accustomed to fix a price upon porridge and
milk, to such as we, at least, when we asked her she did not know
what to say; but, seeing that we were travelling for pleasure, no
doubt she concluded we were rich, and that what was a small gain
to her could be no great loss to us.
When we had gone a little way we saw before us a young man
with a bundle over his shoulder, hung on a stick, bearing a great boy
on his back: seeing that they were travellers, we offered to take the
boy on the car, to which the man replied that he should be more
than thankful, and set him up beside me. They had walked from
Glasgow, and that morning from Inverary; the boy was only six
years old, "But," said his father, "he is a stout walker," and a fine
fellow he was, smartly dressed in tight clean clothes and a nice
round hat: he was going to stay with his grandmother at Dalmally. I
found him good company; though I could not draw a single word out
of him, it was a pleasure to see his happiness gleaming through the
shy glances of his healthy countenance. Passed a pretty chapel by
the lake-side, and an island with a farm-house upon it, and corn and
pasture fields; but, as we went along, we had frequent reason to
regret the want of English hedgerows and English culture; for the
ground was often swampy or moorish near the lake where
comfortable dwellings among green fields might have been. When
we came near to the end of the lake we had a steep hill to climb, so
William and I walked; and we had such confidence in our horse that
we were not afraid to leave the car to his guidance with the child in
it; we were soon, however, alarmed at seeing him trot up the hill a
long way before us; the child, having raised himself up upon the
seat, was beating him as hard as he could with a little stick which he
carried in his hand; and when he saw our eyes were on him he sate
down, I believe very sorry to resign his office: the horse slackened
his pace, and no accident happened.
When we had ascended half-way up the hill, directed by the man,
I took a nearer footpath, and at the top came in view of a most
impressive scene, a ruined castle on an island almost in the middle
of the last compartment of the lake, backed by a mountain cove,
down which came a roaring stream. The castle occupied every foot
of the island that was visible to us, appearing to rise out of the
water; mists rested upon the mountain side, with spots of sunshine
between; there was a mild desolation in the low grounds, a solemn
grandeur in the mountains, and the castle was wild, yet stately, not
dismantled of its turrets, nor the walls broken down, though
completely in ruin. After having stood some minutes I joined William
on the high road, and both wishing to stay longer near this place,
we requested the man to drive his little boy on to Dalmally, about
two miles further, and leave the car at the inn. He told us that the
ruin was called Kilchurn Castle, that it belonged to Lord Breadalbane,
and had been built by one of the ladies of that family for her defence
during her Lord's absence at the Crusades, for which purpose she
levied a tax of seven years' rent upon her tenants;6 he said that
from that side of the lake it did not appear, in very dry weather, to
stand upon an island; but that it was possible to go over to it
without being wet-shod. We were very lucky in seeing it after a
great flood; for its enchanting effect was chiefly owing to its
situation in the lake, a decayed palace rising out of the plain of
waters! I have called it a palace, for such feeling it gave to me,
though having been built as a place of defence, a castle or fortress.
We turned again and reascended the hill, and sate a long time in the
middle of it looking on the castle and the huge mountain cove
opposite, and William, addressing himself to the ruin, poured out
these verses:7—

Child of loud-throated War! the mountain


stream
Roars in thy hearing; but thy hour of rest
Is come, and thou art silent in thy age.

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.

Thursday, September 1st.—We had been attended at supper by a


civil boy, whom we engaged to rouse us at six o'clock, and to
provide us each a basin of milk and bread, and have the car ready;
all which he did punctually, and we were off in good time. The
morning was not unpleasant, though rather cold, and we had some
fear of rain. Crossed the bridge, and passed by the manse and
chapel, our road carrying us back again in the direction we had
come; but on the opposite side of the river. Passed close to many of
the houses we had seen on the hill-side, which the lame gentleman
had told us belonged to Lord Breadalbane, and were attached to
little farms, or "crofts," as he called them. Lord Breadalbane had
lately laid out a part of his estates in this way as an experiment, in
the hope of preventing discontent and emigration. We were sorry we
had not an opportunity of seeing into these cottages, and of learning
how far the people were happy or otherwise. The dwellings certainly
did not look so comfortable when we were near to them as from a
distance; but this might be chiefly owing to what the inhabitants did
not feel as an evil—the dirt about the doors. We saw, however—a
sight always painful to me—two or three women, each creeping
after her single cow, while it was feeding on the slips of grass
between the corn-grounds. Went round the head of the lake, and
onwards close to the lake-side. Kilchurn Castle was always
interesting, though not so grand as seen from the other side, with its
own mountain cove and roaring stream. It combined with the vale of
Dalmally and the distant hills—a beautiful scene, yet overspread with
a gentle desolation. As we went further down we lost sight of the
vale of Dalmally. The castle, which we often stopped to look back
upon, was very beautiful seen in combination with the opposite
shore of the lake—perhaps a little bay, a tuft of trees, or a slope of
the hill. Travelled under the foot of the mountain Cruachan, along an
excellent road, having the lake close to us on our left, woods
overhead, and frequent torrents tumbling down the hills. The distant
views across the lake were not peculiarly interesting after we were
out of sight of Kilchurn Castle, the lake being wide, and the opposite
shore not rich, and those mountains which we could see were not
high.
Came opposite to the village where we had dined the day before,
and, losing sight of the body of the lake, pursued the narrow
channel or pass,8 which is, I believe, three miles long, out of which
issues the river that flows into Loch Etive. We were now enclosed
between steep hills, on the opposite side entirely bare, on our side
bare or woody; the branch of the lake generally filling the whole
area of the vale. It was a pleasing, solitary scene; the long reach of
naked precipices on the other side rose directly out of the water,
exceedingly steep, not rugged or rocky, but with scanty sheep
pasturage and large beds of small stones, purple, dove-coloured, or
red, such as are called Screes in Cumberland and Westmoreland.
These beds, or rather streams of stones, appeared as smooth as the
turf itself, nay, I might say, as soft as the feathers of birds, which
they resembled in colour. There was no building on either side of the
water; in many parts only just room for the road, and on the other
shore no footing, as it might seem, for any creature larger than the
mountain sheep, and they, in treading amongst the shelving stones,
must often send them down into the lake below.
After we had wound for some time through the valley, having met
neither foot-traveller, horse, nor cart, we started at the sight of a
single vessel, just as it turned round the point of a hill, coming into
the reach of the valley where we were. She floated steadily through
the middle of the water, with one large sail spread out, full swollen
by the breeze, that blew her right towards us. I cannot express what
romantic images this vessel brought along with her—how much
more beautiful the mountains appeared, the lake how much more
graceful. There was one man on board, who sate at the helm, and
he, having no companion, made the boat look more silent than if we
could not have seen him. I had almost said the ship, for on that
narrow water it appeared as large as the ships which I have watched
sailing out of a harbour of the sea. A little further on we passed a
stone hut by the lake-side, near which were many charcoal sacks,
and we conjectured that the vessel had been depositing charcoal
brought from other parts of Loch Awe to be carried to the iron-works
at Loch Etive. A little further on we came to the end of the lake, but
where exactly it ended was not easy to determine, for the river was
as broad as the lake, and we could only say when it became
positively a river by the rushing of the water. It is, indeed, a grand
stream, the quantity of water being very large, frequently forming
rapids, and always flowing very quickly; but its greatness is short-
lived, for, after a course of three miles, it is lost in the great waters
of Loch Etive, a sea loch.
Crossed a bridge, and climbing a hill towards Taynuilt, our baiting-
place, we saw a hollow to the right below us, through which the
river continued its course between rocks and steep banks of wood.
William turned aside to look into the dell, but I was too much tired.
We had left it, two or three hundred yards behind, an open river, the
hills, enclosing the branch of the lake, having settled down into
irregular slopes. We were glad when we reached Taynuilt, a village
of huts, with a chapel and one stone house, which was the inn. It
had begun to rain, and I was almost benumbed with the cold,
besides having a bad headache; so it rejoiced me to see kind looks
on the landlady's face, and that she was willing to put herself in a
bustle for our comfort; we had a good fire presently, and breakfast
was set out—eggs, preserved gooseberries, excellent cream, cheese,
and butter, but no wheat bread, and the oaten cakes were so hard I
could not chew them. We wished to go upon Loch Etive; so, having
desired the landlady to prepare a fowl for supper, and engaged beds,
which she promised us willingly—a proof that we were not in the
great road—we determined to find our way to the lake and
endeavour to procure a boat. It rained heavily, but we went on,
hoping the sky would clear up.
Walked through unenclosed fields, a sort of half-desolate country;
but when we came to the mouth of the river which issues out of
Loch Awe, and which we had to cross by a ferry, looking up that
river we saw that the vale down which it flowed was richly wooded
and beautiful.
We were now among familiar fireside names. We could see the
town of Bunawe, a place of which the old woman with whom William
lodged ten years at Hawkshead used to tell tales half as long as an
ancient romance. It is a small village or port on the same side of
Loch Etive on which we stood, and at a little distance is a house built
by a Mr. Knott of Coniston Water-head, a partner in the iron-foundry
at Bunawe, in the service of whose family the old woman had spent
her youth. It was an ugly yellow-daubed building, staring this way
and that, but William looked at it with pleasure for poor Ann Tyson's
sake.9 We hailed the ferry-boat, and a little boy came to fetch us; he
rowed up against the stream with all his might for a considerable
way, and then yielding to it, the boat was shot towards the shore
almost like an arrow from a bow. It was pleasing to observe the
dexterity with which the lad managed his oars, glorying in the
appearance of danger—for he observed us watching him, and
afterwards, while he conveyed us over, his pride redoubled; for my
part, I was completely dizzy with the swiftness of the motion.
We could not have a boat from the ferry, but were told that if we
would walk to a house half a mile up the river, we had a chance of
getting one. I went a part of the way with William, and then sate
down under the umbrella near some houses. A woman came out to
talk with me, and pressed me to take shelter in her house, which I
refused, afraid of missing William. She eyed me with extreme
curiosity, asking fifty questions respecting the object of our journey.
She told me that it rained most parts of the year there, and that
there was no chance of fine weather that day; and I believe when
William came to tell me that we could have a boat, she thought I
was half crazed. We went down to the shore of the lake, and, after
having sate some time under a wall, the boatman came to us, and
we went upon the water. At first it did not rain heavily, and the air
was not cold, and before we had gone far we rejoiced that we had
not been faint-hearted. The loch is of a considerable width, but the
mountains are so very high that, whether we were close under them
or looked from one shore to the other, they maintained their dignity.
I speak of the higher part of the loch, above the town of Bunawe
and the large river, for downwards they are but hills, and the water
spreads out wide towards undetermined shores. On our right was
the mountain Cruachan, rising directly from the lake, and on the
opposite side another mountain, called Ben Durinish,10 craggy, and
exceedingly steep, with wild wood growing among the rocks and
stones.
We crossed the water, which was very rough in the middle, but
calmer near the shores, and some of the rocky basins and little
creeks among the rocks were as still as a mirror, and they were so
beautiful with the reflection of the orange-coloured seaweed growing
on the stones or rocks, that a child, with a child's delight in gay
colours, might have danced with joy at the sight of them. It never
ceased raining, and the tops of the mountains were concealed by
mists, but as long as we could see across the water we were
contented; for though little could be seen of the true shapes and
permanent appearances of the mountains, we saw enough to give
us the most exquisite delight: the powerful lake which filled the large
vale, roaring torrents, clouds floating on the mountain sides, sheep
that pastured there, sea-birds and land birds. We sailed a
considerable way without coming to any houses or cultivated fields.
There was no horse-road on either side of the loch, but a person on
foot, as the boatman told us, might make his way at the foot of Ben
Durinish, namely on that side of the loch on which we were; there
was, however, not the least track to be seen, and it must be very
difficult and laborious.
We happened to say that we were going to Glen Coe, which
would be the journey of a long day and a half, when one of the men,
pointing to the head of the loch, replied that if we were there we
should be but an hour's walk from Glen Coe. Though it continued
raining, and there was no hope that the rain would cease, we could
not help wishing to go by that way: it was an adventure; we were
not afraid of trusting ourselves to the hospitality of the Highlanders,
and we wanted to give our horse a day's rest, his back having been
galled by the saddle. The owner of the boat, who understood
English much better than the other man, his helper, said he would
make inquiries about the road at a farm-house a little further on. He
was very ready to talk with us, and was rather an interesting
companion; he spoke after a slow and solemn manner, in book and
sermon language and phrases:

A stately speech,
Such as grave livers do in Scotland use.11

When we came to the farm-house of which the man had spoken,


William and he landed to make the necessary inquiries. It was a
thatched house at the foot of the high mountain Ben Durinish—a
few patches or little beds of corn belonging to it; but the spot was
pastoral, the green grass growing to the walls of the house. The
dwelling-house was distinguished from the outer buildings, which
were numerous, making it look like two or three houses, as is
common in Scotland, by a chimney and one small window with sash-
panes; on one side was a little woody glen, with a precipitous
stream that fell into the bay, which was perfectly still, and bordered
with the rich orange-colour reflected from the sea-weed. Cruachan,
on the other side of the lake, was exceedingly grand, and appeared
of an enormous height, spreading out two large arms that made a
cove down which fell many streams swoln by the rain, and in the
hollow of the cove were some huts which looked like a village. The
top of the mountain was concealed from us by clouds, and the mists
floated high and low upon the sides of it.
William came back to the boat highly pleased with the cheerful
hospitality and kindness of the woman of the house, who would
scarcely permit him and his guide to go away without taking some
refreshment. She was the only person at home, so they could not
obtain the desired information; but William had been well repaid for
the trouble of landing; indeed, rainy as it was, I regretted that I had
not landed also, for I should have wished to bear away in my
memory a perfect image of this place,—the view from the doors, as
well as the simple Highland comforts and contrivances which were
near it. I think I never saw a retirement that would have so
completely satisfied me, if I had wanted to be altogether shut out
from the world, and at the same time among the grandest of the
works of God; but it must be remembered that mountains are often
so much dignified by clouds, mists, and other accidents of weather,
that one could not know them again in the full sunshine of a
summer's noon. But, whatever the mountains may be in their own
shapes, the farm-house with its pastoral grounds and corn fields
won from the mountain, its warm out-houses in irregular stages one
above another on the side of the hill, the rocks, the stream, and
sheltering bay, must at all times be interesting objects. The
household boat lay at anchor, chained to a rock, which, like the
whole border of the lake, was edged with sea-weed, and some
fishing-nets were hung upon poles,—affecting images, which led our
thoughts out to the wide ocean, yet made these solitudes of the
mountains bear the impression of greater safety and more deep
seclusion.
The rain became so heavy that we should certainly have turned
back if we had not felt more than usual courage from the pleasure
we had enjoyed, which raised hope where none was. There were
some houses a little higher up, and we determined to go thither and
make further inquiries. We could now hardly see to the other side of
the lake, yet continued to go on, and presently heard some people
pushing through a thicket close to us, on which the boatman called
out, "There's one that can tell us something about the road to Glen
Coe, for he was born there." We looked up and saw a ragged, lame
fellow, followed by some others, with a fishing-rod over his shoulder;
and he was making such good speed through the boughs that one
might have half believed he was the better for his lame leg. He was
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like