Sie sind auf Seite 1von 15

Image Processing (part 2)

2/25/14

Review
Images are represented as matrices Color images
RGB 3D matrices

Grayscale images imread, imshow, imtool Motion tracking

Indexed Images
Colormap
Is a 2D matrix with 3 columns Each row represents an RGB value

Each pixel value of an indexed image serves as an index into the colormap

Displaying an Indexed Image


image
Another way to display an image
imshow(A)
Display RGB image if A is mn3 Display grayscale image if A is 2D
imshow(A,MAP) will display an indexed image using the colormap MAP

image(A)
Display RGB image if A is mn3 Display indexed image (using current colormap) if A is 2D

Indexed Images and Scaling


Data can be scaled to use the full colormap
I used this in the heat equation simulation imagesc Setting certain properties

Indexed Images and Grayscale Images


A grayscale image is essentially just an indexed image using the gray colormap and some scaling

Image Functions
Converting between image types
rgb2gray rgb2ind ind2rgb ind2gray

Image Processing Toolbox


Can do all sorts of processing/manipulation of images Read documentation for this toolbox if you are interested in image processing

Interacting with Figures


ginput
Allows a user to click on locations on a figure
Returns the location that was clicked

Can allow interaction between a user and a figure! Applies to figures in general, not just images

Movies
A movie is just an array of individual images! Create a movie in Matlab
Create a bunch of images and use getframe
getframe takes a snapshot of the current axis Often done in a loop see example_file9.m

movie play the frames back in Matlab movie2avi create .avi file from frames VideoWriter

Movies
Read a movie into Matlab
VideoReader
m=VideoReader('matlab_light_message.avi'); image_stack=read(m);
image_stack is a 4-D matrix An additional input argument allows you to select just a subset of the frames

implay
Opens a movie player Input can be
Filename Movie structure Image stack

Like 'matlab_light_message.avi' Created using getframe and loop Like image_stack from above

Structures
Has multiple fields
To access different fields, use a dot
variable_name.field_name

Often just called struct

See example_file9.m for examples The movie structure we created using getframe has two fields and one element for each frame
1x100 struct array with fields: cdata colormap

Matlab Data Files


MAT-files
Matlabs datafile format

save
Save all or just specific variables to a file save my_datafile.mat save my_datafile2.mat x y

load
Load data from a file load my_datafile.mat

Matlab Data Files


MAT-files vs ASCII (text) files
MAT-file
Binary format
For large amounts of data, can result in a much smaller file Can hold essentially all types of Matlab information

ASCII (text) file


You can read it!
5 * '5' = ??? http://www.asciitable.com/

save, load
Can deal with both MAT and ASCII files If loading from a text file, the See documentation for details data is stored in a variable
named after the file (without the file extension)

Final Notes
Lecture slides and examples posted on Canvas Homework #6 Upcoming Schedule
Exam Review
Come prepared with questions
2/25: Image Processing (part 2) 2/27: Curve Fitting/Exam Review
Exam covers through todays lecture (through HW6) 3/4: Exam 3/6: Sound/Curve Fitting SPRING BREAK!!!

Fun with Matlab

Das könnte Ihnen auch gefallen