image processing a/prof.dr.supot nitsuwat [email protected] dip

82
Image Processing A/Prof.Dr.Supot Nitsuwat [email protected] http:// it.kmitnb.ac.th DIP

Upload: nigel-hicks

Post on 28-Dec-2015

221 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

Image Processing

A/Prof.Dr.Supot [email protected]

http://it.kmitnb.ac.th

DIP

Page 2: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  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

Page 3: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 4: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 5: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 6: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

2.1 Pixel-based basic relation

2.1.1 Neighboring System of a Pixel

Page 7: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 8: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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)

Page 9: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 10: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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)

Page 11: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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)

Page 12: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

2.1.2 Connectivity

Page 13: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 14: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 15: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

4-connectivity

(D4)

8-connectivity

(D8)

Page 16: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 17: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 18: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 19: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 20: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Dm จุาก A ไปถี�ง B 3 1 2 1 B

2 2 0 3 1 2 1 2

A 1 0 1 2

Page 21: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

2.1.3 Adjacency

Page 22: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 23: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 24: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

2.2 Pixel-based operations

MTCT DI&SP

2.2.1 Arithmetic Operations

Page 25: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 26: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

Image Addition

Used to create double-exposures

C[x, y] A[x, y] B[x, y]

+ =

Page 27: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

Image Averaging

Average multiple images (frames) of the same scene together

Useful for removing noise

+ + . . . =

Page 28: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

Special Effect

Page 29: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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]

Page 30: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 31: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

Background Subtraction

“What’s changed?”

- =

(absolute difference)

Page 32: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

a) b) c)

Page 33: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 34: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 35: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 36: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 37: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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)

% =

Page 38: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 39: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 40: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 41: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 42: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

• AND/NAND• OR/NOR• XOR/NXOR• NOT (Negative)

MTCT DI&SP

2.2.2 Logical Operations

Page 43: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 44: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 45: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

a) b) c) d)

e) g)f)

and =

Page 46: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 47: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP
Page 48: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

a) b)

c) d)

Page 49: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 50: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

e)d)c)

b)a)

xor =

Page 51: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

Homework 02

Page 52: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

• 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

Page 53: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 54: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

I = checkerboard(20);

figure(1);

imshow(I);

title('original');

Page 55: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

1)Affine Transformation

• translation• scaling• rotation• shearing• mirroring• concatenation of simple transforms

MTCT DI&SP

Page 56: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

1

1 333231

232221

131211'

'

y

x

aaa

aaa

aaa

y

x

Affine TransformationAffine Transformation

New CoordinateOld Coordinate

Transform matrix, T

Page 57: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 58: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 59: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

1.5 mirroring

MTCT DI&SP

1 0 0

0 2 cos- 2sin

0 2 sin 2cos

θ

Tmr

Page 60: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 61: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 62: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 63: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Image rotation with a) 15 b) 45 and c) 90

a) b) c)

Page 64: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 65: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

% 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

Page 66: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

t_lc = maketform('affine',T);I_Lconf = imtransform(I,t_lc,'FillValues',.3);imshow(I_Lconf);title('linear conformal');

MTCT DI&SP

Page 67: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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.

Page 68: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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)

Page 69: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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')

Page 70: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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.

Page 71: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 72: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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.

Page 73: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 74: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

MTCT DI&SP

Page 75: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 76: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

resamp = makeresampler('linear','fill');I_sinusoid = tformarray(I,[],resamp,[2 1],[1 2],[],tmap_B,.3);imshow(I_sinusoid);title('sinusoid')

MTCT DI&SP

Page 77: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

7) Barrel Transform

Barrel distortion perturbs an image radially outward from its center. Distortion is greater farther from the center, resulting in convex sides.

Page 78: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

% 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

Page 79: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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

Page 80: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

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.

Page 81: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

% 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

Page 82: Image Processing A/Prof.Dr.Supot Nitsuwat sns@kmitnb.ac.th  DIP

[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