source: distools/blobbox.m @ 100

Last change on this file since 100 was 10, checked in by bduin, 14 years ago
File size: 1.5 KB
RevLine 
[10]1%BLOBBOX Find box around a binary blob and resample
2%
3%   B = BLOBBOX(A,ny,nx)
4%
5% INPUT
6%   A     MY x MX x N matrix of N binary images of the size MY x MX
7%   NX,NY Resampling sizes (optional, default: 16)
8%
9% OUTPUT
10%   B     NY x NX x N matrix of N binary images of the size NY x NX
11%
12% DEFAULT
13% NX = NY = 16.
14%
15% DESCRIPTION
16% For an MY x MX x N set of N binary images A the bounding boxes around
17% the blobs are computed and resampled with NX x NY pixels.
18%
19
20% Copyright: R.P.W. Duin, r.duin@ieee.org
21% and Elzbieta Pekalska, ela.pekalska@googlemail.com
22% Faculty EWI, Delft University of Technology and
23% School of Computer Science, University of Manchester
24
25
26function b = blobbox(a,ny,nx);
27if nargin < 2,
28  ny = 16;
29end
30if nargin < 3,
31  nx = ny;
32end
33
34[mx,my,n] = size(a);
35b = zeros(nx,ny,n);
36
37for i=1:n
38  c = a(:,:,i);
39  J = find(any(c));
40  J = [min(J):max(J)];
41  K = find(any(c'));
42  K = [min(K):max(K)];
43  c = double(c(K,J));
44  if length(c(:)) > 0,
45    c = bord(c,0);
46    b(:,:,i) = imresize(c,[ny,nx]);
47  end
48end
49
50
51
52function C = bord(A,n,m);
53% C = bord(A,n,m)
54% Puts a border of the width m (default m=1) around the image A
55% and gives it value n. If n = NaN: mirror image values.
56
57if nargin == 2;
58  m=1;
59end
60[x,y] = size(A);
61if m > min(x,y)
62  mm = min(x,y);
63  C = bord(A,n,mm);
64  C = bord(C,n,m-mm);
65  return
66end
67
68if isnan(n)
69  C = [A(:,m:-1:1),A,A(:,y:-1:y-m+1)];
70  C = [C(m:-1:1,:);C;C(x:-1:x-m+1,:)];
71else
72  bx = ones(x,m)*n;
73  by = ones(m,y+2*m)*n;
74  C = [by;[bx,A,bx];by];
75end
Note: See TracBrowser for help on using the repository browser.