1 / 27

Ch. 2: Image Files and File Types

Understand the different file formats for images such as BMP, JPEG, GIF, PNG, TIFF, HDF, PCX, XWD, ICO, CUR. Learn how to read and manipulate image files in Python using libraries like scipy, numpy, and matplotlib.

orr
Télécharger la présentation

Ch. 2: Image Files and File Types

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. Ch. 2: Image Files and File Types Physically, an image file is a binary file, which can be shown in hexadecimal dump. Example: : img BMP format GIF format hexdump (‘img.bmp’, 64) hexdump (‘img.gif, 64)

  2. An image file contains (a) Header: Characteristics of image e.g., image size, color map, compression method, ….. (b) Image data: pixel values, index values 2.1 File Formats -- Different formats for different application purposes, e.g., transmission, storage, operation, …… BMP (Microsoft Bitmap Pattern) -- without compression, need larger storage

  3. JPEG (Joint Photo-graphics Experts Group) -- lossy compression, need smaller storage GIF (Graphics Interchange Format) -- lossless compression PNG(Portable Network Graphics) TIFF (Tagged Image File Format) HDF (Hierarchical Data Format) PCX (PC Paintbrush) XWD (X Window Dump) ICO (ICOns) CUR (CURsor) 2-3

  4. BMP Format Example:

  5. C/C++ Program • How to read a BMP image?

  6. // 0讀進灰階圖, 1讀進彩色圖

  7. GIF Format Colors are stored using a color map of 256 colors Pixel data is compressed using LZW compression Allow for multiple images per file A GIF file contains a header including 1. image size (in pixels), 2. color map, 3. color resolution (# bits per pixel), 4. flag indicating whether the color map is ordered, 5. color map size ………………………. -- for communication

  8. Header

  9. Example: GIF format

  10. PNG Format -- Support grayscale, true color, and indexed images Also support Gamma correction: associated different display systems Alpha channels: associate variable transparencies

  11. A PNG file consists of 4 critical chunks: IHDR : image dimensions and bit depth PLTE : color palette IDAT : image data IEND : end 5 ancillary chunks: pHYS: pixel size and aspect ratio bKGD: background color gAMA: gamma sRGB: RGB color space cHRM: primary chromaticites and white point

  12. Example IHDR: 2-13

  13. 2.2 Introduction to Python Python was first released in 1991 by Guido van Rossum. ○ Versions: Python 1.1 – 1.5, Python 1.5.2 (1999.4) -------------------------------------------------- Python 3.6.7 (2018.10.20) ○ Installation: (A) https://www.python.org/ (B) google  search “Python”  download  execute

  14. ○ Libraries: • Standard library: mathematics, internet protocols, • multimedia, system interfaces, file and data • handling, graphics interface design • Most used libraries: scipy (Scientific Python) : modules for optimization, numerical analysis, signal and image processing, diferential equation solvers. numpy (Numerical Python) : routines for array manipulation, functions for operating on arrays.

  15. matplotlib (Plotting library) : plotting tools. • Many functions have to be imported either by • importing their libraries or the functions needed ○ Interfaces: • IDLE (Integrated Development Environment): • bundled with the language • IPython: includes syntax highlighting, • automatic indentation, inline graphics

  16. Spyder: a graphics development environment with • integration of numpy, scipy, matplotlib, iPython • including a variable and file browser, integrated • editor, interface to Python debugger

  17. 2.2.1 Basic Use • Prompt: (a) IDLE - >>>, (b)iPython - In [#]: • Arithmetic: • // - integer division • ^ - bitwise conjunction • ** - exponentiation Examples: In : 37+42 Out : 79 In : 2**67 - 1 Out : 147573952589676412927L?

  18. In : 1.0/7 Out : 0.14285714285714285 In : 11/7 Out : 1 In : 11.0/7 Out : 1.57142857142857714 In : 11.0//7 Out : 1.0 * Python returns a value of the same type as the input

  19. Mathematical functions, in math, must be loaded • before they are available (import the math library) In : importmath Individual libraries (e.g., sqrt) are called as (math.sqrt) In : math.sqrt(3.0) Out :1.7320508075688772 In : from math import exp In : exp(1.5) Out :4.4816890703380645

  20. In : from math import (import all libraries ) In : sqrt(3.0) Out : 1.7320508075688772 In : sin(pi/6) Out : 0.49999999999999994 In : cos(pi/12) Out : 0.9659258262890683 • Import library with an alias In : importmath as m In : m.tan(pi/8) Out : 0.41421356237309503

  21. To see all math functions In : math. tab 2-22

  22. 2.2.2 Image I/O • Input images In : importskimage.io as io In : w = io.imread (‘wombats.png’) This takes the grayscale image wombats.pgn and puts it into array w. In : io.imshow (w) This shows array w as a grayscale image. 2-23

  23. Interactive display using ImageViewer method In : from skimage.viewer import ImageViewer as IV In : viewer = IV(w) In : viewer.show ( ) • Directly display the image In : io.imshow (‘wombats.png’)

  24. Output images In : io.imsave (x, ‘filename.abc’) Write an image array x to an image file. e.g., In : io.imsave (c, ‘camerman.pgn’) Write image array c to a PGN image. 2-25

  25. Homework 1: • Input a color image C(R,G,B); • 2. Transform the color image C into a • grayscale image O by O = (R+G+B)/3; • 3. Show images C and O.

  26. (B) Submit the assignment file through Moodle https://moodle.ntnu.edu.tw/ 27 (A) Prepare the assignment file File Name: NAME.HW# , e.g., 陳世旺.HW1 Content: (1) Input/Output images (2) Source code (3) Comments

More Related