100% found this document useful (1 vote)
6 views

MATLAB Computer Vision Toolbox User s Guide The Mathworks instant download

The document is a user's guide for the MATLAB Computer Vision Toolbox, detailing installation, usage, and features of the toolbox. It includes links to various related MATLAB toolboxes and provides contact information for MathWorks. Additionally, it outlines a series of featured examples and revisions of the guide from its initial release to the latest version.

Uploaded by

pdtwziphue485
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
100% found this document useful (1 vote)
6 views

MATLAB Computer Vision Toolbox User s Guide The Mathworks instant download

The document is a user's guide for the MATLAB Computer Vision Toolbox, detailing installation, usage, and features of the toolbox. It includes links to various related MATLAB toolboxes and provides contact information for MathWorks. Additionally, it outlines a series of featured examples and revisions of the guide from its initial release to the latest version.

Uploaded by

pdtwziphue485
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/ 66

MATLAB Computer Vision Toolbox User s Guide The

Mathworks download

https://textbookfull.com/product/matlab-computer-vision-toolbox-
user-s-guide-the-mathworks/

Download full version ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

MATLAB Econometrics Toolbox User s Guide The Mathworks

https://textbookfull.com/product/matlab-econometrics-toolbox-
user-s-guide-the-mathworks/

MATLAB Bioinformatics Toolbox User s Guide The


Mathworks

https://textbookfull.com/product/matlab-bioinformatics-toolbox-
user-s-guide-the-mathworks/

MATLAB Mapping Toolbox User s Guide The Mathworks

https://textbookfull.com/product/matlab-mapping-toolbox-user-s-
guide-the-mathworks/

MATLAB Optimization Toolbox User s Guide The Mathworks

https://textbookfull.com/product/matlab-optimization-toolbox-
user-s-guide-the-mathworks/
MATLAB Trading Toolbox User s Guide The Mathworks

https://textbookfull.com/product/matlab-trading-toolbox-user-s-
guide-the-mathworks/

MATLAB Curve Fitting Toolbox User s Guide The Mathworks

https://textbookfull.com/product/matlab-curve-fitting-toolbox-
user-s-guide-the-mathworks/

MATLAB Fuzzy Logic Toolbox User s Guide The Mathworks

https://textbookfull.com/product/matlab-fuzzy-logic-toolbox-user-
s-guide-the-mathworks/

MATLAB Global Optimization Toolbox User s Guide The


Mathworks

https://textbookfull.com/product/matlab-global-optimization-
toolbox-user-s-guide-the-mathworks/

MATLAB Image Processing Toolbox User s Guide The


Mathworks

https://textbookfull.com/product/matlab-image-processing-toolbox-
user-s-guide-the-mathworks/
Computer Vision Toolbox™
User's Guide

R2020a
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.


1 Apple Hill Drive
Natick, MA 01760-2098
Computer Vision Toolbox™ User's Guide
© COPYRIGHT 2004–2020 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
July 2004 First printing New for Version 1.0 (Release 14)
October 2004 Second printing Revised for Version 1.0.1 (Release 14SP1)
March 2005 Online only Revised for Version 1.1 (Release 14SP2)
September 2005 Online only Revised for Version 1.2 (Release 14SP3)
November 2005 Online only Revised for Version 2.0 (Release 14SP3+)
March 2006 Online only Revised for Version 2.1 (Release 2006a)
September 2006 Online only Revised for Version 2.2 (Release 2006b)
March 2007 Online only Revised for Version 2.3 (Release 2007a)
September 2007 Online only Revised for Version 2.4 (Release 2007b)
March 2008 Online only Revised for Version 2.5 (Release 2008a)
October 2008 Online only Revised for Version 2.6 (Release 2008b)
March 2009 Online only Revised for Version 2.7 (Release 2009a)
September 2009 Online only Revised for Version 2.8 (Release 2009b)
March 2010 Online only Revised for Version 3.0 (Release 2010a)
September 2010 Online only Revised for Version 3.1 (Release 2010b)
April 2011 Online only Revised for Version 4.0 (Release 2011a)
September 2011 Online only Revised for Version 4.1 (Release 2011b)
March 2012 Online only Revised for Version 5.0 (Release 2012a)
September 2012 Online only Revised for Version 5.1 (Release R2012b)
March 2013 Online only Revised for Version 5.2 (Release R2013a)
September 2013 Online only Revised for Version 5.3 (Release R2013b)
March 2014 Online only Revised for Version 6.0 (Release R2014a)
October 2014 Online only Revised for Version 6.1 (Release R2014b)
March 2015 Online only Revised for Version 6.2 (Release R2015a)
September 2015 Online only Revised for Version 7.0 (Release R2015b)
March 2016 Online only Revised for Version 7.1 (Release R2016a)
September 2016 Online only Revised for Version 7.2 (Release R2016b)
March 2017 Online only Revised for Version 7.3 (Release R2017a)
September 2017 Online only Revised for Version 8.0 (Release R2017b)
March 2018 Online only Revised for Version 8.1 (Release R2018a)
September 2018 Online only Revised for Version 8.2 (Release R2018b)
March 2019 Online only Revised for Version 9.0 (Release R2019a)
September 2019 Online only Revised for Version 9.1 (Release R2019b)
March 2020 Online only Revised for Version 9.2 (Release R2020a)
Contents

Featured Examples
1
Localize and Read Multiple Barcodes in Image . . . . . . . . . . . . . . . . . . . . . 1-2

Monocular Visual Odometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22

Track Vehicles Using Lidar: From Point Cloud to Track List . . . . . . . . . . 1-35

Semantic Segmentation Using Dilated Convolutions . . . . . . . . . . . . . . . . 1-55

Define Custom Pixel Classification Layer with Tversky Loss . . . . . . . . . . 1-59

Track a Face in Scene . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-66

Create 3-D Stereo Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-71

Measure Distance from Stereo Camera to a Face . . . . . . . . . . . . . . . . . . . 1-72

Reconstruct 3-D Scene from Disparity Map . . . . . . . . . . . . . . . . . . . . . . . 1-74

Visualize Stereo Pair of Camera Extrinsic Parameters . . . . . . . . . . . . . . . 1-77

Remove Distortion from an Image Using the Camera Parameters Object


......................................................... 1-80

Point Cloud Processing


2
Getting Started with Point Clouds Using Deep Learning . . . . . . . . . . . . . . 2-2
Import Point Cloud Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Augment Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Encode Point Cloud Data to Image-like Format . . . . . . . . . . . . . . . . . . . . . 2-3
Train a Deep Learning Classification Network with Encoded Point Cloud
Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3

Point Cloud Registration Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4


Point Cloud Registration Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Point Cloud Registration Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6

The PLY Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8


File Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8

v
Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Common Elements and Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10

Using the Installer for Computer Vision System Toolbox


Product
3
Install Computer Vision Toolbox Add-on Support Files . . . . . . . . . . . . . . . 3-2

Install OCR Language Data Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3


Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
Pretrained Language Data and the ocr function . . . . . . . . . . . . . . . . . . . . 3-3

Install and Use Computer Vision Toolbox OpenCV Interface . . . . . . . . . . . 3-6


Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6
Support Package Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6
Create MEX-File from OpenCV C++ file . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7
Use the OpenCV Interface C++ API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7
Create Your Own OpenCV MEX-files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
Run OpenCV Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8

Install and Use Computer Vision Toolbox OpenCV Interface for Simulink
......................................................... 3-10
Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
Import OpenCV Code into Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-18

Smile Detection by Using OpenCV Code in Simulink . . . . . . . . . . . . . . . . 3-19


Required Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
Set Up Your C++ Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
Model Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
Step 1: Import OpenCV Function to Create a Simulink Library . . . . . . . . 3-20
Step 2: Use Generated Subsystem in Simulink Model . . . . . . . . . . . . . . . 3-25
Step 3: Simulate the Smile Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-26
Step 4: Generate C++ Code from the Smile Detector Model . . . . . . . . . . 3-26
Deploy the Smile Detector on the Raspberry Pi Hardware . . . . . . . . . . . . 3-27

Convert RGB Image to Grayscale Image by Using OpenCV Importer . . . 3-29


