Since it was first released, MATLAB has been associated with technical computing and scientific programming. Due to its high uptake in academia and its large and active community, it has grown to become a versatile and multifunctional tool, providing solutions in a vast diversity of fields. Its usage in image and video processing for scientific applications has been popular for a while, but more recent versions have included processing tools that are more user-friendly and aimed at a broader spectrum of users. The usefulness of MATLAB for image processing is rather self-explanatory, since it is a programming environment specialized for matrix manipulation and images are nothing more than matrices.
In this chapter, you will be introduced to the very basics of image manipulation using MATLAB. Prior experience in using MATLAB is not required, since we will be covering everything from scratch. Some basic understanding of programming would be beneficial.
More specifically, in this chapter we will cover:
So, let's get started.
In order to be able to start working with MATLAB, you should install it on your system. Since the installation is a very straightforward process, we will not cover it here. The only thing you have to be certain of, is that your installation includes the Image Processing and Image Acquisition toolboxes, which are necessary for the purposes of this book. A few examples towards the end will also need the Computer Vision System Toolbox in order to work. The version of MATLAB we will be using is 2012b, the latest available version at the time of writing this book.
The first thing we see when opening MATLAB 2012b is a window comprising other windows and a ribbon with various toolbars. The ribbon has grouped sets of many processes that can be helpful for a beginner, but may prove distracting when the user has acquired more experience. This is why, besides giving a few details in this chapter, we will be avoiding extensive use of the ribbon, limiting it to the most time-saving and relevant processes to digital media processing. The subwindows residing in the environment of MATLAB will be our basic tools in this book, along with the MATLAB editor, which is the basic core tool for writing your own scripts and functions.
The pre-set windows you will face when first using the application will be:
Downloading the example code
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
It is worth noting that the environment of MATLAB 2012b has been altered significantly compared to previous versions, mainly because of the inclusion of a ribbon menu resembling the one used in Microsoft Office 2007 onward. However, since most of the processes described in this book are based on using the command line, users of previous versions will not have problems following the examples.
Most of the MATLAB usage time will probably be spent on typing commands in the command line. The command line resides in the Command Window and starts with the symbol fx which is clickable and contains a list of all installed functions organized by toolbox. Following this symbol, there is the prompt symbol, >>, followed by a blinking cursor at the place where you can enter commands. All codes that must be written in the command line will be preceded by the prompt symbol in this book.
The available commands are all the inherent MATLAB functions, most of which help you manipulate matrices (hence the name: MATrixLABoratory). In this book, we will mainly be using functions for image manipulation, included in the Image Processing and Image Acquisition toolboxes.
The Current Folder window is basically a file manager, resembling Windows Explorer. You can navigate your way through the folders in your computer, in order to find files you would like to use in your work, for example, an image you would like to load. By default, MATLAB can access the contents of the current folder and a number of folders that have been included in its path. During installation, all the folders containing the installed toolboxes have been added to MATLAB's path; hence the functions and files contained in them can be accessed no matter what the current folder is.