Title: Chapter 2: Digital Image Fundamentals
1Images and MATLAB
2Matlab Advantages
- Every variable in Matlab is a multidimensional
matrix. - Highly modular.
- No memory allocation is necessary.
- Matlab enables its own garbage collection.
- Simple interface for complex mathematical
concepts.
3Image Types
- Intensity imagesscaled to represent intensities
(uint8 0,255, double 0,1) - Binary imageslogical array of 0s and 1s
- Indexed imagesLook up table x, map
- RGB imagestruecolor, array of (mn3)
-
Checking the image type isind, isbw, isgray,
isrgbConverting image types rgb2ind, rgb2gray,
gray2ind, ind2gray,.
4Data Classes
Converting between types B data_class_name(A)
for example B double(A)
5Conversions
- When converting between data classes and types it
is important to keep the value range for each
data class - gtgt img double(img)/255
- gtgt img im2double(img)
6MATLAB supported image formats
- JPEG Joint Photographics Experts Group
- TIFF Tagged Image File Format
- GIF Graphics Interchange Format
- BMP Microsoft Bitmap Format
- PNG Portable Network Graphics
-
7Displaying an image(cont.)
8Matlab Basics
- Digital image representation 2D function
f(x,y) -gt finite discrete quantities - Coordinate Conventions
- img(r,c)r rows (height)c cols (width)
- The first pixelimg(1,1)
9Matlab ????
- C\MATLAB7\toolbox\images\imdemos
- ??Matlab Help?????????
- ???????????????,?????
- ???????????
10Different Image Types
- Indexed images
- Intensity (grayscale) images
- Binary images
- RGB (true-color) images
11Reading an image
- imread()
- ??????????array????
- ??I,map imread(filename)
- I imread(filename)
- ex I imread('pout.tif')
- I????????
- ?????,??ans
12Displaying an image
- imshow()
- ????????????
- ?? imshow(I)
- imshow(I,map)
- Figure, imshow()
- ?????????????
- ?? figure,imshow(I)
-
13Displaying an image(cont.)
- imshow(I, low, high)
- imshow(I, )
- ??displays I as a grayscale intensity image,
specifying the data range for I. The minimum
value in I is displayed as black, and the maximum
value is displayed as white. - pixval
- ??cursor on image to show pixel values
- ?? imshow(I),pixval
14Displaying an image(cont.)
- colorbar
- ??To display an image with a colorbar that
indicates the range of intensity values. - ?? imshow(I), colorbar
- ex
- I imread('pout.tif')
- imshow(I) , colorbar
15Writing an image
- imwrite()
- ??????????
- ?? imwrite(I,filename,format)
- ex
- imwrite(I,'pout.jpg','JPEG')
-
16Image information
- Image size size()
- ex
- I imread('saturn.png')
- size(I)
- M,N size(I)
- M??I??
- N??I??
17Image information
- whos
- ??display information about an image .
- ex whos I
- Imfinfo( filename )
- ?? display information about image file .
- ex info imfinfo('saturn.png')
18Digital Image processing
- ?????
- g im2bw(I, T)
- ??Convert intensity image I to binary image g
using threshold T, where T must be in range 0,
1. - ex
- I imread('pout.tif')
- g im2bw(I, 0.4)
- imshow(g) colorbar
19Digital Image processing(cont.)
- ?????
- Rgb2gray()
- ???RBG???????gray-level???ex
- I2 imread ('onion.png')
- figure,imshow(I2) colorbar
- g2 rgb2gray(I2)
- figure,imshow(g2) colorbar
20Digital Image processing(cont.)
- ??
- imcomplement( )
- ??The negative of an image.
- ex
- I2 imread ('onion.png')
- figure,imshow(I2) colorbar
- J2 imcomplement(g2)
- figure, imshow(J2) colorbar
21Grayscale images ????
- Matlab example
- wimread('pout.tif')
- figure, imshow(w), pixval on
- figure create a window to place graphic object
- imshow display matrix
- Data type of w?
- 291x240 uint8 (unsigned integer 8 bits
22Binary image ????
- Matlab example
- w2imread('circles.png')
- figure, imshow(w2), pixval on
- Data type of w?
- 256x256 logical
- Pixel value is 0 or 1
23RGB (true color) images ????
- Matlab example
- w3imread('peppers.png')
- figure, imshow(w3), pixval on
- size(w3)
- w3(100,200,2)
- w3(100,200,13)
- w3(100,200,)
24RGB color model
25Pixel depth
- Pixel depth the number of bits used to represent
each pixel in RGB space - Full-color image 24-bit RGB color image
- (R, G, B) (8 bits, 8 bits, 8 bits)
26Indexed color image ??????
- Matlab example
- wIimread('trees.tif')
- figure, imshow(w), pixval on
- Whats wrong?
27Indices
Color Map
28Indexed color image
- Matlab example
- wI,wmapimread('trees.tif')
- figure, imshow(wI, wmap)
- How do we know its an indexed image?
29Indexed color image ??????
- Matlab example
- wimread(emu.tif)
- figure, imshow(w), pixval on
- Whats wrong?
30Indexed color image
31Indexed color image
- Matlab example
- w,wmapimread(emu.tif)
- imshow(w, wmap)
- How do we know its an indexed image?
32Get information about image
Filename 'emu.tif'
FileModDate '12-Jul-2004 114000'
FileSize 119804
Format 'tif'
FormatVersion Width
331 Height 384
BitDepth 8
ColorType 'indexed' ByteOrder
'little-endian' NewSubfileType 0
BitsPerSample 8
Colormap 256x3 double
33Get information about image
Filename 'emu.tif'
FileModDate '12-Jul-2004 114000'
FileSize 119804
Format 'tif'
FormatVersion Width
331 Height 384
BitDepth 8
ColorType 'indexed' ByteOrder
'little-endian' NewSubfileType 0
BitsPerSample 8
Colormap 256x3 double
34Data types and conversion
- uint8 image must be converted to double before
any arithmetic operation - wimread('pout.tif')
- ww1 fail
- wdouble(w) data type is also conversion
func. - ww1 ok
35Write image matrix to file
- Matlab code
- wimread('pout.tif')
- imwrite(w, 'pout.jpg','jpg')
- General form
- imwrite(X, map, filename, format)
36Zooming and Shrinking Digital Images
- Zooming
- Create a new pixel location.
- Assign a gray-level to those new locations
- Nearest neighbor interpolation
- Pixel replication a checkboard effect
- Bilinear interpolation using four nearest
neighbors - v(x, y)axbycxyd
- where a, b, c, and d are determined from the
gray-level of the four neighbors. - Shrinking
- Direct shrinking causes aliasing
- Expansion then Shrinking blurring the image
before shrinking it and reduce aliasing.
37Sampling Methods of Inverse Mapping
- If transformed pixel X locates among
- P1, P2, P3 and P4
- Nearest neighbor method
- I(X) I(P3 )
- where I(p) is the intensity value of pixel p
- Bi-linear interpolation
- I(X) (1-a)(1-b)I( P1 ) a(1-b)I(P2 )
- (1-a)bI(P3 ) abI(P4 )
- where a, b are the fractional parts of X
- Bi-cubic interpolation
- based on cubic splines
P2
P1
P3
P4
38Nearest neighbor interpolation
- The closest neighbor is chosen , by rounding the
new indexes to original images coordinates .
39(No Transcript)
40(No Transcript)
41(No Transcript)
42(No Transcript)
43(No Transcript)
44(No Transcript)
45(No Transcript)
46(No Transcript)
47Digital Image processing(cont.)
- ??????
- imresize(I,scale,method)
- ??To change the size of an image.
- interpolation Method
- -'nearest Nearest-neighbor interpolation
- -'bilinear Bilinear (the default)
- -'bicubic Bicubic interpolation
48Digital Image processing(cont.)
- ??????
- imresize(I,scale,method)
- ??To change the size of an image.
- interpolation Method
- -'nearest Nearest-neighbor interpolation
- -'bilinear Bilinear (the default)
- -'bicubic Bicubic interpolation
49Digital Image processing(cont.)
- ex
- I3 imread('circuit.tif')
- J3 imresize(I3,1.25)
- figure, imshow(I3)
- figure, imshow(J3)
- ex
- I3 imread('circuit.tif')
- J4 imresize(I3,100 150, 'bilinear')
- figure, imshow(I3)
- figure, imshow(J4)
50Digital Image processing(cont.)
- ????
- imrotate(I, angle)
- ??To rotate an image.
- ex
- I imread('pout.tif')
- J5 imrotate(I,35)
- figure, imshow(J5)
51Contents
- Histogram
- Histogram transformation
- Histogram equalization
- Contrast streching
- Applications
52(No Transcript)
53(No Transcript)
54(No Transcript)
55Histogram
The (intensity or brightness) histogram shows how
many times a particular grey level (intensity)
appears in an image. For example, 0 - black,
255 white
0 1 1 2 4
2 1 0 0 2
5 2 0 0 4
1 1 2 4 1
histogram
image
56Histogram equalization (HE)
                              Â
transforms the intensity values so that the
histogram of the output image approximately
matches the flat (uniform) histogram
57(No Transcript)
58(No Transcript)
59(No Transcript)
60(No Transcript)
61(No Transcript)
62(No Transcript)
63Histogram equalization II.
                              Â
As for the discrete case the following formula
applies k 0,1,2,...,L-1 L number of grey
levels in image (e.g., 255) nj number of times
j-th grey level appears in image n total number
of pixels in the image
(L-1)
?
64(No Transcript)
65(No Transcript)
66Histogram equalization III
                              Â
67(No Transcript)
68histogram
- pimread('pout.tif')
- imshow(p), figure, imhist(p), axis tight
69Histogram equalization
- phhisteq(p)
- imshow(ph), figure, imhist(ph), axis tight
70Histogram equalization (cont.)
- ph, thisteq(p)
- plot(t), title('transform function')
Exercise1. Apply histogram equalization to tire
image