Required Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Set Up Your C++ Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Model Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-29
Step 1: Import OpenCV Function to Create a Simulink Library . . . . . . . . 3-30
Step 2: Use Generated Subsystem in Simulink Model . . . . . . . . . . . . . . . 3-33
Step 3: Simulate the RGB to Gray Convertor . . . . . . . . . . . . . . . . . . . . . . 3-34

Draw Different Shapes by Using OpenCV Code in Simulink . . . . . . . . . . 3-36


Required Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36
Set Up Your C++ Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36
Model Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-36
Step 1: Import OpenCV Function to Create a Simulink Library . . . . . . . . 3-37
Step 2: Use Generated Subsystem in Simulink Model . . . . . . . . . . . . . . . 3-38
Draw Atom on Image by Using C Caller Block . . . . . . . . . . . . . . . . . . . . . 3-38

vi Contents
Input, Output, and Conversions
4
Export to Video Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Setting Block Parameters for this Example . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Configuration Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3

Import from Video Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4


Setting Block Parameters for this Example . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Configuration Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5

Batch Process Image Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6


Configuration Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6

Convert R'G'B' to Intensity Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7

Process Multidimensional Color Video Signals . . . . . . . . . . . . . . . . . . . . . 4-10

Video Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12


Defining Intensity and Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12
Video Data Stored in Column-Major Format . . . . . . . . . . . . . . . . . . . . . . 4-12

Image Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13


Binary Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13
Intensity Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13
RGB Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13

Display and Graphics


5
Display, Stream, and Preview Videos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
View Streaming Video in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Preview Video in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
View Video in Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

Draw Shapes and Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4


Rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Line and Polyline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4
Polygon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6
Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6

Registration and Stereo Vision


6
Fisheye Calibration Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2
Fisheye Camera Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3
Fisheye Camera Calibration in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4

vii
Single Camera Calibrator App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
Camera Calibrator Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
Single Camera Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8
Open the Camera Calibrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Prepare the Pattern, Camera, and Images . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Add Images and Select Camera Model . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11
Calibrate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15
Evaluate Calibration Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-17
Improve Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-20
Export Camera Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-23

Stereo Camera Calibrator App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-25


Stereo Camera Calibrator Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-25
Stereo Camera Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-25
Open the Stereo Camera Calibrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26
Prepare Pattern, Camera, and Images . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26
Add Image Pairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-29
Calibrate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-31
Evaluate Calibration Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-31
Improve Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-35
Export Camera Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-37

What Is Camera Calibration? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-39


Camera Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-39
Pinhole Camera Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-40
Camera Calibration Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-41
Distortion in Camera Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-42

Structure from Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-45


Structure from Motion from Two Views . . . . . . . . . . . . . . . . . . . . . . . . . 6-45
Structure from Motion from Multiple Views . . . . . . . . . . . . . . . . . . . . . . 6-46

Object Detection
7
Getting Started with SSD Multibox Detection . . . . . . . . . . . . . . . . . . . . . . 7-2
Predict Objects in the Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
Transfer Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Design an SSD Detection Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Train an Object Detector and Detect Objects with an SSD Model . . . . . . . 7-4
Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4
Label Training Data for Deep Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4

Getting Started with Object Detection Using Deep Learning . . . . . . . . . . 7-6


Create Training Data for Object Detection . . . . . . . . . . . . . . . . . . . . . . . . 7-6
Create Object Detection Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
Train Detector and Evaluate Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
Detect Objects Using Deep Learning Detectors . . . . . . . . . . . . . . . . . . . . . 7-7

How Labeler Apps Store Exported Pixel Labels . . . . . . . . . . . . . . . . . . . . . 7-9


Location of Pixel Label Data Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9
View Exported Pixel Label Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9

viii Contents
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-10

Anchor Boxes for Object Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14


What Is an Anchor Box? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14
Advantage of Using Anchor Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14
How Do Anchor Boxes Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-15
Anchor Box Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18

Getting Started with YOLO v2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-19


Predicting Objects in the Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-19
Transfer Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-20
Design a YOLO v2 Detection Network . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-20
Train an Object Detector and Detect Objects with a YOLO v2 Model . . . . 7-21
Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21
Label Training Data for Deep Learning . . . . . . . . . . . . . . . . . . . . . . . . . . 7-21

Getting Started with R-CNN, Fast R-CNN, and Faster R-CNN . . . . . . . . . 7-23
Object Detection Using R-CNN Algorithms . . . . . . . . . . . . . . . . . . . . . . . 7-23
Comparison of R-CNN Object Detectors . . . . . . . . . . . . . . . . . . . . . . . . . 7-24
Transfer Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-25
Design an R-CNN, Fast R-CNN, and a Faster R-CNN Model . . . . . . . . . . . 7-25
Label Training Data for Deep Learning . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27

Getting Started with Semantic Segmentation Using Deep Learning . . . 7-29


Train a Semantic Segmentation Network . . . . . . . . . . . . . . . . . . . . . . . . 7-29
Label Training Data for Semantic Segmentation . . . . . . . . . . . . . . . . . . . 7-29

Training Data for Object Detection and Semantic Segmentation . . . . . . 7-31

Create Automation Algorithm for Labeling . . . . . . . . . . . . . . . . . . . . . . . . 7-35


Create New Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-35
Import Existing Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-36
Custom Algorithm Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-36

Label Pixels for Semantic Segmentation . . . . . . . . . . . . . . . . . . . . . . . . . . 7-39


Start Pixel Labeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-39
Label Pixels Using Flood Fill Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-40
Label Pixels Using Smart Polygon Tool . . . . . . . . . . . . . . . . . . . . . . . . . . 7-41
Label Pixels Using Polygon Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-43
Label Pixels Using Assisted Freehand Tool . . . . . . . . . . . . . . . . . . . . . . . 7-44
Replace Pixel Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-45
Refine Labels Using Brush Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-45
Visualize Pixel Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-46
Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-47

Get Started with the Image Labeler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-49


Load Unlabeled Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-49
Create Label Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-49
Label Ground Truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-56
Export Labeled Ground Truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-58
Save App Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-60

Choose an App to Label Ground Truth Data . . . . . . . . . . . . . . . . . . . . . . . 7-62

ix
Get Started with the Video Labeler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-64
Load Unlabeled Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-64
Set Time Interval to Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-64
Create Label Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-65
Label Ground Truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-72
Export Labeled Ground Truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-74
Label Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-76
Save App Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-77

Use Custom Image Source Reader for Labeling . . . . . . . . . . . . . . . . . . . . 7-79


Create Custom Reader Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-79
Import Data Source into Video Labeler App . . . . . . . . . . . . . . . . . . . . . . 7-79
Import Data Source into Ground Truth Labeler App . . . . . . . . . . . . . . . . 7-80

Use Sublabels and Attributes to Label Ground Truth Data . . . . . . . . . . . 7-81


When to Use Sublabels vs. Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-81
Draw Sublabels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-81
Copy and Paste Sublabels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-82
Delete Sublabels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-83
Sublabel Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-84

Temporal Automation Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-85


Create Temporal Automation Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 7-85
Run Temporal Automation Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-85

View Summary of Ground Truth Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-87


View Label Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-87
Compare Selected Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-89

Share and Store Labeled Ground Truth Data . . . . . . . . . . . . . . . . . . . . . . 7-91


Share Ground Truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-91
Move Ground Truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-94
Store Ground Truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-95

Keyboard Shortcuts and Mouse Actions for Image Labeler . . . . . . . . . . . 7-97


Label Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-97
Image Browsing and Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-97
Labeling Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-97
Polyline Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-98
Polygon Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-98
Zooming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-99
App Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-99

Keyboard Shortcuts and Mouse Actions for Video Labeler . . . . . . . . . . 7-100


Label Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-100
Frame Navigation and Time Interval Settings . . . . . . . . . . . . . . . . . . . . 7-100
Labeling Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-100
Polyline Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-101
Polygon Drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-101
Zooming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-102
App Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-102

Point Feature Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-103


Functions That Return Points Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 7-103
Functions That Accept Points Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 7-105

x Contents
Local Feature Detection and Extraction . . . . . . . . . . . . . . . . . . . . . . . . . 7-109
What Are Local Features? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-109
Benefits and Applications of Local Features . . . . . . . . . . . . . . . . . . . . . 7-109
What Makes a Good Local Feature? . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-110
Feature Detection and Feature Extraction . . . . . . . . . . . . . . . . . . . . . . 7-110
Choose a Feature Detector and Descriptor . . . . . . . . . . . . . . . . . . . . . . 7-111
Use Local Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-112
Image Registration Using Multiple Features . . . . . . . . . . . . . . . . . . . . . 7-114

