What will we learn?
How is a digital image represented and stored in
memory?
What are the main types of digital image representation?
What are the most popular image file formats?
What are the most common types of image processing
operations and how do they affect pixel values?
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Image: Visual representation (2D) of an object /
person / scene (3D)
Digital image: Representation of 2D image using a
finite number pixels.
Digital Image: is essentially a 2D matrix of real
numbers.
Monochrome Images: f ( x , y ) where x denotes the
row number and y represents the column number
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Image coordinate convention
NB: There is no universally accepted convention or notation. Always check carefully!
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Mathematical notation (0-based array notation)
The value of function f(x , y)at pixel (x0 , y0) is denoted by
f(x0 , y0) and represents the intensity or gray level of the
image at that pixel.
Range: 0.0 (Black) – 1.0 (White) double
0 (Black) – 255 (White) uint8
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
MATLAB representation (1-based array notation)
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Raster Vs Vector
Two different ways of encoding the contents of a
2D image in digita format:
Raster (Bitmap) representation stores graphics as 2-D arrays (one
or more) of pixels.
Vector formats use a series of drawing commands to store
graphics as geometric objects.
Advantages of Bitmap: Quality and Display Speed
Disadvantages of Bitmap: Large memory requirements and Size
Dependence
Advantages of Vector: Less memory requirement, Allows resizing
and geometric manipulations w/o introducing artifacts; BUT
Disadvantages of Vector: Need to be rasterized for most
presentation devices.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Raster Vs Vector
• In either case, there is no such a thing as a perfect digital representation of an image.
Artifacts due to finite resolution, color mapping, and many others will always be present.
• The key to selecting an adequate representation is to find a suitable compromise b/w:
• size (in bytes),
• subjective quality, and
• interoperability of the adopted format or standard.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Binary / Bilevel (1-bit) images
Encoded as 2D array of pixels, with 1 bit per pixel
A 0 usually means “black” and a 1 means “white”.
Usually suitable for images containing simple graphics, text, or line art
Main advantage : Small size
In MATLAB: represented using a logical array of 0s and 1s.
logical convert numerical to logical values
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Binary / Bilevel (1-bit) images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Binary / Bilevel (1-bit) images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Gray-level / Gray Scale / Intensity images
Encoded as 2D array of pixels, usually with 8 bits per pixel
A 0 usually means “black”, a 255 means “white”, and intermediate
values indicate varying shades of gray
In MATLAB: Intensity images can be represented using different data
types (or classes): uint8 [0, 255], uint16 [0, 65535], or double
[0.0, 1.0].
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Gray-level / Gray Scale / Intensity images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Gray-level / Gray Scale / Intensity images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Color images :
Two common ways of storing color image contents are:
RGB (a.k.a Trucolor) representation :
Indexed (a.k.a Pseudocolor) representation:
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Color images : Two common ways of storing color image contents are:
RGB (a.k.a Trucolor) representation :
Each pixel is usually represented by a 24-bit number containing the
amount of its Red (R), Green (G), and Blue (B) components.
i.e., each pixel is specified by three values — one each for the red, blue,
and green components of the pixel's color — 8 bits each.
Truecolor images are stored as an m-by-n-by-3 data array that defines
red, green, and blue color components for each individual pixel.
Truecolor images do not use a colormap.
The color of each pixel is determined by the combination of the red,
green, and blue intensities stored in each color plane at the pixel's
location.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Color images : Two common ways of storing color image contents are:
Indexed (a.k.a Pseudocolor) representation:
An indexed image consists of a 2D array and a colormap matrix.
The pixel values in the array are direct indices into a colormap / color
palette / LUT
The colormap matrix is an m-by-3 array of class double containing
floating-point values in the range [0,1].
The colormap is of fixed maximum size (usually m=256 colors).
Each row of map specifies the red, green, and blue components of a
single color.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Color Planes of a 24-
bit (true color) RGB
images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
24-bit (true color) RGB images
• A pixel whose color
components are (0,0,0) is
displayed as black, and a pixel
whose color components are
(1,1,1) is displayed as white.
• Thus a mix of these three
colors can result in 256 × 256
× 256 = 16,777,216 different
colors!
• See it for yourself !!!
Open MS Office and see the
Color Mixer.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
24-bit (true color) RGB images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
32-bit (true color) RGB images
• Includes a fourth channel, called
alpha channel.
•Alpha provides a measure of
transparency for each pixel and is
widely used in image editing
effect.
• = 0% fully transparent (invisible)
• = 100% a fully opaque pixel
(traditional digital images).
• Values between 0% and 100% make it
possible for pixels to show through a
background like a glass (translucency), an
effect not possible with simple binary
(transparent or opaque) transparency.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Indexed color images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Indexed color images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Digital image representation
Indexed color images
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Compression
Raw Images = Large amount of data
Most image file formats employ some type of compression.
Compression methods can be:
Lossy: a tolerable degree of deterioration in the visual quality
of the resulting image is acceptable.
Lossless: the image is encoded in its full quality.
As a general guideline:
lossy compression should be used for general purpose
photographic images;
lossless compression should be used for line art, drawings,
facsimiles, or images in which no loss of detail may be
tolerable (e.g., space images and medical images).
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Compression
The overall results of the compression process in terms
of both storage savings and resulting quality loss (for
lossy techniques) may vary depending on the:
Technique
Format
Options (such as the quality setting for JPEG), and
Actual image contents.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Compression
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Compression
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Compression: Lossless Vs Lossy
= original
original
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Compression: Lossless Vs Lossy
(A) Uncompressed TIFF
image (Brain MRI)
(B) TIFF image with
lossless
compression
(C) uncompressed
JPEG image
(D) JPEG image with
lossy compression
(reduction of image
quality to 80% of
original),
(E) JPEG image with
lossy compression
(reduction of image
quality to 40% of
original) and
(F) JPEG image with
lossy compression
(reduction of image
quality to 10% of
original).
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Image file formats
Image file contents:
File header: (info. About image height, width, no. of bands, no. of
bpp, and signature bytes indicating file type info. About compression /
decompression)
Pixel data: often compressed
Ex: GIF uses an indexed representation for color images (with a palette of a
maximum of 256 colors), the LZW (Lempel–Ziv–Welch) compression algorithm, and
a 13-byte header.
Most Common File Types:
BIN, PPM, PBM, PGM, PNM, BMP, JPEG, GIF, TIFF, PNG
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Image file formats
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Image file formats
Choosing between these file types is largely a matter of
assessing:
The nature the image ( a “photographic” collection of smooth tonal
transitions or a diagrammatic image with hard edges and lines?)
The effect of various kinds of file compression on image quality
The efficiency of a compression technique in producing the smallest file
size that looks good
Actually we are looking for a compromise between the quality of the image
and the file size.
➢ For photographic type images, JPG is best
➢ For logos or images with blocks of flat colour and no gradients, GIF or PNG8
➢For images using effects such as drop shadows or glows, which also require
transparency, choose PNG24.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Image file formats
From a MATLAB perspective, it doesn’t really
matter much...
Prof. Alasdair McAndrew: “You can use MATLAB for image
processing very happily without ever really knowing the
difference between GIF, TIFF, PNG, and all the other
formats.”
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Image topology
Image topology is the field of image processing concerned
with investigation of fundamental image properties (e.g.,
number of connected components and number of holes in an
object) using concepts such as adjacency and connectivity.
Usually done on binary images
Done with the help of morphological operations like dilation and erosion
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Neighborhood
The pixels surrounding a given pixel constitutes its neighborhood.
Represented as smaller matrix with an odd number of pixels usually
centered around reference pixel.
33 Neighborhood
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Neighborhood
In the context of image topology, neighborhood has a different meaning:
4-Neighborhood: Set of pixels situated above, below, to the right, and to the
left of the reference pixel (p),
8-Neighborhood: Set of all of p’s immediate neighbors
Diagonal Neighborhood: Pixels that belong to the 8-neighborhood, but not to
the 4-neighborhood, make up the diagonal neighborhood
N4 +ND = N8
4-Neighborhood Diagonal Neighborhood 8-Neighborhood
(a.k.a Edge Neighborbood) (a.k.a Point Neighborbood)
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Adjacency
Two pixels p and q are 4-adjacent if they have the same value and are
4-neighbors of each other
You can’t move diagonally
Two pixels p and q are 8-adjacent if they have the same value and are
8-neighbors of one another.
You can move diagonally but it may arise redundant paths
A third type of adjacency known as mixed adjacency (a.k.a. m-
adjacency) is often used to eliminate ambiguities (redundant paths) that
may arise when 8-adjacency is used.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Mixed Adjacency
Two pixels p and q are m-adjacent if they have the same value and
q is in the set N4(p) OR
q is in the set ND(p) AND the set N4(p) N4(q) is empty.
m-adjacency is a modified form of 8-adjacency
It is used to eliminate redundant paths
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Mixed Adjacency
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Paths
A 4-path between two pixels p and q is a sequence of pixels starting with p
and ending with q such that each pixel in the sequence is 4-adjacent to its
predecessor in the sequence.
An 8-path indicates that each pixel in the sequence is 8-adjacent to its
predecessor.
Similarly, an m-path indicates that each pixel in the sequence is m-adjacent
to its predecessor.
Connectivity
If there is a 4-path between pixels p and q, they are said to be 4-connected.
The existence of an 8-path between them means that they are 8-connected.
If an m-path can be draw between two pixels they are m-connected.
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Connectivity
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.
Basic terminology
Paths and Connectivity 4-connected paths
8-connected but not 4
Pattern that is not 8-connected
By Oge Marques Copyright © 2011 by John Wiley & Sons, Inc. All rights reserved.