Introduction to Digital Image Processing with MATLAB Asia
Introduction to Digital Image Processing with MATLAB® Asia Edition Mc. Andrew‧Wang‧Tseng Chapter 2: Images and MATLAB 1 © 2010 Cengage Learning Engineering. All Rights Reserved. 1
2. 1 Grayscale Images • MATLAB is a data analysis software package with powerful support for matrices and matrix operations ü Command window ü Reads pixel values from an image 2 Ch 2 -p. 21 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 1 Grayscale Images • figure ü Creates a figure on the screen ü A figure is a window in which a graphics object can be placed 3 Ch 2 -p. 22 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 1 Grayscale Images • imshow(w) ü displays the matrix w as an image pixval on ü turns on the pixel values in our figure ü They appear at the bottom of the figure in the form 4 Ch 2 -p. 22 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 2. 1 5 Ch 2 -p. 23 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 2 RGB Images Note that the command pixval on may be removed in a later MATLAB version 6 Ch 2 -p. 23 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 2. 2 7 Ch 2 -p. 24 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 2 RGB Images • Multidimensional array ü 206 (rows) 345 (columns) 3 (pages) ü 25 8 Ch 2 -p. 24 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 2 RGB Images or or function impixel ü 75 25 30 9 Ch 2 -p. 25 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 3 Indexed Color Images 10 • >> figure, imshow(‘trees. tif’) • >> em = imread(‘trees. tif’); >> figure, imshow(em) Ch 2 -p. 25 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 3 Indexed Color Images • >> [em, emap] = imread(‘trees. tif’); >> figure, imshow(em, emap) • Information about Your Image • A great deal of information can be obtained with the imfinfo function 11 Ch 2 -p. 26 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 4 Data Types and Conversions 12 Ch 2 -p. 28 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 4 Data Types and Conversions 13 Ch 2 -p. 28 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5 Images Files and Formats • You can use MATLAB for image processing very happily without ever really knowing the difference between GIF, TIFF, PNG, etc. • However, some knowledge of the different graphics formats can be extremely useful in order to make a reasoned decision 14 Ch 2 -p. 29 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5 Images Files and Formats • Header information ü This will, at the very least, include the size of the image in pixels (height and width) ü It may also include the color map, compression used, and a description of the image 15 Ch 2 -p. 29 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5 Images Files and Formats • The imread and imwrite functions of MATLAB currently support the following formats ü JPEG These images are created using the Joint Photographics Experts Group compression method (ch 14) üTIFF A very general format that supports different compression methods, multiple images per file, and binary, grayscale, truecolor, and indexed images 16 Ch 2 -p. 30 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5 Images Files and Formats üGIF A venerable format designed for data transfer. It is still popular and well supported, but is somewhat restricted in the image types it can handle ü BMP Microsoft Bitmap format has become very popular and is used by Microsoft operating systems üPNG, HDF, PCX, XWD, ICO, CUR 17 Ch 2 -p. 30 © 2010 Cengage Learning Engineering. All Rights Reserved.
FIGURE 2. 3 • A HEXADECIMAL DUMP FUNCTION 18 Ch 2 -p. 30 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 1 Vector versus Raster Images • We may store image information in two different ways ü Vector images: a collection of lines or vectors ü Raster images: a collection of dots • The great bulk of image file formats store images as raster information 19 Ch 2 -p. 31 -32 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 2 A Simple Raster Format • As well as containing all pixel information, an image file must contain some header information ü this must include the size of the image, but may also include some documentation, a color map, and the compression used ü e. g. PGM format was designed to be a generic format used for conversion between other formats 20 Ch 2 -p. 32 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 3 Microsoft BMP 21 Ch 2 -p. 33 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 3 Microsoft BMP 22 Ch 2 -p. 33 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 3 Microsoft BMP ü The image width is given by bytes 18– 21; they are in the second row 42 00 00 00 ü To find the actual width, we reorder these bytes back-tofront: 00 00 00 42 23 Ch 2 -p. 34 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 3 Microsoft BMP ü Now we can convert to decimal (4× 161)+(2× 160) = 66 which is the image width in pixels ü The image height 1 F 00 00 00 (1× 161)+(F× 160) = 31 24 Ch 2 -p. 34 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 4 GIF and PNG • GIF ü Colors are stored using a color map. The GIF specification allows a maximum of 256 colors per image ü GIF doesn’t allow binary or grayscale images, except as can be produced with RGB values ü The pixel data is compressed using LZW (Lempel-Ziv-Welch) compression ü The GIF format allows multiple images per file. This aspect can be used to create animated GIFs 25 Ch 2 -p. 34 -35 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 4 GIF and PNG • PNG ü The PNG format has been more recently designed to replace GIF and to overcome some of GIF’s disadvantages ü Does not rely on any patented algorithms, and it supports more image types than GIF ü Supports grayscale, true color, and indexed images ü Moreover, its compression utility, zlib, always results in genuine compression 26 Ch 2 -p. 35 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 5 JPEG • The JPEG algorithm uses lossy compression, in which not all the original data can be recovered 27 Ch 2 -p. 35 -36 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 5 JPEG 28 Ch 2 -p. 36 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 6 TIFF • One of the most comprehensive image formats • Can store multiple images per file • Allows different compression routines and different byte orderings • Allows binary, grayscale, truecolor or indexed images, and opacity or transparency • An excellent format for data exchange 29 Ch 2 -p. 36 -37 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 6 TIFF 30 Ch 2 -p. 37 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 6 TIFF • This particular image uses the little-endian byte ordering • The first image in this file (which is in fact the only image), begins at byte • Because this is a little-endian file, we reverse the order of the bytes: 00 01 01 E 0. This works out to 66016 31 Ch 2 -p. 37 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 7 DICOM • DICOM (Digital Imaging and Communications in Medicine) • Like GIF, may hold multiple image files • May be considered as slices or frames of a three dimensional object • The DICOM specification is huge and complex. Drafts have been published on the World Wide Web 32 Ch 2 -p. 37 -38 © 2010 Cengage Learning Engineering. All Rights Reserved.
2. 5. 8 Files in MATLAB • Which writes the image stored in matrix X with color map (if appropriate) to filename with format fmt • Without the map argument, the image data is supposed to be grayscale or RGB e. g. 33 Ch 2 -p. 38 © 2010 Cengage Learning Engineering. All Rights Reserved.
- Slides: 33