Train a Cascade Object Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-122


Why Train a Detector? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-122
What Kinds of Objects Can You Detect? . . . . . . . . . . . . . . . . . . . . . . . . 7-122
How Does the Cascade Classifier Work? . . . . . . . . . . . . . . . . . . . . . . . . 7-122
Create a Cascade Classifier Using the trainCascadeObjectDetector . . . 7-123
Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-126
Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-128
Train Stop Sign Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-132

Train Optical Character Recognition for Custom Fonts . . . . . . . . . . . . . 7-135


Open the OCR Trainer App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-135
Train OCR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-135
App Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-137

Troubleshoot ocr Function Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-139


Performance Options with the ocr Function . . . . . . . . . . . . . . . . . . . . . 7-139

Create a Custom Feature Extractor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-140


Example of a Custom Feature Extractor . . . . . . . . . . . . . . . . . . . . . . . . 7-140

Image Retrieval with Bag of Visual Words . . . . . . . . . . . . . . . . . . . . . . . 7-143


Retrieval System Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-144
Evaluate Image Retrieval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-145

Image Classification with Bag of Visual Words . . . . . . . . . . . . . . . . . . . . 7-146


Step 1: Set Up Image Category Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-146
Step 2: Create Bag of Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-146
Step 3: Train an Image Classifier With Bag of Visual Words . . . . . . . . . 7-147
Step 4: Classify an Image or Image Set . . . . . . . . . . . . . . . . . . . . . . . . . 7-148

Motion Estimation and Tracking


8
Multiple Object Tracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Prediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Data Association . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Track Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4

Video Mosaicking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5

Pattern Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-10

xi
Pattern Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-15

Geometric Transformations
9
Nearest Neighbor, Bilinear, and Bicubic Interpolation Methods . . . . . . . 9-2
Nearest Neighbor Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Bilinear Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3
Bicubic Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3

Filters, Transforms, and Enhancements


10
Adjust the Contrast of Intensity Images . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2

Adjust the Contrast of Color Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-6

Remove Salt and Pepper Noise from Images . . . . . . . . . . . . . . . . . . . . . 10-10

Sharpen an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-14

Statistics and Morphological Operations


11
Correct Nonuniform Illumination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2

Count Objects in an Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8

Fixed-Point Design
12
Fixed-Point Signal Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
Fixed-Point Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
Benefits of Fixed-Point Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
Benefits of Fixed-Point Design with System Toolboxes Software . . . . . . . 12-2

Fixed-Point Concepts and Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-4


Fixed-Point Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-4
Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-5
Precision and Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-6

xii Contents
Arithmetic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8
Modulo Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8
Two's Complement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8
Addition and Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-9
Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-10
Casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-12

Fixed-Point Support for MATLAB System Objects . . . . . . . . . . . . . . . . . 12-15


Getting Information About Fixed-Point System Objects . . . . . . . . . . . . . 12-15
Setting System Object Fixed-Point Properties . . . . . . . . . . . . . . . . . . . . 12-15

Specify Fixed-Point Attributes for Blocks . . . . . . . . . . . . . . . . . . . . . . . . 12-17


Fixed-Point Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-17
Specify System-Level Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-19
Inherit via Internal Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-19
Specify Data Types for Fixed-Point Blocks . . . . . . . . . . . . . . . . . . . . . . . 12-26

Code Generation and Shared Library


13
Simulink Shared Library Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2

Accelerating Simulink Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-3

Portable C Code Generation for Functions That Use OpenCV Library . . 13-4
Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-4

xiii
1

Featured Examples

• “Localize and Read Multiple Barcodes in Image” on page 1-2


• “Monocular Visual Odometry” on page 1-22
• “Track Vehicles Using Lidar: From Point Cloud to Track List” on page 1-35
• “Semantic Segmentation Using Dilated Convolutions” on page 1-55
• “Define Custom Pixel Classification Layer with Tversky Loss” on page 1-59
• “Track a Face in Scene” on page 1-66
• “Create 3-D Stereo Display” on page 1-71
• “Measure Distance from Stereo Camera to a Face” on page 1-72
• “Reconstruct 3-D Scene from Disparity Map” on page 1-74
• “Visualize Stereo Pair of Camera Extrinsic Parameters” on page 1-77
• “Remove Distortion from an Image Using the Camera Parameters Object” on page 1-80
1 Featured Examples

Localize and Read Multiple Barcodes in Image


This example shows how to use the readBarcode function from the Computer Vision Toolbox™ to
detect and decode 1-D and 2-D barcodes in an image. Barcodes are widely used to encode data in a
visual, machine-readable format. They are useful in many applications such as item identification,
warehouse inventory tracking, and compliance tracking. For 1-D barcodes, the readBarcode
function returns the location of the barcode endpoints. For 2-D barcodes, the function returns the
locations of the finder patterns. This example uses two approaches for localizing multiple barcodes in
an image. One approach is clustering-based, which is more robust to different imaging conditions and
requires the Statistics and Machine Learning Toolbox™. The second approach uses a segmentation-
based workflow and might require parameter tuning based on the imaging conditions.

Barcode Detection using the readBarcode Function

Read a QR code from an image.

I = imread("barcodeQR.jpg");

% Search the image for a QR Code.


[msg, ~, loc] = readBarcode(I);

% Annotate the image with the decoded message.


xyText = loc(2,:);
Imsg = insertText(I, xyText, msg, "BoxOpacity", 1, "FontSize", 25);

% Insert filled circles at the finder pattern locations.


Imsg = insertShape(Imsg, "FilledCircle", [loc, ...
repmat(10, length(loc), 1)], "Color", "red", "Opacity", 1);

% Display image.
imshow(Imsg)

1-2
Localize and Read Multiple Barcodes in Image

Read a 1-D barcode from an image.

I = imread("barcode1D.jpg");

% Read the 1-D barcode and determine the format..


[msg, format, locs] = readBarcode(I);

% Display the detected message and format.


disp("Detected format and message: " + format + ", " + msg)

Detected format and message: EAN-13, 1234567890128

% Insert a line to show the scan row of the barcode.


xyBegin = locs(1,:); imSize = size(I);
I = insertShape(I,"Line",[1 xyBegin(2) imSize(2) xyBegin(2)], ...
"LineWidth", 7);

% Insert markers at the end locations of the barcode.


I = insertShape(I, "FilledCircle", [locs, ...
repmat(10, length(locs), 1)], "Color", "red", "Opacity", 1);

1-3
1 Featured Examples

% Display image.
imshow(I)

Improving Barcode Detection

For a successful detection, the barcode must be clearly visible. The barcode must also be as closely
aligned to a horizontal or vertical position as possible. The readBarcode function is inherently more
robust to rotations for 2-D or matrix codes than it is to 1-D or linear barcodes. For example, the
barcode cannot be detected in this image.

I = imread("rotated1DBarcode.jpg");

% Display the image.


imshow(I)

1-4
Localize and Read Multiple Barcodes in Image

% Pass the image to the readBarcode function.


readBarcode(I)

ans =
""

Rotate the image using the imrotate so that the barcode is roughly horizontal. Use readBarcode
on the rotated image.

% Rotate the image by 30 degrees clockwise.


Irot = imrotate(I, -30);

% Display the rotated image.


imshow(Irot)

1-5
1 Featured Examples

% Pass the rotated image to the readBarcode function.


readBarcode(Irot)

ans =
"012345678905"

Detect Multiple Barcodes

The readBarcode function detects only a single barcode in each image. In order to detect multiple
barcodes, you must specify a region-of-interest (ROI). To specify an ROI, you can use the
drawrectangle function to interactively determine the ROIs. You can also use image analysis
techniques to detect the ROI of multiple barcodes in the image.

1-6
Localize and Read Multiple Barcodes in Image

Interactively determine ROIs

I = imread("multiple1DBarcodes.jpg");

1-7
1 Featured Examples

Use the drawrectangle function to draw and obtain rectangle parameters.

roi1 = drawrectangle;

pos = roi1.Position;

% ROIs obtained using drawrectangle


roi = [350 190 690 370
350 640 690 360
350 1090 690 340];

imSize = size(I);
for i = 1:size(roi,1)
[msg, format, locs] = readBarcode(I, roi(i,:));
disp("Decoded format and message: " + format + ", " + msg)

