Title: ? Image Files
1Ch. 2 Image Files and MATLAB
? Image Files
Types of file formats BMP Microsoft
Bitmap Pattern GIF Graphics
Interchange Format JPEG Joint
Photo-graphics Experts Group TIFF
Tagged Image File Format PNG
Portable Network Graphics HDF
Hierarchical Data Format PCX PC
Paintbrush XWD X Window Dump
ICO ICOns CUR CURsor
2- BMP ( Microsoft Bitmap Pattern )
- without compression, need larger storage
- JPEG ( Joint Photographics Experts Group )
- lossy compression, need smaller storage
- GIF (Graphics Interchange Format )
- lossless compression
- PNG (Portable Network Graphics)
3 Physically,
- An image file is a binary file, which can be
- shown in hexadecimal dump.
4An image file contains
- (a) Header Characteristics of image
- Image size, Color map, Compression
method - (b) Image data Pixel values, Index values
Header
5(No Transcript)
6(No Transcript)
7 Example
8(No Transcript)
9How to read a BMP image?
10C/C Program
- http//www.cs.ucsd.edu/classes/sp03/cse190-b/hw1/
11- Reading header information
12Open CV
- Download
- ftp//140.122.184.49876 ????? ????
- Setting
- http//iammic.pixnet.net/blog/post/34304039-visual
- studio-2010EFBC9Aopencv-2.3-
- E4BDBFE794A8-webcam
13// 0?????, 1?????
14Homework
1. Input a color image C(R,G,B) 2. Transform the
color image C into a grayscale image G by
G (RGB)/3 3. Show the input and output
images C and G.
- You may download the I/O program bmp_io.rar
- from
- http//www.cs.ucsd.edu/classes/sp03/cse190-b/hw1/
14
15 GIF Format
Name Name Name Size Description
Signature Signature Signature 6 bytes GIF87a or GIF89a
Global Descriptor Global Descriptor Global Descriptor 7 bytes Global descriptor
Width Width 2 bytes Width in pixels
Height Height 2 bytes Height in pixels
Flags Flags Bit 7 Global descriptor flags
Global color map Bits 4-6
Color resolution bits Bit 3
Pixel bits Bit 2-0
Background color Background color 1 bytes 1color depth
Aspect Ratio Aspect Ratio 1 bytes
16 17 Example
18 19Steps of Compression
- (1) Splitting the image into blocks of
- 88 pixels
- (2) Applying DCT to each block
- (3) Storing the magnitudes of the low-
- frequency components
20Example http//en.wikipedia.org/wiki/JPEG
Shift values
Apply DCT
Quantization
21? MATLAB
1. Introduction ? MATLAB (a) A data
analysis and visualization tool (b)
Powerful for matrix operations,
graphics, and programming ? Toolbox a set of
programs designed to support a
particular task e.g., image-processing
toolbox
22- ? Function accepts parameters and
- produces output matrix,
- string, graph, or figure
- e.g., sin, imread, imclose
- ? Command
- e.g.,
- gtgt sin(pi/3)
- gtgt c imread(cameraman.tif)
- gtgt a imclose(b)
- Not display the result on the
screen
23- Multiple commands can be put on a single line,
which are separated by commas - All data are considered to be matrices
- e.g.
- single value -- 11 matrix
- string -- 1n matrix of characters
24? Command window
2. Use of MATLAB
? prompt gtgt
25? Addition, subtraction, multiplication,
division, exponentiation
e.g., gtgt 22
26? Default format Internal double
precision Display 8 decimal places
Entering format returns to the default
format
27 sqrt, log, log10
pi built-in constant
283. Variables and Workspace
- Variable for storing value
a and b are displayed in the short format
29Internally, MATLAB stores their full values
Further calculations
303.1. Workspace
- -- contains all variables, their data types and
sizes - To open (1) use View menu, choose Workspace
- (2) use whos function
- Function who lists variables only
314. Matrices
gtgt a4 -2 -4 7 1 5 -3 2 6 -8 -5 -6 -7 3
0 1
324.1. Matrix Elements
m(i,j) corresponds to m(ir(j-1))
33 Extract multiple values from a matrix
gtgt 2316 ans 2 5 8 11
14
34- gtgt a(2,13)
- ans
- 1 5 -3
- gtgt a(24,3)
- ans
- -3
- -5
- 0
gtgt a(23,34) ans -3 2
-5 -6 gtgt a(3,) ans 6
-8 -5 -6 gtgt a(,2) gtgt a()
35- 4.2. Matrix Operations
- -- add, subtract, multiply, invert power
gtgt b2 4 -7 -4 5 6 3 -2 1 -8 -5 -3 0 -6 7
-1 b 2 4 -7 -4 5 6
3 -2 1 -8 -5 -3 0 -
6 7 -1
36(No Transcript)
37(No Transcript)
38 39(No Transcript)
40? Dot operators
- Dot multiplication c(i,j) a(i,j) b(i,j)
41- gtgt a./b
- Warning Divide by zero.
- ans
- 2.0000 -0.5000 0.5714 -1.7500
- 0.2000 0.8333 -1.0000 -1.0000
- 6.0000 1.0000 1.0000 2.0000
- -Inf -0.5000 0 -1.0000
42 434.3. Constructing Matrices -- zeros, ones,
rand, randn, floor
gtgt zeros(5) ans 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
44- gtgt zeros(3,5)
- ans
- 0 0 0 0 0
- 0 0 0 0 0
- 0 0 0 0 0
zeros(m,n,o,p,) zero(a)
45 46 A(i,j) ij-1
47(No Transcript)
484.4. Vectorization
49(No Transcript)
50(No Transcript)
51(No Transcript)
52(No Transcript)
53(No Transcript)
54(No Transcript)
55(No Transcript)
56(No Transcript)
57MATHLAB ??
1
2
3
4
58- 1 Current Directory
- -??????????
- 2 Workspace
- -?????????,?????????
- 3 Command Window
- -??????????
- 4 Command History
- -?????Command Window??????
59????
- Enter?????????
- ??()
- 1.????????,???????? ???
- ?,??????????
- 2.????????,??????(row)???
-
- ??A1,2,34,5,6
- ? ? ? ?(?-??)????????
60- ??()
- 1. ????
- ?? ?????? ? ????
- ?? A1210
- A1 3 5 7 9 10
- 2. for-loop iteration
- ?? for i110
- ???
- end
61- ????
- sin( ?? ) cos( ?? ) tan( ?? )
- csc( ?? ) sec( ?? ) cot( ?? )
- pi3.1416
- ????
- ??? plot ( x , y )
- ??? bar ( x , width )
- ?????? figure( number )
- ??title ( ?? ) -??figure ??
62- ????
- 1. ?????????(element)??0
- ?? A zeros( m , n , )
- ??m-by-n ???
- 2. ?????????(element)??1
- ?? A ones( m , n , )
- ??m-by-n ???
- ????
- 1. ???doubleAdouble(A) -???
- 2. ???uint8 Auint8(A) -?????
63????
- ??????(Matrix operation)
- 1.????() AB
- 2.????(-)A-B
- 3.????() AB
- 4.????() Ac (c is a constant)
- ???????(Array operation)
- 1. Array multiply(.) A.B
- ??A????????B???,??????
- 2. Array power(.) A.c
- ??A???????????
64- ??????(Matrix transpose)
- Binv(A)
-
- ?????(Matrix inverse)
- BA
65Example
66?????
A 4,52,1 b 102 x A\b
67??????
- ???? imread( )
- IMimread(c\example\pic1.bmp')
- ???? imread( '????' )
- ???? imwrite( )
- imwrite(TM , 'c\example\OM1.bmp' , 'bmp'
) - imwrite(????, '??' , '??')
- ???? imshow( )
- imshow(TM)
- imshow(????)
68- ????? rgb2gray()
- TMrgb2gray(IM)
- ???? rgb2gray ( RGB?? )
- mat2gray()??????gray scale 0-1
- mat2gray(IM)
- mat2gray(????)
- ?????? size()
- height width size ( IM )
- ??????imfinfo()
- info imfinfo ( '????' )
69- RGB to HSI?RGB????????HSI
- TM rgb2hsv ( IM )
- h s v rgb2hsv ( IM )
- HSI to RGB?HSI????????RGB
- TM2 hsv2rgb(TM)
- r g b hsv2rgb(TM)
- RGB to YCbCr?RGB????????YCbCr
- TM hsv2rgb(IM)
- YCbCr to RGB?YCbCr???RGB
- TM2 hsv2rgb(TM)
70- ?????
- OM imfilter (IM, Mask, option1, option2 )
- OM???????
- IM???????
- Mask??????mask(window)
- option???????????????
- ??Mask
- 1. ?????????,???????weight
- 2. Mask fspecial ( '??' , ?? )
71 72- Order-statistic filter
- OM ordfilt2 ( TM, order, domain)
- domain??mask???
- order????n
- ?? 33 Median filter
- OM ordfilt2 (TM, 5, ones(3,3) )
-
73- Histogram of an image
- imhist (IM, bin)
- IM???????(gray-scale)
- bin???(???256)
- Histogram equalization
- OM histeq ( IM)
- OMhistogram equaliztion???
- IM???????
74- Edge detection
- OM edge ( TM, 'detector' , threshold , )
- detector????edge???
- threshold??edge??????
- edge????gray-scale???
-
detector
'prewitt'
'roberts'
'sobel'
'log'
'zerocross'
'canny'
75- Dilation
- OM imdilate ( TM, SE)
- SE?????structuring element (mask)
- Erosion
- OM imerode ( TM, SE)
- Closing
- OM imclose ( TM, SE)
- Opening
- OM imopen ( TM, SE)
76- Structuring element
- SE strel ( shape , ?? )
- shape??structuring element???