MASTERCLASS

# Getting images into a computer

### Lessons

#### Share

#### Transcript

Let’s summarise some of the key things that we have learned about getting images from the world into a computer where we can manipulate them with MATLAB.

We have looked at a number of examples about how we can load images from a file; load images live from a camera; load images from somebody else’s camera, a web camera attached to the internet somewhere on the planet; how to load frames from a movie file and we can even load frames from an online internet service like Google Earth.

What you will notice about all of these different approaches is that there’s some common patterns here. We create an image source object that might be a video camera object or an Axis web camera object or movie object and then we use one of the methods of that object, the grab method, to obtain the next image from that image source. So we are able to grab images a diversity of image sources, using software which varies only very, very little.

Now once we have the image into the MATLAB environment it is represented by a matrix; by a rectangular array of numbers. Every element within that array represents the intensity of light at the corresponding point in the real world.

We refer to these elements as picture elements, which is often contracted to pixel. The position of a pixel is defined by two coordinates. The horizontal coordinate which I denote by the symbol u, is the distance from the left-hand edge, and the vertical coordinate which I define by the symbol v, is defined as the distance from the top left-hand corner.

MATLAB is a computational environment for dealing with matrices, and the convention for matrices is that we index them using the row index first followed by the column index. Now the row is the vertical coordinate and the column is the horizontal coordinate. So there is a flip here between the normal way that we represent the coordinates in a rectangular frame or in a graph. Normally we would reference the horizontal coordinate followed by the vertical coordinate—we would write u,v as the coordinate of a pixel. In MATLAB, because we are indexing into a matrix we have to reverse that so we would write v,u.

Now this is confusing and it is a bit of a trap for people who are just starting out. It is really important to remember that the coordinates when you are indexing a matrix are reversed compared to the coordinates that you would use when you think about a two dimensional plane.

Let’s recap some of the most important topics we’ve covered about treating an image as a matrix within MATLAB which we can display or index into.

### Skill level

MATLAB experience

This content assumes an understanding of high school level mathematics; for example, trigonometry, algebra, calculus, physics (optics) and experience with MATLAB command line and programming, for example workspace, variables, arrays, types, functions and classes.