chapter 2: images and m atlab 2.1 grayscale images

28
1 Chapter 2: Images and MATLAB 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 >> help imdemos >> w=imread(‘caeraman.tif’); >> figure, imshow(w); impixelinfo

Upload: hadar

Post on 22-Feb-2016

79 views

Category:

Documents


0 download

DESCRIPTION

Chapter 2: Images and M ATLAB 2.1 Grayscale Images. M ATLAB is a data analysis software package with powerful support for matrices and matrix operations Command window Reads pixel values from an image. >> help imdemos. >> w=imread(‘caeraman.tif’); >> figure, imshow(w); impixelinfo. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

1

Chapter 2: Images and MATLAB2.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 >> help imdemos

>> w=imread(‘caeraman.tif’); >> figure, imshow(w); impixelinfo

Page 2: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

2

• displays the matrix w as an image

turns on the pixel values in our figureThey appear at the bottom of the figure in the form

2.1 Grayscale Images

• Creates a figure on the screenA figure is a window in which a graphics object

can be placed

figure

imshow(w)

impixelinfo

Pixel Info: (X, Y) intensity

Page 3: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

3

2.1 Grayscale Images

cameraman.tif

Page 4: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

4

2.2 RGB Images >> a=imread(‘autumn.tif’); >> figure, imshow(a), impixelinfo

Page 5: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

5

FIGURE 2.2

Page 6: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

6

>> a(100,200,1:3) or >> a(100,200,:) or function impixel>> impexel(a,200,100)75 25 30

2.2 RGB Images• Multidimensional array >> size(a)

206 (rows) 345 (columns) 3 (pages) >> a(100,200,2)25

Page 7: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

7

2.3 Indexed Color Images

>> c=imread(‘forest.tif’); >> figure, imshow(c), impixelinfo

>> figure, imshow(‘forest.tif’), impixelinfo

Page 8: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

8

2.3 Indexed Color Images

• Information about Your Image• A great deal of information can be obtained with

the imfinfo function

>> [c, cmap]=imread(‘forest.tif’); >> figure, imshow(c, cmap), impixelinfo

>> imfinfo(‘forest.tif’)

Page 9: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

9

2.4 Data Types and Conversions

Page 10: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

10

2.4 Data Types and Conversions

Page 11: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

11

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

• Header informationThis 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

Page 12: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

12

• The imread and imwrite functions of MATLAB currently support the following formats

JPEGThese images are created using the Joint Photographics Experts Group compression method (ch14)

TIFFA very general format that supports different compression methods, multiple images per file, and binary, grayscale, truecolor, and indexed images

2.5 Images Files and Formats

Page 13: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

13

GIFA venerable format designed for data transfer. It is still popular and well supported, but is somewhat restricted in the image types it can handle

BMPMicrosoft Bitmap format has become very

popular and is used by Microsoft operating systems

PNG, HDF, PCX, XWD, ICO, CUR

2.5 Images Files and Formats

Page 14: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

14

• A HEXADECIMAL DUMP FUNCTION

FIGURE 2.3

Page 15: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

15

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

• 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

Page 16: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

16

2.5.3 Microsoft BMP

Page 17: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

17

2.5.3 Microsoft BMP

Page 18: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

18

The image width is given by bytes 18–21; they are in the second row42 00 00 00

To find the actual width, we reorder these bytes back-to-front:00 00 00 42

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 height1F 00 00 00 (1×161)+(F×160) = 31

Page 19: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

19

• 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

2.5.4 GIF and PNG

Page 20: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

20

• 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

2.5.4 GIF and PNG

Page 21: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

21

• The JPEG algorithm uses lossy compression, in which not all the original data can be recovered

2.5.5 JPEG

>> dumphex('football.jpg',4)

ans =

FF D8 FF E0 00 10 4A 46 49 46 00 01 01 00 00 01 ......JFIF......00 01 00 00 FF DB 00 43 00 03 02 02 03 02 02 03 .......C........03 03 03 04 03 03 04 05 08 05 05 04 04 05 0A 07 ................07 06 08 0C 0A 0C 0C 0B 0A 0B 0B 0D 0E 12 10 0D ................

Page 22: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

22

2.5.5 JPEG

Page 23: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

23

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

Page 24: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

24

2.5.6 TIFF

Page 25: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

25

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 E0. This works out to 66016.

E0 01 01 00

Page 26: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

26

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

Page 27: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

27

2.5.8 Files in MATLAB

• Which writes the image stored in matrix X with color map map (if appropriate) to file filename with format fmt

• Without the map argument, the image data is supposed to be grayscale or RGB

e.g. >>imwrite(c,cmap,’forest.png’,’png’);>>imwrite(c,’forest1.png’,’png’);

Page 28: Chapter 2: Images and M ATLAB 2.1 Grayscale Images

28

Exercise

• The following shows the hexadecimal dump of a BMP file:

42 4D 7E 05 02 00 00 00 00 00 36 04 00 00 28 00 00 00 23 01 00 00 C2 01 00 00 01 00 08 00 00 00 00 00 48 01 02 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 01 01 01 00 02 02

Determine the height and width of this image (in pixels) and state whether it is a grayscale or color image.