Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Images and Matlab

Prof. Eric Miller


elmiller@ece.tufts.edu

Fall 2007 EN 74-ECE Image Processing Lecture 2-1


Representation of Images
• All images in this class are going to be
discrete
• Represented as information defined on
an array (pixels)
• Array indexed by rows, columns, or
lexicographically
• Different types of images have different
stuff at each pixel
Fall 2007 EN 74-ECE Image Processing Lecture 2-2
Images
Columns
1 2 3 N • Mostly work with row and
1 1 M+1 2M+1 column indexing
2 2 M+2 X(2,2) = information
3 3 in pixel on row 2
and column 2 in
Rows

image X

• Occasionally, want to use


single index
M-1 M-1 X(M+2) = info. in pixel
M M MN on row 2 and column
2 in image X

Fall 2007 EN 74-ECE Image Processing Lecture 2-3


Types of Images
• x(m,n) = 0 or 1: binary image
• x(m,n) = 0, 1, 2, … P-1: grayscale image
– P typically something like 256, 512 or some power of 2.
– 256 is really the most common
– 0 = black, P = white
• x(m,n) = [0 to P-1, 0 to P-1, 0 to P-1]
– Red, green, blue color image
– Like three grayscale images
• x(m,n) = index into color map.
– Color map = three column table with all possible colors
– Image index says which row in that table gives RBG values
for that pixel
– So long as table is known, very easy to store indices

Fall 2007 EN 74-ECE Image Processing Lecture 2-4


Examples
Binary

Grayscale (256 levels)

RGB

How to tell
difference?
Indexed
Fall 2007 EN 74-ECE Image Processing Lecture 2-5
Matlab
• Wonderful tool for doing all sorts of
computational things
• We’ll use it here for image processing
• Resources
– Formal tutorial on the class web site.
• See especially sections 1, 2, 3, 4, 9, 12
– Appendix to the text
– Code used in class posted to the web site
• Can always type “help command”

Fall 2007 EN 74-ECE Image Processing Lecture 2-6


Matlab Concepts Covered
• Reading images with imread
• Plotting images with imshow
• Getting pixel values with impixelinfo
– NOT pixval as in the text Making a figure window
with figure
• Getting image file information with imfinfo
• Multiple plots using subplot
• Printing information to screen using disp
• Indexing arrays using colon :
• Use of semicolon to suppress output

Fall 2007 EN 74-ECE Image Processing Lecture 2-7


Image File Formats
• Standards for storing images on
computers
• Some better than others for different
things (e.g. compression)
• imread will deal with all of the ones we
care about

Fall 2007 EN 74-ECE Image Processing Lecture 2-8


Common Formats
• BMP
– Microsoft format
– Header followed by pixel information
– Lossless compression
• GIF, PNG
– Compuserve
– Color only
– Lossless compression
– More than one image per file

Fall 2007 EN 74-ECE Image Processing Lecture 2-9


Formats
• JPEG (Joint Photographicc Experts
Group)
– Lossy compression so much smaller files
• TIFF (Tagged Image File Format)
– All sorts of compression
– All sorts of storage schemes
– All sorts of color schemes

Fall 2007 EN 74-ECE Image Processing Lecture 2-10


JPEG Header
Field Size (bytes) Description
APP0 Marker 2 Always equals 0xFFE0
Length 2 Length of segment excluding APP0 marker
Identifier 5 Always equals "JFIF\x00" (0x4A46494600)
Version 2 First byte is major version (currently 0x01),
Second byte is minor version (currently 0x02)
Density Units 1 Units for pixel density fields
* 0 - No units, aspect ratio only specified
* 1 - Pixels per Inch
* 2 - Pixels per Centimetre
X Density 2 Integer horizontal pixel density
Y Density 2 Integer vertical pixel density
Thumbnail Width 1 Horizontal size of embedded JFIF thumbnail in pixels
Thumbnail Height 1 Vertical size of embedded JFIF thumbnail in pixels
Thumbnail Data 3*W*H Uncompressed 24 bit RGB raster thumbnail

Fall 2007 EN 74-ECE Image Processing Lecture 2-11


BMP Header

Fall 2007 EN 74-ECE Image Processing Lecture 2-12


Matlab Data Types
• Different means of representing numbers
depending on what you want to do
• Examples:
– Floating point numbers for scientific applications
• 2.3543, -7.8956
– Integers: 1, 2, -7, 6354, -2333430948
– Unsigned integers for positive things (like pixel
values): 255, 7, 0
• Question: Can computers represent numbers
like π or e?

Fall 2007 EN 74-ECE Image Processing Lecture 2-13

You might also like