Image Acquisition and Analysis in MATLAB

Transcription

Image Acquisition and Analysis in MATLAB
2009/8/5
Image Acquisition and
Analysis in MATLAB
Presenter: Claire Chuang
TeraSoft Inc.
Copyright © 2007 by TeraSoft, Inc.
Using MATLAB for Image Processing
Image pre-processing
Image analysis
Visualization
Algorithm
development
Image acquisition
Idea sharing and
reporting
Data access
Application
deployment
Copyright © 2007 by TeraSoft, Inc.
1
2009/8/5
Outline
▪
▪
▪
▪
▪
▪
▪
Hardware Connections
Examining Hardware Resources
Create a Video Input Object
Configuring Properties
Preview the Video Stream
Acquiring Image Data
Deleting and Clearing Toolbox Objects
Copyright © 2007 by TeraSoft, Inc.
Image Acquisition Application
This section shows you an example of:
Original Image
1. Accessing the webcam’s video input.
2. Acquiring an image and store as a
MATLAB variable.
3. Bring the acquired image into MATLAB,
process, and visualize.
Copyright © 2007 by TeraSoft, Inc.
2
2009/8/5
Hardware Connections
▪ Connect the image acquisition device to your PC (In our
case, a USB port connected webcam).
▪ Check the hardware with the application software
provided by the manufacturer.
USB Port
Webcam
http://www.mathworks.com/products/imaq/supportedio.html
Copyright © 2007 by TeraSoft, Inc.
Examining Hardware Resources
▪ You should examine the image acquisition
hardware resources visible to the toolbox with
the imaqhwinfo function.
• General toolbox information
>> a = imaqhwinfo;
>> a.InstalledAdaptors
ans =
'coreco'
'winvideo'
• Adaptor-specific information
>> b = imaqhwinfo('winvideo');
Copyright © 2007 by TeraSoft, Inc.
3
2009/8/5
Creating a Video Input Object – Basics
▪ Create a video input object with the videoinput
constructor.
>> vid = videoinput('winvideo',1);
where:
• vid is called a video input object.
• winvideo is the adaptor name for image acquisition
hardware.
• 1 is the device ID (given by imaqhwinfo)
▪ vid is a custom MATLAB class.
>> whos vid
Copyright © 2007 by TeraSoft, Inc.
Configuring Properties – Basics
▪ Use the set function to display all configurable
device object properties.
>> set(vid)
▪ Use the get function to return the current device
object property values.
>> get(vid)
▪ Use the image acquisition property editor to view
and edit the device object's properties.
>> inspect(vid)
Copyright © 2007 by TeraSoft, Inc.
4
2009/8/5
Configuring Properties – Summary
▪ The Image Acquisition Toolbox provides the
following functions to return property information.
Function
Property information provided
set
All configurable properties
Possible value strings, with the default contained by braces
get
All properties and their current values
propinfo
Runtime property characteristics
Property value data type
Default property values
Constraints (min and max values)
imaqhwinfo
Hardware-related property values
- Maximum height and width
- Vendor driver version
inspect
Image acquisition object property editor
Copyright © 2007 by TeraSoft, Inc.
Preview Video Stream
The data extraction process is shown below.
Log data to engine
Engine
Logged data
Preview 5 most
recent frames
>> preview(vid)
>> data = peekdata(vid,5);
>> montage(data);
4-D data array
Note peekdata is an non-blocking function
that immediately returns data and execution
control to MATLAB.
Copyright © 2007 by TeraSoft, Inc.
5
2009/8/5
Acquiring Image Data - Extracting
(Continued)
The data extraction process is shown below.
Engine
Extracted
data
Log data to engine
Remaining
data
Extract data from engine
>> [data,time] = getdata(ai);
t1
t2
t3
.
.
.
tm
4-D data array
Note getdata blocks the command
line until the requested number of
samples is returned or a timeout
occurs.
m-by-1 time array
Copyright © 2007 by TeraSoft, Inc.
Acquiring Image Data – Extracting
(Continued)
Use the getdata function to extract acquired data
from the engine.
▪ Extract the specified number of frames.
>> data = getdata(vid,5);
▪ Extract all the data associated with one trigger.
>> data = getdata(vid);
>> data = getdata(vid,get(vid,'FramesPerTrigger'));
▪ Extract all the data available in the engine.
>> data = getdata(ai,get(vid,'FramesAvailable'));
Copyright © 2007 by TeraSoft, Inc.
6
2009/8/5
Deleting and Clearing Toolbox Objects
▪ Remove variables from the MATLAB workspace.
>> delete(vid)
>> clear vid
▪ To quickly delete all device objects and reset the
hardware to its initial state
>> imaqreset
Copyright © 2007 by TeraSoft, Inc.
The Video Input Session
>> vid = videoinput('winvideo',1);
Create object
>> set(vid,'ReturnedColorSpace','rgb');
>> triggerconfig(vid,'immediate');
>> set(vid,'FramesPerTrigger',10);
Configure properties
(optional)
>> preview(vid);
Preview video input
(optional)
>> start(vid);
>> data = getdata(vid);
>> imshow(data(:,:,:,end));
>> stop(vid);
Acquire data
>> delete(vid)
>> clear vid
Delete / Clean-up
Copyright © 2007 by TeraSoft, Inc.
7
2009/8/5
Image Processing Toolbox
Perform image processing, analysis,
visualization, and algorithm development
•
•
•
•
•
•
Graphical tools
Image pre- and postprocessing
Image analysis
Spatial transformations
Image registration
Color image processing
Copyright © 2007 by TeraSoft, Inc.
Image Pre- and Postprocessing
▪
▪
▪
▪
▪
Contrast enhancement
Noise removal
Deblurring
Region-based processing
Linear and nonlinear filtering
Original Landsat image courtesy of Space Imaging, LLC.
Original image courtesy of MIT. This
version created by simulating motion
blur.
Deblurred image using Wiener
filter deconvolution.
Copyright © 2007 by TeraSoft, Inc.
8
2009/8/5
Image Analysis
▪
▪
▪
▪
▪
▪
▪
▪
Edge detection
Segmentation
Morphological operators
Image statistics
Boundary tracing
Region properties
Texture analysis
Hough transform
Copyright © 2007 by TeraSoft, Inc.
Q&A
Thanks!!
Copyright © 2007 by TeraSoft, Inc.
9