Lecture Recap: Image Processing - Histogram Segmentation, Region Properties, Pyramid, Study notes of Computer Science

A recap of a lecture by dr. Alper yilmaz at the university of central florida (ucf) in fall 2005. The lecture covered various image processing techniques, including histogram segmentation, region properties, and pyramid representation. Matlab code snippets for histogram segmentation and plots of derivative, histogram, and peakiness. It also includes a summary of the concepts covered in the lecture.

Typology: Study notes

Pre 2010

Uploaded on 02/25/2010

koofers-user-g6c
koofers-user-g6c 🇺🇸

10 documents

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Alper Yilmaz, Fall 2005 UCF
CAP 5415 Computer Vision
Fall 2005
Dr. Alper Yilmaz
Univ. of Central Florida
www.cs.ucf.edu/courses/cap5415/fall2005
Office: CSB 250
Alper Yilmaz, Fall 2005 UCF
Histogram Segmentation Code
%smooth
for i=1:5
hst=conv2(hst,gauss,'same');
end
%compute derivative
dr1=conv2(hst,dr,'same');
%find peaks and valleys
pw =dr1(1:254).*dr1(2:255);
peaks_valleys(find(pw<0))=1;
control=find(peaks_valleys==1);
for i=1:size(control,2)
if (dr1(control(i)-2)>0)
valleys(control(i))=1;
end
if (dr1(control(i)-2)<0)
peaks(control(i))=1;
end
end
peaklocs=find(peaks==1);
valleylocs=find(valleys==1);
current_valley=1;
for i=1:size(peaklocs,2)
Va = hst(valleylocs(current_valley));
Vb = hst(valleylocs(current_valley+1));
P = hst(peaklocs(i));
W = valleylocs(current_valley+1)-
valleylocs(current_valley);
N = 0 ;
for
j=valleylocs(current_valley):valleylocs
(current_valley+1)
N = N + hst(j);
end
val1 = 1-((Va+Vb)/(2*P));
val2 = 1-(N/(W*P));
if (val1>0 && val1>0)
peakiness(peaklocs(i)) = val1*val2;
end;
current_valley = current_valley +1;
end
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Lecture Recap: Image Processing - Histogram Segmentation, Region Properties, Pyramid and more Study notes Computer Science in PDF only on Docsity!

Alper Yilmaz, Fall 2005 UCF

CAP 5415 Computer Vision

Fall 2005

Dr. Alper Yilmaz

Univ. of Central Florida

www.cs.ucf.edu/courses/cap5415/fall Office: CSB 250

Alper Yilmaz, Fall 2005 UCF

Histogram Segmentation Code

%smooth for i=1: hst=conv2(hst,gauss,'same'); end %compute derivative dr1=conv2(hst,dr,'same'); %find peaks and valleys pw =dr1(1:254).*dr1(2:255); peaks_valleys(find(pw<0))=1; control=find(peaks_valleys==1); for i=1:size(control,2) if (dr1(control(i)-2)>0) valleys(control(i))=1; end if (dr1(control(i)-2)<0) peaks(control(i))=1; end end peaklocs=find(peaks==1); valleylocs=find(valleys==1);

current_valley=1; for i=1:size(peaklocs,2) Va = hst(valleylocs(current_valley)); Vb = hst(valleylocs(current_valley+1)); P = hst(peaklocs(i)); Wvalleylocs(current_valley); = valleylocs(current_valley+1)- N = 0 ; forj=valleylocs(current_valley):valleylocs (current_valley+1) N = N + hst(j); end val1 = 1-((Va+Vb)/(2P)); val2 = 1-(N/(WP)); if (val1>0 && val1>0) peakiness(peaklocs(i)) = val1*val2; end; current_valley = current_valley +1; end

Alper Yilmaz, Fall 2005 UCF

Plots

Derivative

Histogram

Peaks

Valleys

Peakiness

-500 0 50 100 150 200 250 300

0

500

(^00 50 100 150 200 250 )

1000

2000

(^00 50 100 150 200 250 )

1

(^00 50 100 150 200 250 )

1

(^00 50 100 150 200 250 )

Alper Yilmaz, Fall 2005 UCF

