Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Visual Media Processing Using MATLAB Beginner's Guide
Visual Media Processing Using MATLAB Beginner's Guide
Visual Media Processing Using MATLAB Beginner's Guide
Ebook730 pages4 hours

Visual Media Processing Using MATLAB Beginner's Guide

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Written in a friendly, Beginner's Guide format, showing the user how to use the digital media aspects of Matlab (image, video, sound) in a practical, tutorial-based style.This is great for novice programmers in any language who would like to use Matlab as a tool for their image and video processing needs, and also comes in handy for photographers or video editors with even less programming experience wanting to find an all-in-one tool for their tasks.
LanguageEnglish
Release dateSep 24, 2013
ISBN9781849697217
Visual Media Processing Using MATLAB Beginner's Guide

Related to Visual Media Processing Using MATLAB Beginner's Guide

Related ebooks

Applications & Software For You

View More

Related articles

Reviews for Visual Media Processing Using MATLAB Beginner's Guide

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Visual Media Processing Using MATLAB Beginner's Guide - George Siogkas

    Table of Contents

    Visual Media Processing Using MATLAB Beginner's Guide

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    Why Subscribe?

    Free Access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Time for action – heading

    What just happened?

    Pop quiz – heading

    Have a go hero – heading

    Reader feedback

    Customer support

    Downloading the example code

    Errata

    Piracy

    Questions

    1. Basic Image Manipulations

    Getting acquainted with the MATLAB environment

    Default subwindows of the environment

    The Command Window

    The Current Folder window

    The Details window

    The Workspace window

    The ribbon

    The HOME tab

    The PLOTS tab

    The APPS tab

    The editor

    The EDITOR window

    Importing and displaying an image

    Importing and displaying an image using the command line

    Time for action – importing and displaying an image

    What just happened?

    Importing and displaying an image using imtool

    Time for action – using imtool to extract useful information

    What just happened?

    Applying geometric transformations

    Performing image rotation

    Time for action – rotating an image and displaying the result

    What just happened?

    Performing image mirroring

    Time for action – mirroring an image and displaying the result

    What just happened?

    Have a go hero – using flipdim and comparing the results

    Resizing an image

    Cropping an image

    Saving an image

    Time for action – cropping and resizing an image, then saving it as BMP

    What just happened?

    Have a go hero – tailoring an image to suit your needs

    Pop quiz – image processing in MATLAB

    Summary

    2. Working with Pixels In Grayscale Images

    Accessing image pixels and changing their values

    Changing the pixel values of a square area using loops

    Changing the pixel values of a square area using indexing

    Writing and using scripts

    Time for action – whiten an area and blacken another

    What just happened?

    Thresholding an image

    Image thresholding using for loops

    Image thresholding using indexing

    Image thresholding using im2bw

    Image thresholding using an automatic threshold

    Calculating and displaying histograms with imhist

    Histogram equalization for contrast enhancement

    Contrasting enhancement using imadjust

    Contrasting enhancement using imcontrast

    Adaptive histogram equalization using adapthisteq

    Custom functions for complex tasks

    Time for action – using imtool to pinpoint differences

    What just happened?

    Have a go hero – writing a function to enhance an image area

    Restoring old photographs

    Time for action – restoring your ancestors' photographs

    What just happened?

    Pop quiz – contrasting enhancement methods

    Summary

    3. Morphological Operations and Object Analysis

    The importance of binary images

    Time for action – understanding the value of thresholding

    What just happened?

    Enlarging and shrinking a region of interest

    Time for action – using dilation and erosion to refine ROIs

    What just happened?

    Choosing a structuring element

    Using strel to generate structuring elements

    Altering structuring elements from strel to suit our needs

    Time for action – ROI refinement using strel

    What just happened?

    Have a go hero – write a function to for local dilation/erosion

    More morphological operations

    Manually defining a non-rectangular ROI

    Using roipoly to make a mask

    Using imfreehand to make a mask

    Time for action – making a custom object eraser function

    What just happened?

    Analyzing objects in an image

    Detecting edges in an image

    Detecting corners in an image

    Detecting circles in an image

    Pop quiz – object analysis pros and cons

    Summary

    4. Working with Color Images

    An introduction to color image processing

    Basic color image manipulations

    Setting a rectangular area to a specified color

    Time for action – repainting two areas in a color image

    What just happened?

    Thresholding color images

    Time for action – isolating the red pixels in an image

    What just happened?

    Achieving color masking

    Time for action – color isolation

    What just happened?

    The importance of different color spaces

    Time for action – color space transformation

    What just happened?

    CIE-L*a*b* for more efficient color masking

    Time for action – color isolation using CIE-L*a*b*

    What just happened?

    Have a go hero – writing a function for region color isolation

    Fixing illumination issues in RGB color images

    Fixing illumination issues in CIE-L*a*b*

    A practical example – red eye reduction

    Time for action – writing a function for red eye reduction

    What just happened?

    Taking advantage of eye circularity

    Time for action – automating our function for red eye reduction

    What just happened?

    Pop quiz – working with color

    Summary

    5. 2-Dimensional Image Filtering

    An introduction to image filtering

    Processing neighborhoods of pixels

    The basics of convolution

    The ugly mathematical truth

    Time for action – applying averaging filters in images

    What just happened?

    Alternatives to convolution

    Using imfilter

    Creating filters with fspecial

    Different ways to blur an image

    Time for action – how much blurring is enough

    What just happened?

    Time to make art using blurring

    Time for action – creating the bokeh effect in an image

    What just happened?

    Have a go hero – add a motion effect in your image

    Removing noise using blurring

    Time for action – trying to remove different types of noise

    What just happened?

    The importance of the median filter

    Time for action – removing salt & pepper with medfilt2

    What just happened?

    Have a go hero – denoising real images

    Bringing back the details

    Time for action – enhancing the edges in our images

    What just happened?

    Brighten up the lights

    Time for action – brighten up the lights in our soldier picture

    Pop quiz – image filtering in 2-dimensions

    Summary

    6. Mixing Images for Science or Art

    The importance of mixing or combining images

    Using multispectral imaging

    Loading and manipulating the multispectral images

    Time for action – visible spectrum from a multiband image of Rio

    What just happened?

    Time for action – working with invisible spectrums

    What just happened?

    Creating composite images

    Using imfuse to create a composite image

    Using imshowpair to inspect a composite image

    Time for action – cloning the seagull

    What just happened?

    Have a go hero – playing Warhol with your pictures

    One step beyond – blending selected image regions

    Time for action – directing a threatening scene

    What just happened?

    Creating High Dynamic Range images

    Time for action – composing your own HDR images

    What just happened?

    Stitching images for the creation of panoramas

    Time for action – basic approach to panorama stitching

    What just happened?

    Pop quiz – image mixing details

    Summary

    7. Adding Motion – From Static Images to Digital Videos

    An introduction to digital videos

    The meaning of frames

    Interlaced versus progressive

    Frame rates and their importance

    Calculating number of frames

    Some thoughts on choosing frame rates

    Loading videos in MATLAB

    Loading videos with aviread

    Loading videos with mmreader

    Loading videos with VideoReader

    Choosing which function to use for video reading

    Playing back videos in MATLAB

    Time for action – reading and playing back a video

    What just happened?

    Making videos from static images

    Time for action – constructing and saving a video

    What just happened?

    Have a go hero – make a video with a fade in/fade out effect

    Inspecting a video using montage

    Time for action – don't wait for the ball

    What just happened?

    A tool just for your playback needs – implay

    Using the GUI of implay

    Using implay to play a video file

    Using implay to play an image sequence

    Creating time-lapse videos

    Time for action – time-lapsing a regular video

    What just happened?

    Have a go hero – spinning our time-lapse

    Saving your time-lapse videos in a gif file

    Pop quiz – image filtering in 2-dimensions

    Summary

    8. Acquiring and Processing Videos

    Using MATLAB for digital video recording

    The Hardware Browser window

    The Information window

    The Desktop Help window

    The Preview window

    The Acquisition Parameters window

    The General tab

    The Device Properties tab

    The Logging tab

    The Triggering tab

    The Region of Interest tab

    The Session Log window

    Time for action – capturing a video using a firewire connection

    What just happened?

    Have a go hero – adding a trigger to our recording

    The importance of video compression

    Checking the size of an uncompressed video

    Checking the size of an MP4 video without any motion

    Checking the size of an MP4 video with high motion

    Working with uncompressed videos

    Working with large videos in postproduction

    Time for action – making an edge detection video

    What just happened?

    Have a go hero – getting the last chunk of frames processed

    Pop quiz – what is the problem with our function?

    Acquiring frames for time-lapse videos

    Detecting your acquisition hardware

    Creating a video object and acquiring a frame

    Time for action – using MATLAB as an intervalometer

    What just happened?

    Have a go hero – creating a time-lapse creation function

    Real-time processing of time-lapse videos

    Time for action – creating time-lapses with isolated colors

    What just happened?

    Real-time processing of normal videos

    Evaluating real-time capabilities with a simple example

    Time for action – adjusting the contrast of the video

    What just happened?

    Revisiting the contrast adjustment example

    Time for action – adding preview in our code

    What just happened?

    Have a go hero – doubling the speed of our code

    Pop quiz – acquiring and processing videos

    Summary

    9. Spatiotemporal Video Processing

    Basic video processing with MATLAB

    Cropping and resizing our video

    Time for action – loading, cropping, resizing, and saving a video

    What just happened?

    Have a go hero – adding rotation and more error-checking

    Filtering your video frames

    Time for action – reducing the blocking effect

    What just happened?

    Deinterlacing videos in MATLAB

    Intra-frame filtering for deinterlacing tasks

    Deinterlacing with the Computer Vision System Toolbox

    Time for action – deinterlacing a video using the vision toolbox

    What just happened?

    Have a go hero – comparing the deinterlacing methods

    Deinterlacing with the custom functions

    Time for action – deinterlacing with line repetition

    What just happened?

    Time for action – deinterlacing with the scan line interpolation

    What just happened?

    Have a go hero – comparing the deinterlacing methods

    Inter-frame filtering for the deinterlacing tasks

    Temporal deinterlacing by field merging

    Time for action – deinterlacing with field merging

    What just happened?

    Have a go hero – evaluating the field merge method

    Temporal deinterlacing by field averaging

    Time for action – deinterlacing with field averaging

    What just happened?

    Mixing intra-frame and inter-frame deinterlacing

    Vertical and temporal interpolation for deinterlacing

    Time for action – vertical and temporal interpolation method

    What just happened?

    Have a go hero – Comparing deinterlacing techniques

    Adding a new dimension to the filters

    Spatiotemporal averaging filter

    Time for action – implementing a spatiotemporal averaging filter

    What just happened?

    Have a go hero – creating a spatiotemporal median filter

    Using convolution for spatiotemporal averaging

    Time for action – spatiotemporal averaging filter with the convn function

    What just happened?

    Pop quiz – videos and filters

    Summary

    10. From Beginner to Expert – Handling Motion and 3-D

    Detecting and estimating motion in videos

    Detecting motion

    Time for action – detecting a moving object in a still scene

    What just happened?

    Time for action – detecting motion in a complex scene

    What just happened?

    Have a go hero – making your own surveillance system

    Estimating the motion

    Estimating motion using optical flow

    Time for action – tracking people with Horn-Schunck optical flow

    What just happened?

    Have a go hero – estimating optical flow using Lucas-Kanade

    Time for action – warping frames using optical flow

    What just happened?

    Have a go hero – making your own surveillance system

    Compensating camera motion using feature tracking

    Time for action – tracking feature points for motion compensation of a shaky video

    What just happened?

    Have a go hero – tweaking the settings of the stabilization demo

    Working with stereoscopic images

    Time for action – creating a 3-D video from left and right videos

    What just happened?

    Time for action – creating a 3-D video from a regular one

    What just happened?

    Have a go hero – writing a function for 3-D video creation

    Pop quiz –working with video frames

    Summary

    A. Pop Quiz Answers

    Chapter 1, Basic Image Manupulation

    Pop quiz – image processing in Matlab

    Chapter 2, Working with Pixels in Grayscale Images

    Pop quiz – contrasting enhancement methods

    Chapter 3, Morphological Operations and Object Analysis

    Pop quiz – object analysis pros and cons

    Chapter 4, Working with Color Images

    Pop quiz – working with color

    Chapter 5, 2-Dimensional Image Filtering

    Pop quiz – image filtering in 2-dimensions

    Chapter 6, Mixing Images for Science or Art

    Pop quiz – image mixing details

    Chapter 7, Adding Motion – From Static Images to Digital Videos

    Pop quiz – image filtering in 2-dimensions

    Chapter 8, Acquiring and Processing Videos

    Pop quiz – what is the problem with our function?

    Pop quiz – acquiring and processing videos

    Chapter 9, Spatiotemporal Video Processing

    Pop quiz – videos and filters

    Chapter 10, From Beginner to Expert – Handling Motion and 3-D

    Pop quiz – working with video frames

    Index

    Visual Media Processing Using MATLAB Beginner's Guide


    Visual Media Processing Using MATLAB Beginner's Guide

    Copyright © 2013 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: September 2013

    Production Reference: 1170913

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-84969-720-0

    www.packtpub.com

    Cover Image by George Siogkas (<siogkas@gmail.com>)

    Credits

    Author

    George Siogkas

    Reviewers

    R. Surya Murali

    Ashish Uthama

    Alexander Wright

    Acquisition Editor

    Joanne Fitzpatrick

    Lead Technical Editor

    Anila Vincent

    Technical Editors

    Chandni Maishery

    Iram Malik

    Manal Pednekar

    Project Coordinator

    Navu Dhillon

    Proofreader

    Elinor Perry-Smith

    Indexers

    Hemangini Bari

    Monica Ajmera Mehta

    Graphics

    Ronak Dhruv

    Production Coordinator

    Kirtee Shingan

    Cover Work

    Kirtee Shingan

    About the Author

    George Siogkas is currently the Associate Dean of the Department of Engineering and Informatics at New York College, Greece, where he has been teaching as a senior lecturer for the past four years. He also has more than ten years of research experience in the academia. His keen passion for MATLAB programming, especially in the areas of image and video processing, was developed while working towards a PhD in the field of computer vision for intelligent transportation systems.

    Dr. Siogkas received his PhD in Electrical and Computer Engineering from the University of Patras, Greece in 2013.

    For more information about the author, visit his webpage, at http://www.cvrlab.com/gsiogkas.

    I would like to first and foremost thank my beautiful wife, Maro, who put up with my exhausting writing schedule for both this book and my PhD thesis, while staying focused enough to organize our wedding. I would also like to thank my parents and my brother for their continuous support, especially during this past year. Without the encouragement from all of them, this project would never even have got started in the first place.

    I would also like to thank everyone at Packt Publishing who got involved in this book, especially Joanne Fitzpatrick, Hardik Patel, Navu Dhillon, and Anila Vincent. They played a very important role in helping me understand the rationale behind such a writing project and provided invaluable feedback throughout the writing process. Also, a special thanks goes to the reviewers, R. Surya Murali, Ashish Uthama, and Alexander Wright, who provided very useful and insightful comments and suggestions for improving the quality of the book. Without them all, this book would never have reached its publishing stage.

    About the Reviewers

    R. Surya Murali received his PhD in Chemical Engineering from Osmania University. He has seven years of research experience on Membrane technology for gas and liquid separations. He has worked as a senior research fellow and junior research fellow at the Indian Institute of Chemical Technology. He also has experience in the installation, operation, and maintenance of membrane separation systems at laboratory and pilot plant levels. He has developed expertise in the synthesis, modification, and characterization of various types of membranes for different membrane processes. He has also gained knowledge in developing simulation programs in Microsoft Excel, C, and MATLAB.

    I am thankful to my family and friends for their constant support and encouragement.

    Ashish Uthama is a developer in the Image Processing Toolbox team at Mathworks, makers of MATLAB. He has a Bachelor’s degree in Electronics and Communication from PESIT, Bangalore, India, and a Master’s degree in Applied Science from UBC, Vancouver, Canada.

    Alexander Wright is a computer vision programmer specializing in histopathological image analysis for the automated diagnosis of cancer patients. He has been using MATLAB and C++ in this domain since 2006 in collaboration with the School of Computing and the Section of Pathology, Anatomy and Tumour Biology, at the University of Leeds. Alex has co-authored many research articles that base their research on his image analysis algorithms, and is interested in the standardization of automated histology image analysis for routine clinical application. In his spare time, Alex enjoys performing image manipulation in MATLAB and Adobe Photoshop for web design projects, and playing his bass guitar at unnecessarily loud volumes.

    www.PacktPub.com

    Support files, eBooks, discount offers and more

    You might want to visit www.PacktPub.com for support files and downloads related to your book.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    http://PacktLib.PacktPub.com

    Do you need instant solutions to your IT questions? PacktLib is Packt’s online digital book library. Here, you can access, read and search across Packt’s entire library of books. 

    Why Subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print and bookmark content

    On demand and accessible via web browser

    Free Access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

    Preface

    Digital visual media has, undoubtedly, become a vital part of our everyday lives. Analog means of storing and processing information have gradually faded and are nowadays used either by aficionados of analog media, or for very specialized applications. Capturing and storing image or video information have rapidly become common, fast, and cheap processes, since almost everyone can have access to a digital electronic device that can be used for these aims, whether it is a photographic or video camera, or even a mobile phone. The outburst of visual media-capturing devices has led to an increase of amateur photographers and weekend filmmakers, who often have a problem deciding what software to use to process their stored images or videos. The rule of thumb is that free software solutions often have limited functionalities or are very complicated, while commercial solutions tend to be very expensive and sometimes do not provide all the functionalities that a user would hope for.

    This book presents a rather uncommon alternative solution that might not be considered by users who only need an image, or a video editing software, but could certainly appeal to users who are also students, scientists, or just have easy access to the multifunctional, high level programming environment, called MATLAB.

    What this book covers

    Chapter 1, Basic Image Manipulations, introduces you to the environment of MATLAB and takes you on a tour to its basic tools and functionalities. Then, image importing and displaying in MATLAB is discussed, followed by a demonstration of the MATLAB GUI for image manipulation. Basic image transformations are covered, such as rotating/flipping, resizing, and cropping an image. Finally, different ways of writing an image are presented. The chapter includes hands-on examples that tie most of the processes covered, together.

    Chapter 2, Working with Pixels in Grayscale Images, is based on examples of pixel-based processing of an image. Several classic processes for image enhancement are discussed, such as thresholding, local, or global contrast enhancement. The methods presented use several techniques that gently introduce you to the secrets of MATLAB programming. A practical example in image enhancement concludes this chapter.

    Chapter 3, Morphological Operations and Object Analysis, introduces the basic methods of morphological image analysis. In it, you will learn of ways to perform binarization of a grayscale image using the thresholding methods. Edge detection and other morphological operators are presented and explained, so that you learn how to select and manipulate particular image regions that interest you the most. You will also learn the techniques that automatically detect corners, circles, and lines in an image. Several hands-on examples will vividly demonstrate all these techniques.

    Chapter 4, Working with Color Images, extends previous methods to color images. Some of the processes mentioned for grayscale are now revisited for color image processing. Different color spaces and their advantages are explained with examples on color enhancement in MATLAB. You will learn how illumination and color can be separated and processed independently. The technique for color isolation is explained through a practical example and finally, some of the methods mentioned previously are used to teach you how to develop a popular application: red eye correction in your photographs.

    Chapter 5, 2-Dimensional Image Filtering, dives into some more complex issues for image filtering, such as deblurring and sharpening of images. You will get to work on more sophisticated techniques for image denoising. Some more interesting and fun examples will let you start enjoying your experience more deeply. We will work on ways to apply some of the filter locally, to enhance or blur specific image regions.

    Chapter 6, Mixing Images for Science or Art, will wake up the artist, or the scientist in you. You will learn the techniques that mix channels of multispectral images for scientific visualization. Then, we will present fun, hands-on examples for blending, or stitching images, to produce artistic results. We will also work on ways to create artistic HDR (High Dynamic Range) images in MATLAB. Finally, we will present a simple way to create panoramic images.

    Chapter 7, Adding Motion – From Static Images to Digital Videos, introduces you to video processing by building on the previous knowledge you have acquired. The fact, that videos can be generated by static images, will help you to better comprehend basic ideas. So, after covering the basics of video frame processing in MATLAB and demonstrating how we can load and play back videos, we will show how to create a video from static images. The construction of a time-lapse video is the basic hands-on example we will be working on in this chapter.

    Chapter 8, Acquiring and Processing Videos, demonstrates the functionalities of the image acquisition tool for MATLAB. You will be given step-by-step examples on ways to shoot video with your camera and use your computer as a Digital Video Recorder, using the special GUI tool contained in MATLAB. Video compression and basic color video processing techniques are also demonstrated in this chapter, accompanied by a discussion on performance issues.

    Chapter 9, Spatiotemporal Video Processing, introduces you to command line manipulation and processing of videos. After covering basic video frames manipulations in MATLAB, you will learn how to deinterlace videos, using intra-frame, inter-frame, or mixed techniques. Furthermore, spatiotemporal video filtering is presented, with hands-on examples to help you get the idea.

    Chapter 10, From Beginner to Expert – Handling Motion and 3-D, introduces you to methods of motion detection in videos. Building on basic knowledge, we will get to the point of creating a simple surveillance system in MATLAB. You will also be taught the basics of estimating motion using popular optical flow algorithms, included in one of the toolboxes of MATLAB. You will also be introduced to feature-based image registration for motion compensation. The working example for this will be video stabilization. Finally, we will introduce an example of three-dimensional video and cover a very basic and fun example of turning a regular video to a 3-D one.

    What you need for this book

    In order to practice what you read in this book, you should have access to a computer with an installed version of MATLAB. The screenshots you will see in this book are all taken from MATLAB Version R2012b, which was the most recent one at the time of writing this book. However, since MATLAB is also a programming language, you will not need to worry about any differences in the way R2012b looks compared to earlier versions. The great majority of the things we will cover in this book will be 100 percent compatible with most previous versions. In the rare cases, when we use a brand new functionality, we will also provide alternative solutions for previous versions.

    The most important thing to make sure of, however, is that you have to find an installed version of MATLAB that includes at least the two basic toolboxes for image and video processing: Image Processing Toolbox and Image Acquisition Toolbox. An extra toolbox, named Computer Vision Toolbox, will also be used for a very small part of video processing. Toolboxes are collections of ready-made functions for special purposes. For those of you with a little familiarity with programming, they could be thought of

    Enjoying the preview?
    Page 1 of 1