You are previewing Visual Media Processing Using MATLAB Beginner's Guide.
O'Reilly logo
Visual Media Processing Using MATLAB Beginner's Guide

Book Description

Using the versatility and power of MATLAB to apply sophisticated effects to images and videos is easy for novice programmers in any language thanks to this fantastic guide. Also suitable for photographers and video-editors.

  • Apply sophisticated techniques to images and videos in just a few steps

  • Learn and practice techniques for enhancing and restoring your photographs

  • Create artistic photographs using simple methods

  • In Detail

    Whether you want to enhance your holiday photographs or make a professional banner image for your website, you need a software tool that offers you quick and easy ways to accomplish it. All-in-one tools tend to be rare, and Matlab is one of the best available.

    This book is a practical guide full of step-by-step examples and exercises that will enable you to use Matlab as a powerful, complete, and versatile alternative to traditional image and video processing software.

    You will start off by learning the very basics of grayscale image manipulation in Matlab to master how to analyze 3-dimensional images and videos using the same tool. The methods you learn here are explained and expanded upon so that you gradually reach a more advanced level in Matlab image and video processing.

    You will be guided through the steps of opening, transforming, and saving images, later to be mixed with advanced masking techniques both in grayscale and in color. More advanced examples of artistic image processing are also provided, like creating panoramic photographs or HDR images. The second part of the book covers video processing techniques and guides you through the processes of creating time-lapse videos from still images, and acquiring, filtering, and saving videos in Matlab.

    You will learn how to use many useful functions and tools that transform Matlab from a scientific software to a powerful and complete solution for your everyday image and video processing needs.

    Table of Contents

    1. Visual Media Processing Using MATLAB Beginner's Guide
      1. Table of Contents
      2. Visual Media Processing Using MATLAB Beginner's Guide
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Time for action – heading
          1. What just happened?
          2. Pop quiz – heading
          3. Have a go hero – heading
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      8. 1. Basic Image Manipulations
        1. Getting acquainted with the MATLAB environment
          1. Default subwindows of the environment
            1. The Command Window
            2. The Current Folder window
            3. The Details window
            4. The Workspace window
        2. The ribbon
          1. The HOME tab
          2. The PLOTS tab
          3. The APPS tab
        3. The editor
          1. The EDITOR window
        4. Importing and displaying an image
          1. Importing and displaying an image using the command line
        5. Time for action – importing and displaying an image
          1. What just happened?
          2. Importing and displaying an image using imtool
        6. Time for action – using imtool to extract useful information
          1. What just happened?
        7. Applying geometric transformations
          1. Performing image rotation
        8. Time for action – rotating an image and displaying the result
          1. What just happened?
          2. Performing image mirroring
        9. Time for action – mirroring an image and displaying the result
          1. What just happened?
          2. Have a go hero – using flipdim and comparing the results
          3. Resizing an image
          4. Cropping an image
          5. Saving an image
        10. Time for action – cropping and resizing an image, then saving it as BMP
          1. What just happened?
          2. Have a go hero – tailoring an image to suit your needs
          3. Pop quiz – image processing in MATLAB
        11. Summary
      9. 2. Working with Pixels In Grayscale Images
        1. Accessing image pixels and changing their values
          1. Changing the pixel values of a square area using loops
          2. Changing the pixel values of a square area using indexing
          3. Writing and using scripts
        2. Time for action – whiten an area and blacken another
          1. What just happened?
        3. Thresholding an image
          1. Image thresholding using for loops
          2. Image thresholding using indexing
          3. Image thresholding using im2bw
          4. Image thresholding using an automatic threshold
        4. Calculating and displaying histograms with imhist
        5. Histogram equalization for contrast enhancement
        6. Contrasting enhancement using imadjust
        7. Contrasting enhancement using imcontrast
        8. Adaptive histogram equalization using adapthisteq
        9. Custom functions for complex tasks
        10. Time for action – using imtool to pinpoint differences
          1. What just happened?
          2. Have a go hero – writing a function to enhance an image area
        11. Restoring old photographs
        12. Time for action – restoring your ancestors' photographs
          1. What just happened?
          2. Pop quiz – contrasting enhancement methods
        13. Summary
      10. 3. Morphological Operations and Object Analysis
        1. The importance of binary images
        2. Time for action – understanding the value of thresholding
          1. What just happened?
        3. Enlarging and shrinking a region of interest
        4. Time for action – using dilation and erosion to refine ROIs
          1. What just happened?
          2. Choosing a structuring element
          3. Using strel to generate structuring elements
        5. Altering structuring elements from strel to suit our needs
        6. Time for action – ROI refinement using strel
          1. What just happened?
          2. Have a go hero – write a function to for local dilation/erosion
            1. More morphological operations
        7. Manually defining a non-rectangular ROI
          1. Using roipoly to make a mask
          2. Using imfreehand to make a mask
        8. Time for action – making a custom object eraser function
          1. What just happened?
        9. Analyzing objects in an image
          1. Detecting edges in an image
          2. Detecting corners in an image
          3. Detecting circles in an image
          4. Pop quiz – object analysis pros and cons
        10. Summary
      11. 4. Working with Color Images
        1. An introduction to color image processing
        2. Basic color image manipulations
        3. Setting a rectangular area to a specified color
        4. Time for action – repainting two areas in a color image
          1. What just happened?
        5. Thresholding color images
        6. Time for action – isolating the red pixels in an image
          1. What just happened?
        7. Achieving color masking
        8. Time for action – color isolation
          1. What just happened?
        9. The importance of different color spaces
        10. Time for action – color space transformation
          1. What just happened?
        11. CIE-L*a*b* for more efficient color masking
        12. Time for action – color isolation using CIE-L*a*b*
          1. What just happened?
          2. Have a go hero – writing a function for region color isolation
        13. Fixing illumination issues in RGB color images
        14. Fixing illumination issues in CIE-L*a*b*
        15. A practical example – red eye reduction
        16. Time for action – writing a function for red eye reduction
          1. What just happened?
        17. Taking advantage of eye circularity
        18. Time for action – automating our function for red eye reduction
          1. What just happened?
          2. Pop quiz – working with color
        19. Summary
      12. 5. 2-Dimensional Image Filtering
        1. An introduction to image filtering
        2. Processing neighborhoods of pixels
        3. The basics of convolution
        4. The ugly mathematical truth
        5. Time for action – applying averaging filters in images
          1. What just happened?
        6. Alternatives to convolution
        7. Using imfilter
        8. Creating filters with fspecial
        9. Different ways to blur an image
        10. Time for action – how much blurring is enough
          1. What just happened?
        11. Time to make art using blurring
        12. Time for action – creating the bokeh effect in an image
          1. What just happened?
          2. Have a go hero – add a motion effect in your image
        13. Removing noise using blurring
        14. Time for action – trying to remove different types of noise
          1. What just happened?
        15. The importance of the median filter
        16. Time for action – removing salt & pepper with medfilt2
          1. What just happened?
          2. Have a go hero – denoising real images
        17. Bringing back the details
        18. Time for action – enhancing the edges in our images
          1. What just happened?
        19. Brighten up the lights
        20. Time for action – brighten up the lights in our soldier picture
          1. Pop quiz – image filtering in 2-dimensions
        21. Summary
      13. 6. Mixing Images for Science or Art
        1. The importance of mixing or combining images
        2. Using multispectral imaging
        3. Loading and manipulating the multispectral images
        4. Time for action – visible spectrum from a multiband image of Rio
          1. What just happened?
        5. Time for action – working with invisible spectrums
          1. What just happened?
        6. Creating composite images
          1. Using imfuse to create a composite image
          2. Using imshowpair to inspect a composite image
        7. Time for action – cloning the seagull
          1. What just happened?
          2. Have a go hero – playing Warhol with your pictures
        8. One step beyond – blending selected image regions
        9. Time for action – directing a threatening scene
          1. What just happened?
        10. Creating High Dynamic Range images
        11. Time for action – composing your own HDR images
          1. What just happened?
        12. Stitching images for the creation of panoramas
        13. Time for action – basic approach to panorama stitching
          1. What just happened?
          2. Pop quiz – image mixing details
        14. Summary
      14. 7. Adding Motion – From Static Images to Digital Videos
        1. An introduction to digital videos
        2. The meaning of frames
          1. Interlaced versus progressive
          2. Frame rates and their importance
          3. Calculating number of frames
          4. Some thoughts on choosing frame rates
        3. Loading videos in MATLAB
          1. Loading videos with aviread
          2. Loading videos with mmreader
          3. Loading videos with VideoReader
          4. Choosing which function to use for video reading
        4. Playing back videos in MATLAB
        5. Time for action – reading and playing back a video
          1. What just happened?
        6. Making videos from static images
        7. Time for action – constructing and saving a video
          1. What just happened?
          2. Have a go hero – make a video with a fade in/fade out effect
        8. Inspecting a video using montage
        9. Time for action – don't wait for the ball
          1. What just happened?
        10. A tool just for your playback needs – implay
          1. Using the GUI of implay
          2. Using implay to play a video file
          3. Using implay to play an image sequence
        11. Creating time-lapse videos
        12. Time for action – time-lapsing a regular video
          1. What just happened?
          2. Have a go hero – spinning our time-lapse
        13. Saving your time-lapse videos in a gif file
          1. Pop quiz – image filtering in 2-dimensions
        14. Summary
      15. 8. Acquiring and Processing Videos
        1. Using MATLAB for digital video recording
          1. The Hardware Browser window
          2. The Information window
          3. The Desktop Help window
          4. The Preview window
          5. The Acquisition Parameters window
            1. The General tab
            2. The Device Properties tab
            3. The Logging tab
            4. The Triggering tab
            5. The Region of Interest tab
          6. The Session Log window
        2. Time for action – capturing a video using a firewire connection
          1. What just happened?
          2. Have a go hero – adding a trigger to our recording
        3. The importance of video compression
          1. Checking the size of an uncompressed video
          2. Checking the size of an MP4 video without any motion
          3. Checking the size of an MP4 video with high motion
        4. Working with uncompressed videos
          1. Working with large videos in postproduction
        5. Time for action – making an edge detection video
          1. What just happened?
          2. Have a go hero – getting the last chunk of frames processed
          3. Pop quiz – what is the problem with our function?
        6. Acquiring frames for time-lapse videos
          1. Detecting your acquisition hardware
          2. Creating a video object and acquiring a frame
        7. Time for action – using MATLAB as an intervalometer
          1. What just happened?
          2. Have a go hero – creating a time-lapse creation function
        8. Real-time processing of time-lapse videos
        9. Time for action – creating time-lapses with isolated colors
          1. What just happened?
        10. Real-time processing of normal videos
          1. Evaluating real-time capabilities with a simple example
        11. Time for action – adjusting the contrast of the video
          1. What just happened?
          2. Revisiting the contrast adjustment example
        12. Time for action – adding preview in our code
          1. What just happened?
          2. Have a go hero – doubling the speed of our code
          3. Pop quiz – acquiring and processing videos
        13. Summary
      16. 9. Spatiotemporal Video Processing
        1. Basic video processing with MATLAB
          1. Cropping and resizing our video
        2. Time for action – loading, cropping, resizing, and saving a video
          1. What just happened?
          2. Have a go hero – adding rotation and more error-checking
          3. Filtering your video frames
        3. Time for action – reducing the blocking effect
          1. What just happened?
        4. Deinterlacing videos in MATLAB
          1. Intra-frame filtering for deinterlacing tasks
        5. Deinterlacing with the Computer Vision System Toolbox
        6. Time for action – deinterlacing a video using the vision toolbox
          1. What just happened?
          2. Have a go hero – comparing the deinterlacing methods
        7. Deinterlacing with the custom functions
        8. Time for action – deinterlacing with line repetition
          1. What just happened?
        9. Time for action – deinterlacing with the scan line interpolation
          1. What just happened?
          2. Have a go hero – comparing the deinterlacing methods
        10. Inter-frame filtering for the deinterlacing tasks
          1. Temporal deinterlacing by field merging
        11. Time for action – deinterlacing with field merging
          1. What just happened?
          2. Have a go hero – evaluating the field merge method
        12. Temporal deinterlacing by field averaging
        13. Time for action – deinterlacing with field averaging
          1. What just happened?
        14. Mixing intra-frame and inter-frame deinterlacing
          1. Vertical and temporal interpolation for deinterlacing
        15. Time for action – vertical and temporal interpolation method
          1. What just happened?
          2. Have a go hero – Comparing deinterlacing techniques
        16. Adding a new dimension to the filters
          1. Spatiotemporal averaging filter
        17. Time for action – implementing a spatiotemporal averaging filter
          1. What just happened?
          2. Have a go hero – creating a spatiotemporal median filter
          3. Using convolution for spatiotemporal averaging
        18. Time for action – spatiotemporal averaging filter with the convn function
          1. What just happened?
          2. Pop quiz – videos and filters
        19. Summary
      17. 10. From Beginner to Expert – Handling Motion and 3-D
        1. Detecting and estimating motion in videos
          1. Detecting motion
        2. Time for action – detecting a moving object in a still scene
          1. What just happened?
        3. Time for action – detecting motion in a complex scene
          1. What just happened?
          2. Have a go hero – making your own surveillance system
        4. Estimating the motion
          1. Estimating motion using optical flow
        5. Time for action – tracking people with Horn-Schunck optical flow
          1. What just happened?
          2. Have a go hero – estimating optical flow using Lucas-Kanade
        6. Time for action – warping frames using optical flow
          1. What just happened?
          2. Have a go hero – making your own surveillance system
        7. Compensating camera motion using feature tracking
        8. Time for action – tracking feature points for motion compensation of a shaky video
          1. What just happened?
          2. Have a go hero – tweaking the settings of the stabilization demo
        9. Working with stereoscopic images
        10. Time for action – creating a 3-D video from left and right videos
          1. What just happened?
        11. Time for action – creating a 3-D video from a regular one
          1. What just happened?
          2. Have a go hero – writing a function for 3-D video creation
          3. Pop quiz –working with video frames
        12. Summary
      18. A. Pop Quiz Answers
        1. Chapter 1, Basic Image Manupulation
          1. Pop quiz – image processing in Matlab
        2. Chapter 2, Working with Pixels in Grayscale Images
          1. Pop quiz – contrasting enhancement methods
        3. Chapter 3, Morphological Operations and Object Analysis
          1. Pop quiz – object analysis pros and cons
        4. Chapter 4, Working with Color Images
          1. Pop quiz – working with color
        5. Chapter 5, 2-Dimensional Image Filtering
          1. Pop quiz – image filtering in 2-dimensions
        6. Chapter 6, Mixing Images for Science or Art
          1. Pop quiz – image mixing details
        7. Chapter 7, Adding Motion – From Static Images to Digital Videos
          1. Pop quiz – image filtering in 2-dimensions
        8. Chapter 8, Acquiring and Processing Videos
          1. Pop quiz – what is the problem with our function?
          2. Pop quiz – acquiring and processing videos
        9. Chapter 9, Spatiotemporal Video Processing
          1. Pop quiz – videos and filters
        10. Chapter 10, From Beginner to Expert – Handling Motion and 3-D
          1. Pop quiz – working with video frames
      19. Index