Recap

Region Properties

z Area

z Centroid

z Moments

z Perimeter

z Compactness

z Orientation

∑∑ = =

=

m x

n y

A Bxy 0 0

(, )

A

yBx y y A

xBxy x

m x

n y

m x

n

= ∑∑=^0 y =^0 =^ ∑∑=^0 =^0

(,) (,)

μ pq = ∫ ∫( x − x ) p ( y − y ) qB ( x , y ) d ( x − x ) d ( y − y )

A

C^ Perimeter 4 π

2

Alper Yilmaz, Fall 2005 UCF

Recap

Region Orientation

(x,y)

y 0

r

s θ

x 1

y 1

x 0

θ

θ

sin

cos

0 1

0 1

y y s

x x s

( ) ( ρ θ) θ

ρ θ θ

cos sin

sin cos

0

0

y s

x s

Alper Yilmaz, Fall 2005 UCF

Recap

Region Orientation

(x,y)

y 0

r

x x 0

y

2 0

2 0 r^2 =( xx ) +( yy )

( ) ( ρ θ) θ

ρ θ θ

cos sin

sin cos

0

0

y s

x s

( ) ( ) 2 2 2 r = x +ρ sinθ− s cosθ + y −ρcosθ− s sin θ

r^2 = x^2 + y^2 +ρ 2 + s^2 − 2 s ( x cosθ+ y sinθ) + 2 ρ( x sinθ− y cosθ)

Substitute x 0 and y (^0)

Alper Yilmaz, Fall 2005 UCF

Recap

Region Orientation

r^2 2 s 2 ( x cosθ y sinθ) s

= − + ∂

s = x cos θ + y sinθ

Substitute s back to r

r^2 = x^2 + y^2 +ρ 2 + s^2 − 2 s ( x cosθ+ y sinθ) + 2 ρ( x sinθ− y cosθ)

Alper Yilmaz, Fall 2005 UCF

Recap

Region Orientation

( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) (^2) ( )^2

2 2 2

2 2 2 2 2 2

2 2 2 2 2 2

2 2 2 2 2 2 2 2

2 2 2 2 2

sin cos

sin cos 2 sin cos

sin cos 2 sin cos 2 sin cos

1 cos 1 sin 2 sin cos 2 sin cos

cos 2 sin cos sin 2 sin cos

cos sin 2 sin cos

r x y

r x y x y

r x y xy x y

r x y xy x y

r x y x xy y x y

r x y x y x y

r^2 = x^2 + y^2 +ρ 2 + s^2 − 2 s ( x cosθ+ y sinθ) + 2 ρ( x sinθ− y cosθ)

Alper Yilmaz, Fall 2005 UCF

Homework from last lecture

z Show that following holds

where

E 1 (^) = a sin 2 θ − b sinθcosθ+ c cos^2 θ

θ sin 2 θ

( )cos 2

E 2 = a + c − a − c − b

E 1 = E 2

Alper Yilmaz, Fall 2005 UCF

Pyramid Representation

Gaussian

Laplacian

Alper Yilmaz, Fall 2005 UCF

Gaussian Pyramid

z Very useful for representing images

z Image Pyramid is built by using multiple

copies of image at different scales.

z Each level in the pyramid is ¼ of the size of

previous level

z The highest level is of the highest resolution

z The lowest level is of the lowest resolution

Alper Yilmaz, Fall 2005 UCF

Alper Yilmaz, Fall 2005 UCF

  • Resample the checkerboard by

taking one sample at each circle. In

the case of the top left board, new

representation is reasonable.

  • Top right also yields a reasonable

representation. Bottom left is all black

(dubious) and bottom right has checks

that are too big.

Alper Yilmaz, Fall 2005 UCF

Pyramid With Every Other Pixel

Constructing a pyramid by taking every

second pixel leads to layers that badly

misrepresent the top layer

Alper Yilmaz, Fall 2005 UCF

Sampling

z 1D

z 2D

gray level x

gray level x

gray level x

y

gray level x

y

Alper Yilmaz, Fall 2005 UCF

Smoothing

z High frequencies (edges) lead to trouble with

sampling.

z Solution: suppress edges before sampling

