image files and formats - sahand university of...

26
Image Formats and Files Jung-Ming Wang [email protected]

Upload: others

Post on 19-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Image Formats and Files

Jung-Ming [email protected]

Page 2: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Vector vs. Raster Images

• Vector images– Preserving sharpness after rescaling– Not good for natural scenes– Hard to construct

• Raster images– Contrastively

Page 3: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Raster Image

• Formed by a digital camera

http://zh.wikipedia.org/zh-tw/數位影像

Page 4: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Pixel Resolution

• N pixels high by M pixels wide → M×N

http://zh.wikipedia.org/zh-tw/灰階圖像

M

N

Page 5: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Color Depth

• Number of bits for a single pixel– 1-bit color: black and white– 8-bit color: gray-scale– 24-bit color: true color

Page 6: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

File Format

• Header: characteristics of the image– Size, color map, compression

method, ……• Data value:

– Pixel values, index values• Common formats

– BMP, GIF, PNG, JPEG, TIFF ……

Page 7: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Hexadecimal Dumps• Image file is often saved as a binary file.• Binary file can be shown in hexadecimal

dump.

Page 8: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

BMP Format

• BMP header format

Page 9: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com
Page 10: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com
Page 11: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

BMP Example

Page 12: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Little-Endian

• More significant bit is stored in larger memory address.– 3d 00 00 00 → 00 00 00 3d → 3x16+d →61

• Little-endianness: Intel, AMD• Big-endianness: Sun, Motorola• On Holy Wars and A Plea for Peace

– Computer, pp. 48-54, Oct 1981

Page 13: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

GIF Format

Page 14: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

GIF Example

Page 15: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

PNG Format• LZW (Lempel-Ziv-Welch) algorithm (1978)• Patents of Sperry, Unisys, and IBM (1983)• LZW published by Welch (1984)• GIF announced by CompuServe (1987 &

1989)• Unisys’ patent enforcement (1994)• “Burn All GIFs” campaign (1999)• Patents expired (2003-2006)

Page 16: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

JPEG Format• Encoding using DCT (Discrete Cosine

Transform)• A Fourier-related transform• Fourier transform simulator

– http://www.phy.ntnu.edu.tw/moodle/mod/resource/view.php?id=136

Page 17: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Steps of JPEG Compression

• Splitting the image into blocks of 8×8 pixels

• Applying DCT to each block• Storing the magnitudes of the low-

frequency components

Page 18: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

• Example: http://en.wikipedia.org/wiki/JPEG

Shift values Apply

DCT

Quantization

Page 19: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

TIFF Format

• A flexible, adaptable file format for handling images within a single file

• Color space: grayscale, RGB, YCbCr, CMYK, ……

• Compression: raw data, LZW, JPEG, …..

• Copyright holder: Aldus → Adobe

Page 20: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

• TIFF header

Page 21: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Reading Image File

• C/C++ programming• Visual programming• Matlab

Page 22: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

C/C++ Programming• Example: http://www.cs.ucsd.edu/classes/sp03/cse190-b/hw1/

Page 23: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

• Reading header information

Page 24: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Visual Programming

Page 25: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

References

• http://www.cs.umass.edu/~verts/cs32/endian.html• http://www.phy.ntnu.edu.tw/moodle/mod/resource/

view.php?id=136• http://en.wikipedia.org/wiki/JPEG

Page 26: Image Files and Formats - Sahand University of Technologyfa.bme.sut.ac.ir/Downloads/AcademicStaff/3/Courses/43/P1-3-Image... · Image Formats and Files. Jung-Ming Wang. jmgwang@gmail.com

Homework• Design a program to input and output a

color image.– You may download the program

“bmp_io.rar” fromhttp://www.cs.ucsd.edu/classes/sp03/cse190-b/hw1/

– Transform a color image C(R,G,B) into a grayscale image I by I = (R+G+B)/3.