100 likes | 271 Views
Image Representation. Comp344 Tutorial Kai Zhang. Boundary representation. Chain codes Fourier Descriptor. Chain code. Represent a boundary by a connected sequence of straight-line segments of specified length and direction Freeman chain codes
E N D
Image Representation Comp344 Tutorial Kai Zhang
Boundary representation • Chain codes • Fourier Descriptor
Chain code • Represent a boundary by a connected sequence of straight-line segments of specified length and direction • Freeman chain codes • numbering schemes for directions are 4-neighbor or 8-neighbor connection
codes • a = double(imread('deer.bmp')); • [m,n] = size(a); • b = boundaries(a); • b = b{1}; • bim = bound2im(b,m,n); • figure,imshow(bim); • [s, su] = bsubsamp(b,4); • g2 = bound2im(s); • figure,imshow(g2); • cn = connectpoly(s(:,1),s(:,2)); • g2 = bound2im(cn); • figure,imshow(g2);
functions • B = boundaries(f,conn,dir): traces exterior boundaries in the binary image f. conn and dir is for connectivity (4/8) and direction(clock/counterclock wise). B contains the coordinates of the boundary points found. • In case there are multiple closed boundaries, B is a cell each element of which contains the p-by-2 coordinate matrix. • Example • B = boundaries(f); • d = cellfun('length',B); • [max_d, idx] = max(d); • V = B{idx(1)}; • plot(V(:,2),-V(:,1),'b.');
Fourier Descriptor • Given a set of 2-d coordinates (xk,yk)’s on a boundary • Staring from arbitrary point, traverse the boundary, and obtain a sequence (x1,y1), (x2,y2),…. • Deem this a s a sequence of complex numbers, S • Compute DFT of F = DFT(S) • Cut off frequency components in F with small magnitude • Perform inverse transform IDFT(F) to recover the original boundary
Codes • a = double(imread('deer.bmp')); • [m,n] = size(a); • b = boundaries(a); %detect boundary • b = b{1}; %suppose there is only one boundary • bim = bound2im(b);% turn boundary into image • figure,imshow(bim); • z = frdescp(b); • z1 = ifrdescp(z,20); • bim = bound2im(z1,m,n); • figure,imshow(bim);