Image Processing A/Prof.Dr.Supot Nitsuwat [email protected] DIP.
-
Upload
nigel-hicks -
Category
Documents
-
view
218 -
download
6
Transcript of Image Processing A/Prof.Dr.Supot Nitsuwat [email protected] DIP.
Ch 2 Image Processing
MTCT DI&SP
2.1 Pixel-based relation2.2 Pixel-based operations 2.3 Histogram-based operations 2.4 Frequency-based operations 2.5 Group-based operations
MTCT DI&SP
MTCT DI&SP
MTCT DI&SP
MTCT DI&SP
2.1 Pixel-based basic relation
2.1.1 Neighboring System of a Pixel
MTCT DI&SP
• 4-neighbors system (N4(p))
f(x,y) จุ�ดภาพ p
f(x,y-1)f(x-1,y)
f(x+1,y)f(x,y+1)
MTCT DI&SP
• Diagonal-neighbors system (ND(p))
f(x,y)f(x-1,y-1) f(x+1,y-1)
f(x+1,y+1)f(x-1,y+1)
MTCT DI&SP
• 8-neighbors system (N8(p))
f(x,y)f(x,y-1)
f(x-1,y)
f(x,y+1)
f(x+1,y)
f(x-1,y-1)f(x+1,y-1)
f(x+1,y+1)f(x-1,y+1)
MTCT DI&SP
2.1.2 Connectivity
MTCT DI&SP
4-connectivity
(D4)
8-connectivity
(D8)
Ex. Partial of image with intensity shown in piture. Find D4 , D8 , and Dm which is distances between A and B, if V = {0,1}.
3 1 2 1 B 2 2 0 3 1 2 1 2
A 1 0 1 2 MTCT DI&SP
no D4 from A to B
3 1 2 1 B 2 2 0 3 1 2 1 2
A 1 0 1 2
MTCT DI&SP
MTCT DI&SP
D8 from A to B 3 1 2 1 B
2 2 0 3 1 2 1 2
A 1 0 1 2
D8 from A to B 3 1 2 1 B
2 2 0 3 1 2 1 2
A 1 0 1 2
MTCT DI&SP
Dm จุาก A ไปถี�ง B 3 1 2 1 B
2 2 0 3 1 2 1 2
A 1 0 1 2
2.1.3 Adjacency
2.2 Pixel-based operations
MTCT DI&SP
2.2.1 Arithmetic Operations
Image Addition
Used to create double-exposures
C[x, y] A[x, y] B[x, y]
+ =
Image Averaging
Average multiple images (frames) of the same scene together
Useful for removing noise
+ + . . . =
Special Effect
Image Subtraction
Useful for finding changes between two images of (basically) the same scene
More useful to use absolute difference
C[x, y] A[x, y] B[x, y]
C[x, y] A[x, y] B[x,y]
Background Subtraction
“What’s changed?”
- =
(absolute difference)
MTCT DI&SP
a) b) c)
MTCT DI&SP
a) bad-illumination image
b) Image of white paper that has similar illumination with image a) prepared in LAB
c) Result of image division
a) b) c)
% =
• AND/NAND• OR/NOR• XOR/NXOR• NOT (Negative)
MTCT DI&SP
2.2.2 Logical Operations
MTCT DI&SP
MTCT DI&SP
a) b) c) d)
e) g)f)
and =
MTCT DI&SP
MTCT DI&SP
a) b)
c) d)
MTCT DI&SP
MTCT DI&SP
e)d)c)
b)a)
xor =
Homework 02
• A geometric transformation is a mapping from one coordinate system to another.
• The geometric transformation tells us how to map from (x,y) in the original checkerboard to (u,v) in the transformed images.
2.2.3 Geometric Operations
1. Affine Transform
2. Linear Conformal Transform
3. Projective Transform
4. Polynomial Transform
5. Piecewise Linear Transform
6. Sinusoidal Transform
7. Barrel Transform
8. Pin Cushion Transform
I = checkerboard(20);
figure(1);
imshow(I);
title('original');
1)Affine Transformation
• translation• scaling• rotation• shearing• mirroring• concatenation of simple transforms
MTCT DI&SP
MTCT DI&SP
1
1 333231
232221
131211'
'
y
x
aaa
aaa
aaa
y
x
Affine TransformationAffine Transformation
New CoordinateOld Coordinate
Transform matrix, T
1.1 translation
MTCT DI&SP
1 0 0
1 0
0 1
y
x
Tr d
d
T
1.2 shearing
1 0 0
0 1
0 0 1
ysh shTOr
1 0 0
0 1 0
0 1 x
sh
sh
T
1.3 scaling
MTCT DI&SP
1 0 0
0 0
0 0
y
x
sc s
s
T
1.4 rotation
1 0 0
0 cos sin
0 sin- cos
θ
Trot
1.5 mirroring
MTCT DI&SP
1 0 0
0 2 cos- 2sin
0 2 sin 2cos
θ
Tmr
MTCT DI&SP
MTCT DI&SP
MTCT DI&SP
MTCT DI&SP
Image rotation with a) 15 b) 45 and c) 90
a) b) c)
2) Linear Conformal Transformation2) Linear Conformal Transformation
Linear conformal transformations are a subset of affine transformations.
For a linear conformal transformation:
[u v] = [ x y 1] T.
MTCT DI&SP
% Try varying these 4 parameters.
scale = 1.2; % scale factorangle = 40*pi/180; % rotation angletx = 0; % x translationty = 0; % y translationsc = scale*cos(angle);ss = scale*sin(angle);T = [ sc -ss; ss sc; tx ty];
MTCT DI&SP
t_lc = maketform('affine',T);I_Lconf = imtransform(I,t_lc,'FillValues',.3);imshow(I_Lconf);title('linear conformal');
MTCT DI&SP
3) Projective Transform3) Projective Transform
In a projective transformation, quadrilaterals map to quadrilaterals. Straight lines remain straight. Affine transformations are a subset of projective transformations.
For a projective transformation:
[up vp wp] = [x y w] T, where u = up / wp
v = vp / wp.
T is a 3-by-3 matrix, where all nine elements can be different.
T = [A D G B E H C F I]
The above matrix equation is equivalent to these two expressions:
u = (Ax + By + C) / (Gx + Hy + 1)v = (Dx + Ey + F) / (Gx + Hy + 1)
T = [1 0 0.008; 1 1 0.01; 0 0 1];t_proj = maketform('projective',T); I_projective = imtransform(I,t_proj,'FillValues',.3);subplot(334);imshow(I_projective);title('projective')
4) Polynomial Transform4) Polynomial Transform
In a polynomial transformation, polynomial functions of x and y determine the mapping.
For a second-order polynomial transformation:
[u v] = [1 x y x*y x^2 y^2] T
Both u and v are second-order polynomials of x and y. Each second-order polynomial has six terms. To specify all coefficients, T has size 6-by-2.
xybase = reshape(randn(12,1),6,2);t_poly = cp2tform(xybase,xybase,'polynomial',2);% Try varying any of the twelve elements of T.T = [0 0; 1 0; 0 1; 0.001 0; 0.02 0; 0.01 0];t_poly.tdata = T;I_polynomial = imtransform(I,t_poly,'FillValues',.3);subplot(3,3,5);imshow(I_polynomial);title('polynomial')
MTCT DI&SP
5) Piecewise Linear Transform
In a piecewise linear transformation, linear transformations are applied separately to different parts of the image.
In this example the right side of the image is stretched, while the left side is left unchanged.
imid = round(size(I,2)/2); % Find index of middle element
I_left = I(:,1:imid);stretch = 1.5; % Try varying the stretch factorsize_right = [size(I,1) round(stretch*imid)];I_right = I(:,imid+1:end);I_right_stretched = imresize(I_right,size_right);I_piecewiselinear = [I_left I_right_stretched];imshow(I_piecewiselinear);title('piecewise linear');
MTCT DI&SP
MTCT DI&SP
7) Sinusoidal Transform
% locally varying with sinusoid[nrows,ncols] = size(I);[xi,yi] = meshgrid(1:ncols,1:nrows);a1 = 5; % Try varying the amplitude of the sinusoids.a2 = 3; u = xi + a1*sin(pi*xi/imid);v = yi - a2*sin(pi*yi/imid);tmap_B = cat(3,u,v);
MTCT DI&SP
resamp = makeresampler('linear','fill');I_sinusoid = tformarray(I,[],resamp,[2 1],[1 2],[],tmap_B,.3);imshow(I_sinusoid);title('sinusoid')
MTCT DI&SP
7) Barrel Transform
Barrel distortion perturbs an image radially outward from its center. Distortion is greater farther from the center, resulting in convex sides.
% radial barrel distortionxt = xi(:) - imid;yt = yi(:) - imid;[theta,r] = cart2pol(xt,yt);a = .001; % Try varying the amplitude of the cubic term.s = r + a*r.^3;[ut,vt] = pol2cart(theta,s);
MTCT DI&SP
u = reshape(ut,size(xi)) + imid;v = reshape(vt,size(yi)) + imid;tmap_B = cat(3,u,v);I_barrel = tformarray(I,[],resamp,[2 1],[1… 2],[],tmap_B,.3);subplot(338)imshow(I_barrel)title('barrel')
MTCT DI&SP
8) Pin Cushion Transform
Pin-cushion distortion is the inverse of barrel distortion because the cubic term has a negative amplitude. Distortion is still greater farther from the center but it results in concave sides.
% radial pin cushion distortionxt = xi(:) - imid;yt = yi(:) - imid;[theta,r] = cart2pol(xt,yt);a = -.0005; % Try varying the amplitude of the cubic term.
s = r + a*r.^3;
MTCT DI&SP
[ut,vt] = pol2cart(theta,s);u = reshape(ut,size(xi)) + imid;v = reshape(vt,size(yi)) + imid;tmap_B = cat(3,u,v);I_pin = tformarray(I,[],resamp,[2 1],[1… 2],[],tmap_B,.3);imshow(I_pin);title('pin cushion');
MTCT DI&SP