% Insert a line to indicate the scan row of the barcode.


xyBegin = locs(1,:);
I = insertShape(I,"Line",[1 xyBegin(2) imSize(2) xyBegin(2)], ...
"LineWidth", 7);

% Annotate image with decoded message.


I = insertText(I, xyBegin, msg, "BoxOpacity", 1, "FontSize", 30);
end

Decoded format and message: UPC-A, 012345678905


Decoded format and message: EAN-13, 4567891324562
Decoded format and message: CODE-39, ABC-123

imshow(I)

1-8
Localize and Read Multiple Barcodes in Image

Image analysis to determine ROIs

Use image analysis techniques to automate the detection of multiple barcodes. This requires
localizing multiple barcodes in an image, determining their orientation, and correcting for the
orientation. Without preprocessing, barcodes cannot be detected in the image containing multiple
rotated barcodes.

1-9
1 Featured Examples

I = imread("multiple1DBarcodesRotated.jpg");
Igray = rgb2gray(I);

% Display the image.


imshow(I)

% Pass the unprocessed image to the readBarcode function.


readBarcode(Igray, '1D')

ans =
""

Detection on the unprocessed image resulted in no detection.

Step 1: Detect candidate regions for the barcodes using MSER

Detect regions of interest in the image using the detectMSERFeatures function. Then, you can
eliminate regions of interest based on a specific criteria such as the aspect ratio. You can use the
binary image from the filtered results for further processing.

1-10
Localize and Read Multiple Barcodes in Image

% Detect MSER features.


[~, cc] = detectMSERFeatures(Igray);

% Compute region properties MajorAxisLength and MinorAxisLength.


regionStatistics = regionprops(cc, 'MajorAxisLength', 'MinorAxisLength');

% Filter out components that have a low aspect ratio as unsuitable