z Common solution: use a Gaussian

  • Convolve image with Gaussian filter

Alper Yilmaz, Fall 2005 UCF

Applications of Scaled Images

z Search for correspondence

  • look at coarse scales, then refine with finer scales

z Edge tracking

  • “Good” edge at a fine scale has parents at a coarser scale

z Control of detail and computational cost in matching

  • Finding stripes
  • Very important in texture representation

Alper Yilmaz, Fall 2005 UCF

Gaussian Pyramid

z Let w be Gaussian filter

() ˆ( ) ( 2 )

2

2

g i wmg 1 i m m

l =^ ∑ l + =−

ˆ( 0 ) ( 4 ) ˆ( 1 ) ( 4 1 ) ˆ( 2 ) ( 4 2 )

( 2 ) ˆ( 2 ) ( 4 2 ) ˆ( 1 ) ˆ( 4 1 )

1 1 1

1 1

= − − + − − +

− − −

− −

l l l

l l l

w g w g w g

g w g w g w

ˆ( 0 ) ( 4 ) ˆ( 1 ) ( 5 ) ˆ( 2 ) ( 6 )

( 2 ) ˆ( 2 ) ( 2 ) ˆ( 1 ) ˆ( 3 )

1 1 1

1 1

− − −

− −

= − + − +

l l l

l l l

w g w g w g

g w g w g w

g 0 IMAGE

gl = REDUCE [ gl − 1 ]

Alper Yilmaz, Fall 2005 UCF

Convolution Kernel w

z Symmetric

z Sum must be 1

[ w ( (^) − 2 ) , (^) w (− 1 ), (^) w ( ) 0 , (^) w ( ) 1 , (^) w ( ) 2 ]

w ( ) i = w (− i ) ⇒[ c , b , a , b , c ]

a + 2 b + 2 c = 1

Alper Yilmaz, Fall 2005 UCF

Reduce 1D

Convolution Kernel w

z All nodes at a given level must contribute the same total weight to the nodes at the next higher level

a + 2 c = 2 b

b (^) b

c c

a

Alper Yilmaz, Fall 2005 UCF

Approximate Gaussian (5x1)

c b a b c

Gaussian

Alper Yilmaz, Fall 2005 UCF

Two Dimensions?

z Gaussian is separable

I ( x , y ) = I ( x , y ) * G ( x , y )

)

I ( x , y ) = I ( x , y ) * G ( ) x * G ( y )

)

G ( ) x G ( y ) transpose

T

=

Alper Yilmaz, Fall 2005 UCF

Gaussian Pyramid Algorithm

z Apply 1D mask to alternate pixels along each row of image.

z Apply 1D mask to alternate pixels along each column of resulting image from previous step.

Alper Yilmaz, Fall 2005 UCF

Alper Yilmaz, Fall 2005 UCF

Expand 1D

i p

g i w p g

m

ln ln

) 2

3 2 ) ˆ( 2 ) ( 2

3 1 ) ˆ( 1 ) ( 2

3 ˆ( 0 ) (

) 2

3 1 ) ˆ( 1 ) ( 2

3 2 ( 3 ) ˆ( 2 ) (

, 1 , 1 , 1

, , 1 , 1

− = −

− − −

− −

ln ln l n

ln ln ln

w g w g w g

g w g w g

gl , n ( 3 )= w ˆ(− 1 ) gl , n − 1 ( 1 )+ w ˆ( 1 ) gl , n − 1 ( 2 )

Alper Yilmaz, Fall 2005 UCF

The Laplacian Pyramid

z Similar to edge detected images

z Most pixels are zero

z Can be used in image compression

Alper Yilmaz, Fall 2005 UCF

Constructing Laplacian Pyramid

z Compute Gaussian pyramid

z Compute Laplacian pyramid as follows:

g (^) k , gk − 1 , gk − 2 ,K g 2 , g 1

( )

( )

( )

1 1

2 2 3

1 1 2

1

L g

L g EXPANDg

L g EXPANDg

L g EXPANDg

k k k

k k k

k k k

=

= −

= −

= −

− − −

− − −

M

Alper Yilmaz, Fall 2005 UCF

Laplacian Pyramid