1 / 28

Chapter 2: Images and M ATLAB 2.1 Grayscale Images

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.

hadar
Download Presentation

Chapter 2: Images and M ATLAB 2.1 Grayscale Images

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

  2. imshow(w) figure impixelinfo 2.1 Grayscale Images • Creates a figure on the screen • A figure is a window in which a graphics object can be placed • displays the matrix w as an image • turns on the pixel values in our figure • They appear at the bottom of the figure in the form • Pixel Info: (X, Y) intensity

  3. 2.1 Grayscale Images cameraman.tif

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

  5. FIGURE 2.2

  6. 2.2 RGB Images • Multidimensional array • >>size(a) • 206 (rows) 345 (columns) 3 (pages) • >> a(100,200,2) • 25 • >> a(100,200,1:3) or >> a(100,200,:) • or functionimpixel • >> impexel(a,200,100) • 75 25 30

  7. 2.3 Indexed Color Images • >> figure, imshow(‘forest.tif’), impixelinfo • >> c=imread(‘forest.tif’); • >> figure, imshow(c), • impixelinfo

  8. 2.3 Indexed Color Images • >> [c, cmap]=imread(‘forest.tif’); • >> figure, imshow(c, cmap), impixelinfo • Information about Your Image • A great deal of information can be obtained with the imfinfo function • >> imfinfo(‘forest.tif’)

  9. 2.4 Data Types and Conversions

  10. 2.4 Data Types and Conversions

  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 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

  12. 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 (ch14) • TIFF • A very general format that supports different compression methods, multiple images per file, and binary, grayscale, truecolor, and indexed images

  13. 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

  14. FIGURE 2.3 • A HEXADECIMAL DUMP FUNCTION

  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

  16. 2.5.3 Microsoft BMP

  17. 2.5.3 Microsoft BMP

  18. 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-to-front: • 00 00 00 42 • Now we can convert to decimal • (4×161)+(2×160) = 66 which is the image width in pixels • The image height • 1F 00 00 00 (1×161)+(F×160) = 31

  19. 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

  20. 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

  21. 2.5.5 JPEG • The JPEG algorithm uses lossy compression, in which not all the original data can be recovered >> 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 ................

  22. 2.5.5 JPEG

  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

  24. 2.5.6 TIFF

  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 010100

  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

  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’);

  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.

More Related