% candidates for the bars in the barcode.
minAspectRatio = 10;
candidateRegions = find(([regionStatistics.MajorAxisLength]./[regionStatistics.MinorAxisLength])

% Binary image to store the filtered components.


BW = false(size(Igray));

% Update the binary image.


for i = 1:length(candidateRegions)
BW(cc.PixelIdxList{candidateRegions(i)}) = true;
end

% Display the binary image with the filtered components.


imshow(BW)
title("Candidate regions for the barcodes")

1-11
1 Featured Examples

Step 2: Extract barcode line segments using hough transform

Detect prominent edges in the image using the edge function. Then use the hough transform to find
lines of interest. The lines represent possible candidates for the vertical bars in the barcode.

% Perform hough transform.


BW = edge(BW,'canny');
[H,T,R] = hough(BW);

% Display the result of the edge detection operation.


imshow(BW)

1-12
Exploring the Variety of Random
Documents with Different Content
vainotanterille; somap' on sotahan kuolla, kaunis miekan
kalskehesen, sorea sotainen tauti, äkin poika pois tulevi,
potematta pois menevi, laihtumatta lankeavi.

ÄITI

Kun sinä sotahan kuolet, mitä jääpi taatollesi vanhan


päivänsä varaksi?

KULLERVO

Kuolkohon kujarikoille, kaatukohon kartanolle!

ÄITI (valittaen)

Mitä jääpi maammollesi vanhan päivänsä varaksi?

KULLERVO

Kuolkohon kupo sylihin, läävähän läkähtyköhön!

ÄITI (aina surkeammin)

Mitä jääpi veikollesi päivän vastaisen varaksi?

KULLERVO

Metsähän menettyköhön, vainiolle vaipukohon!

ÄITI

Mitä jääpi siskollesi päivän vastaisen varaksi?


KULLERVO

Kaivotielle kaatukohon, sotkutielle sortukohon!

(Kalervo tulee vasemmalta.)

Hyvästi, hyvä isoni! Itketkö sinä minua, koskas kuulet


kuolleheksi?

KALERVO (raskaasti)

En minä sinua itke; poika toinen tehtänehe, poika paljoa


parempi.

KULLERVO

Enkä itke mie sinua; saan minä mokoman taaton, suun


savesta, pään kivestä, silmät suolta karpaloista.

(Veli tulee vasemmalta.)

Jää hyvästi, veikkoseni! Itketkö sinä minua, koskas kuulet


kuolleheksi?

VELI

En itke minä sinua; veli toinen saatanehe, veli paljoa


parempi.

KULLERVO (aina katkerampana)

Enkä itke mie sinua; saan minä mokoman veljen hiukset


kuivista kuloista, jalat raian haarukasta.
(Toinen sisar tulee vasemmalta.)

Hyvästi, sisarueni! Itketkö sinä minua, koskas kuulet


kuolleheksi?

TOINEN SISAR

En itke minä sinua; veli toinen saatanehe, veli paljoa


parempi.

KULLERVO

Enkä itke mie sinua; saan minä mokoman siskon korvat


lammin lumpehista, varren vaahteren vesasta!

(Kääntyy äitinsä puoleen.)

Äitiseni, armaiseni, minun kaunis kantajani, kultainen


kulettajani! Itketkö sinä minua, koskas kuulet kuolleheksi?

ÄITI (katsoo surullisesti häneen)

Et älyä äitin mieltä, arvoa emon syäntä, itkenpä minä sinua,


kun sun kuulen kuolleheksi, itken tulville tupamme, siltalauat
lainehille, kujat kaikki kuurullani; lumet itken iljeniksi, iljenet
suliksi maiksi, sulat maat vihottaviksi, vihottavat viereviksi.

(Itkee hänet syliinsä. Itkee valtoinaan. Muut kääntyvät hitaasti


pois.
Pitkä vaitiolo. Kullervo irtautuu lempeästi hänen syleilystään.
Äiti poistuu itkuaan pidättäen vasemmalle. Kullervo jää
murhemielisenä
hänen jälkeensä katsomaan. Äkkiä kuin heräten:)
KULLERVO

Viel' on Unto kostamatta, mies katala kaatamatta, ilkeä


hävittämättä!

ESILAUSUJA

Kullervo, Kalervon poika, sinisukka äijön lapsi, läksi soitellen


sotahan, ilotellen tappelohon; soitti suolla, soitti maalla,
kajahutti kankahalla, rojahutti ruohikossa, kulahutteli kulossa.

(Kullervon torvi kuuluu vasemmalta karsikosta.)

1:NEN VUOROLAUSUJA

Saip' on miekan mielehisen, kalvan kaikkien parahan, jolla


kaatoi kaiken kansan, joukon Untamon hävitti; tuvat poltteli
poroksi, kypeniksi kyyätteli, kivet jätti kiukahista, pitkän
pihlajan pihoista.

2:NEN VUOROLAUSUJA

Kullervo, Kalervon poika, jo tuosta kotihin kääntyi ison


entisen tuville, vanhempansa vainioille; tupa on tyhjä
tultuansa, autio avattuansa, ei tulla likistämähän, käyä kättä
antamahan.

1:NEN VUOROLAUSUJA

Antoi kättä hiilokselle: hiilet kylmät kiukahassa; tuosta tunsi


tultuansa, ei ole emo elossa.
2:NEN VUOROLAUSUJA

Pisti kättä kiukahalle: kivet kylmät kiukahassa; tuosta tunsi


tultuansa, ei ole iso elossa.

1:NEN VUOROLAUSUJA

Loi on silmät sillan päälle: silta kaikki siivomatta; tuosta


tunsi tultuansa, ei ole sisar elossa.

2:NEN VUOROLAUSUJA

Vieri valkamavesille: ei venettä valkamassa, tuosta tunsi


tultuansa, ei ole veli elossa.

(Kullervo tulee synkkänä ja vitkalleen karsikosta.)

KULLERVO

Voi minä, poloinen poika, kun kuoli emo minulta, uupui


uutimen tekijä, vaipui vaipan kirjoittaja; enk' ollut luona
luopuessa, läsnä hengen lähtiessä, lie kuollut kovin viluhun,
vainko leivän puuttehesen.

(Siniviitta Viian eukko tulee vasemmalta.)

VIIAN EUKKO

Jäip' on sulle Musti koira käyäksesi metsämaille; ota koirasi


keralle, mene tuonne metsämaille, ylös korpehen kohoa
metsän tyttöjen tyköhön, sinipiikojen pihalle, havulinnan
liepehille, evähiä etsimähän, antia anelemahan.
(Kullervo nyykäyttää raskasmielisesti päätään hänelle ja etenee
vasemmalle etualalle.)

ESILAUSUJA

Kullervo, Kalervon poika, otti koiransa keralle, läksi tietä


telkkimähän, korpehen kohoamahan; kävi matkoa vähäisen,
tuli tuolle saarekselle, kuss' oli piian pillannunna, turmellut
emonsa tuoman.

VUOROLAUSUJAT (hiljaa)

Siin' itki ihana nurmi, aho armahin valitti, eikä nousnut


nuori heinä, kasvanut kanervan kukka, ylennyt sijalla sillä,
tuolla paikalla pahalla, kuss' oli piian pillannunna, emon
tuoman turmellunna.

(Kullervo vetää hitaasti miekan huotrastaan ja katsoo synkkänä


sen terää.)

KULLERVO

Tokko tuon tekisi mieli syöä syyllistä lihoa, viallista verta


juoa?

VIIAN EUKKO (hiljaa)

Miks ei söisi mielellänsä, söisi syyllistä lihoa, viallista verta


joisi? Syö lihoa syyttömänki, juo verta viattomanki.

(Kullervo lankeaa äkisti miekkaansa.)

KUORO
Se oli surma nuoren miehen, kuolo Kullervo urohon!

ESILAUSUJA

Elkötte, etinen kansa, lasta kaltoin kasvatelko luona tuhman


tuuittajan, vierahan väsyttelijän! Lapsi kaltoin kasvattama,
poika tuhmin tuuittama, ei tule älyämähän, miehen mieltä
ottamahan, vaikka vanhaksi eläisi, varreltansa vahvistuisi.

ESIRIPPU.
SAMMON RYÖSTÖ

HENKILÖT:

VÄINÄMÖINEN. ILMARINEN. LEMMINKÄINEN LOUHI. KANTELETAR.


KUORO.

(Kuoro paikallaan uhrlkuusen alla. Valaistus: hämärtyvä ilta, joku


tähti takaisella taivaankannella.)

ESILAUSUJA

Se on seppo Ilmarinen naista itki illat kaiket, yöt itki


unettomana, päivät einehettömänä, aamut aikaisin valitti,
huomeniset huokaeli, kun oli kuollut nuori nainen, kaunis
kalmahan katettu, eipä kääntynyt käessä vaskinen vasaran
varsi, kuulunut pajasta kalke yhen kuuhuen kululla.

(Ilmarinen tulee hitaasti ja murhemielisenä oikealta karsikosta.)

ILMARINEN (raskaasti)

En tieä, poloinen poika, miten olla, kuin eleä; istun yön eli
makoan, äijä on yötä, tunti tuhma, vaivoja, matala mahti.
Ikävät on iltaseni, apeat on aamuseni, äsken yöllä
äitelämpi, havatessa haikeampi; ei ole iltoja ikävä, ei apea
aamujani, mure muita aikojani: ihanaistani ikävä, apeainen
armastani, mure mustakulmaistani.

Jo vainen iällä tällä usein minun utuisen keski-öisissä unissa


koura tyhjeä kokevi, käsi vaalivi valetta kupehelta kummaltaki.

(Etenee hitaasti vasemmalle.)

1:NEN VUOROLAUSUJA

Lähteäksensä lupasi sekä mietti mennäksensä pyytämähän


Pohjolasta toista Pohjolan tytärtä.

2:NEN VUOROLAUSUJA

Sai päivän ajaneheksi, tuosta toisen vierneheksi, päivälläpä


kolmannella tuli Pohjolan pihalle.

(Louhi tulee vasemmalta. Ilmarinen tekee torjuvan liikkeen


kädellään.)

ILMARINEN

Ellös nyt, anoppiseni, ellös sie kyselkö tuota elämiä


tyttäresi, asuntoa armahasi! Jo sen on surma suin piellyt,
kova loppu loukahtanut; maassa on jo marjaseni, kankahassa
kaunoseni, mustakulmani kulossa, hopeani heinikossa.

(Voi tuskin pidättää itkuaan enää. Vaitiolo.)


Annapa, anoppiseni, työnnä toinen tyttäresi naisen entisen
eloille, sijalle sisaruensa!

LOUHI (voivotellen)

Pahoin tein minä poloinen, kun ma lapseni lupasin, työnsin


sulle toisenkana nuorena nukahtamahan, annoin kuin sutosen
suuhun, karhun kiljuvan kitahan. (Äkeästi.) En nyt toista
annakana nokiesi nuoliojaksi, ennen työnnän tyttäreni, laitan
lapseni vakavan koskehen kohisevahan, Tuonen hau'in
hampahisin.

(Menee tuimana vasemmalle. Ilmarinen suuttuneena seuraa


häntä. Palajaa hetken perästä takaisin allapäin ja pahoilla mielin.
Väinämöinen tulee oikealta taustasta.)

VÄINÄMÖINEN

Veli, seppo Ilmarinen, mit' olet pahoilla mielin, kahta kallella


kypärin Pohjolasta tullessasi? Miten Pohjola elävi?

ILMARINEN (katkerasti)

Mi on Pohjolan eleä, kun on Sampo Pohjolassa! Siin' on


kyntö, siin' on kylvö, siinä kasvu kaikenlainen, siinäpä ikuinen
onni.

VÄINÄMÖINEN

Ohoh seppo Ilmarinen, lähtekämme Pohjolahan hyvän


Sammon saa'antahan, kirjokannen katsantahan.

ILMARINEN (päätä pudistaen)


Ei ole Sampo saatavana pimeästä Pohjolasta! Siell' on
Sampo saatettuna, kirjokansi kannettuna Pohjolan
kivimäkehen, vaaran vaskisen sisähän, yheksän lukon ta'aksi;
siihen juuret juurruteltu.

VÄINÄMÖINEN

Laatikamme laiva suuri, johon Sampo saatetahan vaaran


vaskisen sisästä.

ILMARINEN

Vakavampi maisin matka, Lempo menköhön merelle, Surma


suurelle selälle! Siellä tuuli turjuttaisi, siellä viskaisi vihuri saisi
sormet soutimeksi, kämmenet käsimeloiksi.

VÄINÄMÖINEN

Vakavampi maisin matka, vakavampi, vaikeampi, vielä


muuten mutkaisempi; lysti on venon vesillä, purren juosta
jolkutella, ve'et väljät välkytellä; aalto laivoa ajavi, länsituuli
läikyttävä, etelä e'elle viepi; vaan kuitenki, kaikitenki, kun et
mieline merisin, niin on maisin matkatkamme.

Tao nyt mulle uusi miekka, tee miekka tuliteräinen, jolla


hurttia hutelen, Pohjan kansan kaikottelen saaessa otolle
Sammon tuonne kylmähän kylähän.

(Menevät oikealle taustaan. Palajavat hetken perästä,


Väinämöinen miekka kädessään.)

VÄINÄMÖINEN
Onko miekka miestä myöten, kalpa kantajan mukahan?

ESILAUSUJA

Olipa miekka miestä myöten, kalpa kantajan mukahan,


jonka kuu kärestä paistoi, päivä paistoi lappeasta, tähet
västistä välötti, hevonen terällä hirnui, kasi naukui naulan
päässä, penu putkessa puhusi.

VÄINÄMÖINEN (miekkaansa hujautellen)

Jo minä terällä tällä vaikka vuoret poikki löisin, kalliot kaha


jakaisin.

ILMARINEN

Milläpä minä poloinen, millä, tuima, turveleime, hyöteleime,


vyöteleime maan varalle, veen varalle?

VÄINÄMÖINEN

Mies on luustossa lujempi, rautapaiassa parempi,


teräsvyössä tenhoisampi.

(Ilmarinen viittaa oikealle taustaan. Orja tuo sotavarukset, joihin


hän nopeasti pukeutuu. Lemminkäinen tulee oikealta taustasta ja
tervehtii heitä.)

LEMMINKÄINEN

Minnekä menette miehet?

VÄINÄMÖINEN
Kohti pohjaista kulemme
Sampoa tapoamahan,
kirjokantta katsomahan
Pohjolan kivimäestä.

LEMMINKÄINEN (Ilahtuen)

Ohoh vanha Väinämöinen! Otapa minua, miestä, urohoksi


kolmanneksi kirjokannen kannantahan! Vielä mieli miestä
maksan, jos saisi tapella tarve, annan käskyn kämmenille,
olkapäilleni opaston.

(Väinämöinen nyykäyttää päätään hänelle. Sankarit neuvottelevat


keskenään. Kanteletar näkymättömänä nyyhkii oikealla. Väinämöinen
kuuntelee ja viittaa oikealle.)

VÄINÄMÖINEN

Siell' on impi itkemässä, kana kaikerrehtamassa.

ILMARINEN (katsoo oikealle)

Onpa pursi itkemässä, venonen valittamassa.

VÄINÄMÖINEN

Mitä itket, puinen pursi, vene hankava, valitat, itketkö sa


puisuuttasi, hankavuuttasi haveksit?

KANTELETAR

Vesille venosen mieli tervaisiltaki teloilta, mieli neien


miehelähän korkeastaki koista; sitä itken, pursi-raukka, vene
vaivainen, valitan, itken viejäistä vesille, laskijata lainehille.

Sanottihin tehtäessä, laulettihin laitettaissa saatavan


sotivenettä, vainopurtta puuhattavan, tuovan täyteni eloa,
alustani aartehia; ei ole sotahan saatu, eloteillen ensinkänä.

Oisi kahta kaunihimpi olla mäntynä mäellä, petäjänä


kankahalla, oksilla oravan juosta, penun alla pyörähellä.

VÄINÄMÖINEN

Elä itke, puinen pursi!


Kohta saat sotia käyä.

(Sankarit jatkavat neuvotteluaan.)

ESILAUSUJA

Siitä vanha Väinämöinen lauloa hyrähtelevi; lauloi ensin


laitapuolen sukapäitä sulhosia, lauloi toisen laitapuolen
tinapäitä tyttäriä, tinapäitä, vaskivöitä, kultasormia somia.

1:NEN VUOROLAUSUJA

Jopa juoksi puinen pursi, pursi juoksi, matka joutui, loitos


kuului airon loiske, kauas hankojen havina.

2:NEN VUOROLAUSUJA

Vaka vanha Väinämöinen laskea karehtelevi, laski laulellen


vesiä, ilon lyöen lainehia.

1:NEN VUOROLAUSUJA
Neiet niemien nenissä katselevat, kuuntelevat: "Mi lienee ilo
merellä, mikä laulu lainehilla?"

2:NEN VUOROLAUSUJA

Laski vanha Väinämöinen laski päivän maavesiä, päivän


toisen suovesiä, kolmannen kosen vesiä.

MOLEMMAT (hilpeästi)

Soutavi sorehtelevi, teljot rytkyi, laiat notkui, airot piukki


pihlajaiset, airon pyörät pyinä vinkui, terät teirinä kukerti,
nenä joikui joutsenena, perä kaarskui kaarnehena, hangat
hanhina havisi.

(Sankarit etenevät vasemmalle. Louhi tulee heitä vastaan.)

LOUHI

Mipä miehillä sanoma, urohilla uusi tieto?

VÄINÄMÖINEN

Sammosta sanomat miesten, kirjokannesta urosten;


saimme Sampuen jaolle, kirjokannen katselulle.

LOUHI (nokkelasti)

Ei pyyssä kahen jakoa, oravassa miehen kolmen; hyvä on


Sampuen hyrätä Pohjolan kivimäessä, hyvä olla itseniki
Sammon suuren haltiana.

VÄINÄMÖINEN
Kun et antane osoa, tuota Sammon toista puolta, niin on
kaiken kantanemme, vienemme venehesemme.

(Menevät vasemmalle. Louhi hätääntyneenä seuraa heitä. Kuoro


on noussut ja katsoo jännityksellä vasemmalle.)

KUORO

Saivat Sammon purtehensa, kirjokannen kaarillensa,


työntivät venon vesille, satalauan lainehille!

ILMARINEN (huutaa vasemmalta)

Minne Sampo saatetahan?

VÄINÄMÖINEN (vastaa hänelle vasemmalta)

Tuonne Sampo saatetahan nenähän utuisen niemen,


päähän saaren terhenisen.

(Louhi syöksyy epätoivoisena vasemmalta.)

LOUHI (kätensä kohottaen)

Ututyttö, terhenneiti! Seulo seulalla utua, laske talma


taivahalta, jottei päästä Väinämöisen osata Uvantolaisen!

Iku-Turso, Äijön poika, nosta päätäsi merestä, kaataos


Kalevan miehet, hävitä häjyt urohot, saata Sampo Pohjolahan
venehestä vierimättä.

Oi Ukko, ylijumala, rakenna rajuinen ilma, nosta suuri säien


voima, luo tuuli, lähetä aalto aivan vastahan venettä.
(Näyttämö pimenee.)

ESILAUSUJA (voimakkaasti)

Nousi tuulet tuulemahan, säät rajut rajuamahan; kovin


läikkyi länsituuli, luoetuuli tuikutteli, enemmän etelätuuli, itä
inkui ilkeästi, kauheasti kaakko karjui, pohjonen kovin porasi.

1:NEN VUOROLAUSUJA

Tuuli puut lehettömäksi, havupuut havuttomaksi, kanervat


kukattomaksi, heinät helpehettömäksi; nosti mustia muria
päälle selvien vesien.

2:NEN VUOROLAUSUJA

Louhi, Pohjolan emäntä, kutsui Pohjolan kokohon, pani


joukon jousihinsa, laittoi miehet miekkoihinsa, rakenteli
Pohjan purren, suoritti sotavenosen,

1:NEN VUOROLAUSUJA

Latoi miestä laivahansa suoritti sota-urohot, kuni sotka


poikasensa, tavi lapsensa latovi, sata miestä miekallista, tuhat
jousella urosta.

2:NEN VUOROLAUSUJA

Kohenteli purjepuita, vaatevarpoja varasi, nosti puuhun


purjehia, vaattehia varpapuihin, kuin on pitkän pilven longan,
pilven tönkän taivahalla.
(Näyttämöllä on melkein pimeä. Sankarit, samoin kuin Kuoron
jäsenetkin, vain epäselvinä hahmoviivoina.)

ILMARISEN ÄÄNI (kuuluu pimeydestä)

Voi, poloinen, päiviäni! Jo on tukka tuulta nähnyt, hivus


säätä hirveätä, parta päiviä pahoja, nähnyt näilläki vesillä;
harvoin on havaita tainnut tuulta ennen tuon näköistä.

VÄINÄMÖISEN ÄÄNI

Itku ei hä'ästä päästä, parku päivistä pahoista.

Oi sie lieto Lemmin poika, nouse purjepuun nenähän,


katsaise etinen ilma, tarkkoa takainen taivas, onko selvät
ilman rannat.

LEMMINKÄISEN ÄÄNI

Selvänä etinen ilma, taakea takainen taivas; pieni on pilvi


pohjosessa, pilven lonka luotehessa.

VÄINÄMÖISEN ÄÄNI

Se on pursi purjehinen; katso toisti tarkemmasti.

LEMMINKÄISEN ÄÄNI

Saari kaukoa näkyvi, etähältä haamottavi, havukoita haavat


täynnä, koivut kirjokoppeloita.

VÄINÄMÖISEN ÄÄNI
Ne on Pohjan poikasia; katso tarkoin kolmannesti!

LEMMINKÄISEN ÄÄNI (hätääntyneenä)

Jo tulevi Pohjan pursi, satahanka hakkoavi, sata on miestä


soutimilla, tuhat ilman istumassa.

VÄINÄMÖISEN ÄÄNI

Soua, seppo Ilmarinen, soua, lieto Lemminkäinen,


soutakatte, kaikki kansa, jotta juoksisi venonen, pursi eellä
ennättäisi!

VUOROLAUSUJA!

Lyllyivät melat lylyiset. hangat piukki pihlajaiset, vene


honkainen vapisi, nenä hyrski hylkehenä, perä koskena kohisi,
vesi kiehui kelloloissa, vaahti palloissa pakeni.

ESILAUSUJA

Kilvan kiskoivat urohot, miehet veikaten vetivät; eipä matka


eistykänä, ei pakene puinen pursi eestä purren purjehisen
tuon on Pohjolan venosen.

VÄINÄMÖISEN ÄÄNI

Salasaari kasvakohon, johon juosta Pohjan purren!

KUORO
Lenti poikki puinen pursi, satakaari katkieli, mastot
maiskahti merehen, purjehet putoelivat.

Louhi, Pohjolan emäntä, tohti toisiksi ruveta, otti viisi


viikatetta, nepä kynsiksi kyhäsi, puolen purtta särkynyttä,
senpä allensa asetti, laiat siiviksi sivalti, peräpuikon
purstoksensa, sata miestä siiven alle, tuhat purston
tutkaimehen, sata miestä miekallista, tuhat ampuja-urosta.

Kokkona kohotteleikse tavoitellen Väinämöistä, siipi pilviä


sipaisi, toinen vettä vieprahteli.

ILMARISEN ÄÄNI (parahtaen)

Kaitse, kaunoinen Jumala, ettei poika pois tulisi!

VÄINÄMÖISEN ÄÄNI

Ohoh Pohjolan emäntä! Joko saat jaolle Sammon nenähän


utuisen niemen?

LOUHEN ÄÄNI

En lähe jakohon Sammon sinun kanssasi, katala, kerallasi,


Väinämöinen!

LEMMINKÄISEN ÄÄNI

Maahan miehet, maahan miekat, maahan untelot urohot,


sa'at miehet siiven alta, kymmenet kynän nenästä!

ESILAUSUJA
Vaka vanha Väinämöinen, tietäjä iän-ikuinen, arvasi ajan
olevan, tunsi hetken tulleheksi; jo veti melan merestä,
tammen lastun lainehesta, sillä kalhaisi kavetta, iski kynsiä
kokolta; muut kynnet meni muruiksi, jäi yksi sakarisormi.

1:NEN VUOROLAUSUJA

Pojat siiviltä putosi, melskahti merehen miehet, sata miestä


siiven alta, tuhat purstolta urosta!

2:NEN VUOROLAUSUJA

Itse kokko kopsahtihe, kapsahutti kaaripuille, kuni puusto


koppeloinen, kuusen oksalta orava.

1:NEN VUOROLAUSUJA

Siitä Sampoa tavoitti sormella nimettömällä.

2:NEN VUOROLAUSUJA

Sammon vuoalti vetehen, kaatoi kaiken kirjokannen.

MOLEMMAT

Siinä sai muruiksi Sampo, kirjokansi kappaleiksi!

LOUHEN ÄÄNI (parahtaen)

Jo minulta valta vaipui, jo aleni arvioni, eloni meni


merehen, Sampo särkyi lainehisin!
(Pitkä vaitiolo. Näyttämö valkenee vähitellen. Väinämöinen näkyy
seisovana mietteissään keskinäyttämöllä, Kanteletar nojaavana puun
runkoon oikealla.)

KANTELETAR

Niin meni muruja noita, Sammon suuria paloja, alle


vienojen vesien, päälle mustien murien, ne jäivät ve'en
varaksi, ahtolaisten aartehiksi; siitäp' ei sinä ikänä, kuuna
kullan valkeana, vesi puuttune varoja, ve'en Ahto aartehia.

Jäipä toisia muruja, pienempäisiä paloja selälle meren


sinisen, meren laajan lainehille, tuulen tuuiteltavaksi, aaltojen
ajeltavaksi.

Niitä tuuli tuuitteli, meren läikkä läikytteli, selällä meren


sinisen, meren laajan lainehilla, tuuli maalle työnnytteli, aalto
rannallen ajeli.

VÄINÄMÖINEN (miettivästi)

Tuost' on siemenen sikiö, alku onnen ainiaisen, tuosta


kyntö, tuosta kylvö, tuosta kasvu kaikenlainen, tuosta kuu
kumottamahan, onnen päivä paistamahan Suomen suurille
tiloille, Suomen maille mairehille.

(Louhi näkyy puiden lehvien lomitse vasemmalta.)

LOUHI

Vielä ma tuohon mutkan muistan: tungen kuuhuen


kivehen, päivän kätken kalliohon!
VÄINÄMÖINEN (kätensä kohottaen)

Anna, luoja, suo Jumala, anna onni ollaksemme, hyvin ain'


eleäksemme, kunnialla kuollaksemme suloisessa Suomen
maassa, kaunihissa Karjalassa!

(Kuoro kertaa viimeisen säejakson.)

ESIRIPPU.
VÄINÄMÖISEN LÄHTÖ.

HENKILÖT:

VÄINÄMÖINEN. ILMARINEN. MARJATTA. MARJATAN ÄITI. PIIKA


PIKKARAINEN. LOUHI. VIROKANNAS. KANTELETAR. KUORO.

(Kuoro paikallaan uhrikuusen alla. Valaistus: kesäyön hämärä.


Kanteletar nojaa puun runkoon vasemmalla etualalla.)

ESILAUSUJA

Vaka vanha Väinämöinen kauan soitti kanteletta, sekä soitti,


jotta lauloi, jotta ilmankin iloitsi.

Soitto kuului kuun tupihin, ilo päivän ikkunoille, kuu


tuvastahan tulevi, astui koivun konkelolle, päivä päätyi
linnastansa, loihe latvahan petäjän kanteletta kuulemahan,
iloa imehtimähän.

1:NEN VUOROLAUSUJA

Louhi, Pohjolan emäntä, Pohjan akka harvahammas, siitä


päivän kiinni saapi, kuuhuen käsin tavoitti.
2:NEN VUOROLAUSUJA

Kätki kuun kumottamasta kirjarintahan kivehen, lauloi


päivän paistamasta vuorehen teräksisehen.

1:NEN VUOROLAUSUJA

Jopa valkean varasti, tulen Väinölän tuvilta; sai tuvat


tulettomaksi, pirtit valkeattomaksi.

2:NEN VUOROLAUSUJA

Tukela on tuletta olla, vaiva suuri valkeatta, ikävä


inehmisten, ikävä itsen Ukonki.

MOLEMMAT

Jo oli yö alinomainen, pitkä, pilkkosen pimeä; oli yö


Kalevalassa, noilla Väinölän tuvilla, sekä tuolla taivahassa,
Ukon ilman istuimilla.

ESILAUSUJA (nousee)

Tuo Ukko, ylijumala, itse ilman suuri luoja, alkoi tuota


ouostella, arvelee, ajattelevi, mikä kumma kuun e'essä, mikä
terhen päivän tiessä, kun ei kuu kumottakana eikä päivä
paistakana.

(Väinämöinen tulee mietteissään vasemmalta karsikosta.)

VÄINÄMÖINEN
Ain' on päivä paistamatta, kuu-kulta kumottamatta, noilla
Väinölän tuvilla, Kalevalan kankahilla; vilu viljalle tulevi,
karjoille olo kamala, outo ilman lintusille, ikävä imehnosille,
kun ei konsa päivyt paista eikä kuuhuet kumota.

Hauki tiesi hauan pohjat, kokko lintujen kulennan, tuuli


haahen päiväyksen; ei tieä imehnon lapset, milloin aamu
alkanevi, milloin yö yrittänevi nenässä utuisen niemen, päässä
saaren terhenisen Jos ma nyt lähen Pohjolahan, Pohjan
poikien poluille, saan ma kuun kumottamahan, päivä-kullan
paistamahan,

(Etenee yli näyttämön vasemmalle. Louhi tulee häntä vastaan.)

LOUHI

Ku sanoma kurjan miehen?

VÄINÄMÖINEN (ankarasti)

Kuusta on sanomat kummat, päivästä iki-imehet; minnes


meiltä päivä päätyi, kunnes meiltä kuu katosi?

LOUHI

Tuonne teiltä päivä päätyi, tuonne teiltä kuu katosi,


kirjarintahan kivehen, rautaisehen kalliohon; sielt' ei pääse
päästämättä, selviä selittämättä.

VÄINÄMÖINEN (vetäen miekkansa)

Kun ei kuu kivestä pääsne, pääsne päivä kalliosta,


käykämme käsirysyhyn, ruvetkamme miekkasille!
(Menee päättävästi vasemmalle. Louhi säikähtyneenä väistyy
hänen edellään.)

KANTELETAR (vienosti)

Marjatta, korea kuopus, se kauan kotona kasvoi, korkean


ison kotona, emon tuttavan tuvilla; piti viiet vitjat poikki,
kuuet renkahat kulutti isonsa avaimilla, helmassa helottavilla.

Puolen kynnystä kulutti helevillä helmoillansa, puolen hirttä


päänsä päältä sileillä silkillänsä, puolet pihtipuolisia hienoilla
hiansa suilla, siltalaahkon lattiata kautokengän kannoillansa.

Marjatta, korea kuopus, aina piikoina elävä, neitosena


niekottava, päätyi karjan paimeneksi, läksi lammasten keralle.

Lampahat meni mäkeä, vuonat vuoren kukkulata, neiti


asteli ahoa, lepikköä leyhytteli, keksi marjasen mäeltä,
punapuolan kankahalta.

(Äiti ja Piika pikkarainen tulevat vasemmalta taustasta.)

ÄITI

Mi on meiän Marjatalla, kun se pauloitta asuvi, käypi


saunassa saloa, pimeissä pisteleikse?

PIIKA PIKKARAINEN

Se on meiän Marjatalla, kun oli paljon paimenessa, kauan


karjassa käveli.

(Marjatta tulee vasemmalta taustasta ja painautuu äitinsä povelle.)


MARJATTA

Oi emoni, armahani! Laita suojoa sijoa, lämpymyttä


huonehutta piian pieniksi pyhiksi, vaimon vaivahuoneheksi.

ÄITI (inholla)

Kenen oot makaelema, ootko miehen naimattoman eli


nainehen urohon?

MARJATTA

En ole miehen naimattoman enkä nainehen urohon; menin


marjahan mäelle, punapuolan poimentahan, otin marjan
mielelläni, toisen kerran kielelläni, se kävi kerustimille, siitä
vatsahan valahti.

ÄITI (kuten edellä)

Mene, portto, poikemmaksi, tulen lautta, tuonnemmaksi,


kontion kivikoloihin, karhun louhikammioihin, sinne, portto,
poikimahan, tulen lautta, lapsimahan!

MARJATTA

En mä portto ollekana, tulen lautta lienekämi, olen miehen


suuren saava, jalon synnyn synnyttävä, joll' on valta
vallallenki, väki Väinämöisellenki.

(Äiti tehden halveksivan liikkeen, palajaa taustaan.)

Piltti, pienin piikojani! Käypä kylpyä kylästä, saunoa Sara-


ojalta, jossa huono hoivan saisi.
PIIKA PIKKARAINEN

Ei ole kylpyä kylässä, saunoa Sara-ojalla; ruma Ruotuksen


emäntä sanan virkkoi, noin nimesi "Ei kylyt kylähän joua, ei
saunat Sarajan suulta; on kyly kytömäellä, hepohuone
hongikossa tuliporton poiat saa'a, lautan lapsensa latoa; kun
heponen hengähtävi, niin on siinä kylpeköhön."

MARJATTA (valittaen)

Lähteä minun tulevi niinkuin muinenki kasakan eli orjan


palkollisen, lähteä kytömäelle, käyä hongikkokeolle.

(Menee oikealle taustaan. Piika pikkarainen tukee häntä.)

1:NEN VUOROLAUSUJA

Marjatta, matala neiti, teki tuonne pienen poian, heinille


hevosen luoksi, sorajouhen seimen päähän.

2:NEN VUOROLAUSUJA

Piiletteli pojuttansa, kasvatteli kaunoistansa, sylissänsä


syöttelevi, käsissänsä kääntelevi

1:NEN VUOROLAUSUJA

Siitä meiän Marjatalle kasvoi poika kaunokainen; ei tieä


nimeä tuolle, millä mainita nimellä.

2:NEN VUOROLAUSUJA
Etsittihin ristijätä, katsottihin kastajata; tuli ukko
ristimähän, Virokannas kastamahan.

(Ilmarinen tulee kiireesti oikealta taustasta, Väinämöinen


mietteissään vasemmalta.)

ILMARINEN

Ohoh vanha Väinämöinen, laulaja iän-ikuinen! Käypä kuuta


katsomahan, päiveä tähyämähän, jo ovat tarkoin taivahilla,
sijoillansa muinaisilla.

VÄINÄMÖINEN (päänsä kohottaen)

Terve, kuu, kumottamasta, kaunis, kasvot näyttämästä,


päivä-kulta koittamasta, aurinko ylenemästä!

Kuu-kulta kivestä pääsit, päivä kaunis, kalliosta, nousit


kullaisna käkenä, hopeisna kyyhkyläisnä elollesi entiselle,
matkoillesi muinaisille.

Nouse aina aamusilla tämän päivänki perästä; teepä meille


terveyttä, siirrä saama saatavihin, pyyntö päähän
peukalomme, onni onkemme nenähän!

Käy nyt tiesi tervehenä, matkasi imantehena, päätä kaari


kaunihisti, pääse illalla ilohon!

(Näyttämö on valjennut vähitellen taustasta. Marjatta, lapsi


sylissään, Virokannas, Lemminkäinen y.m. kansaa.)

VIROKANNAS
En mä risti riivattua, katalata kastakana, kun ei ensin
tutkittane, tutkittane, tuomittane.

1:NEN VUOROLAUSUJA

Kenpä tuohon tutkijaksi, tutkijaksi, tuomariksi?

2:NEN VUOROLAUSUJA

Vaka vanha Väinämöinen


tutkijaksi, tuomariksi.

(Marjatta lapsineen y.m. kansa lähestyy Väinämöistä ja


keskustelee hänen kanssaan, Väinämöinen kuuntelee hetkisen
heidän puhettaan.)

VÄINÄMÖINEN

Kun lie poika suolta saatu, maalta marjasta siennyt, poika


maahan pantakohon, marjamättähän sivulle, tahi suolle
vietäköhön, puulla päähän lyötäköhön!

(Liikettä kansanjoukossa. Kuoro nousee hämmästyneenä.)

KUORO

Puhui poika puolikuinen, kaksiviikkoinen kajahui!

KANTELETAR (jalolla suuttumuksella).

Ohoh sinua, ukko utra, kun olet tuhmin tuominnunna,


väärin laskenna lakia! Eipä syistä suuremmista, töistä
tuhmemmistakana itseäsi suolle viety eikä puulla päähän
lyöty, kun sa miesnä nuorempana menettelit neiet nuoret alle
aaltojen syvien, päälle mustien mutien.

(Pois oikealle. Kansa polvistuu keskinäyttämölle.)

1:NEN VUOROLAUSUJA

Ukko ristii ripsahutti, kastoi lapsen kapsahutti Karjalan


kuninkahaksi, kaiken vallan vartiaksi.

2:NEN VUOROLAUSUJA

Siitä suuttui Väinämöinen, jopa suuttui ja häpesi, lauloin


vaskisem venehen, kuparisen umpipurren.

(Väinämöinen on siirtynyt oikealle. Marjatta, Virokannas ja kansa


jäänyt keskinäyttämölle)

VÄINÄMÖINEN (kätensä kohottaen)

Annapas ajan kulua, päivän mennä, toisen tulla, taas minua


tarvitahan, katsotahan, kaivatahan uuen Sammon saattajaksi,
uuen soiton suorijaksi, uuen kuun kulettajaksi, uuen päivän
päästäjäksi, kun ei kuuta, aurinkoa, eikä ilmaista iloa.

ESILAUSUJA

Siitä vanha Väinämöinen laskea karehtelevi venehellä


vaskisella, kuutilla kuparisella yläisihin maa-emihin, alaisihin
taivosihin.

VÄINÄMÖISEN ÄÄNI (oikealta)


Vaan kuitenki, kaikitenki laun hiihin laulajoille, laun hiihin,
latvan taitoin, oksat karsin, tien osoitin.

KANTELETAR

Jätti kantelon jälille, soiton Suomelle sorean, kansalle ilon


ikuisen, laulut suuret lapsillensa.

KUORO

Siitäpä nyt tie menevi, ura uusi urkenevi laajemmille,


laulajoille, runsahammille runoille nuorisossa nousevassa,
kansassa kasuavassa.

ESIRIPPU.
*** END OF THE PROJECT GUTENBERG EBOOK KALEVALA
NÄYTTÄMÖLLÄ: III SARJA (OF 3) ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like