source: prextra/gendati.m @ 110

Last change on this file since 110 was 5, checked in by bduin, 14 years ago
File size: 1.6 KB
Line 
1%GENDATI Create dataset from randomly selected windows in a given image
2%
3%               A = GENDATI(IMAGE,WSIZE,N,LABEL)
4%
5% INPUT
6%   IMAGE  - Image of any dimensionality
7%   WSIZE  - Vector with size of the window
8%   N      - Number windows to be generated
9%   LABEL  - Optional string or number with label for all objects
10%
11% OUTPUT
12%   A      - Dataset of N objects and prod(WSIZE) features
13%
14% DESCRIPTION
15%       Windows of the specified size are arbitrarily positioned in the
16% image, converted to a row vector and stored in the dataset A.
17%
18% If specified, all objects have label LABEL. Otherwise they are
19% unlabeled.
20%
21% SEE ALSO
22% DATASETS
23
24% Copyright: R.P.W. Duin, r.p.w.duin@prtools.org
25% Faculty EWI, Delft University of Technology
26% P.O. Box 5031, 2600 GA Delft, The Netherlands
27
28function a = gendati(im,ws,m,label)
29
30if nargin < 4, label = []; end
31if nargin < 3, m = 100; end
32
33n = length(ws);
34imsize = size(im);
35if length(imsize) ~= n
36        error('Window size should have same number of components as image size')
37end
38
39if any(ws > imsize)
40        error('Window size should not be larger than image size')
41end
42
43we = prod(ws);
44n = length(ws);
45window_offset = [0:ws(1)-1]';
46for j=2:n
47        wo = window_offset;
48        for i=1:ws(j)-1
49                wo = wo + prod(imsize(1:j-1));
50                window_offset = cat(j,window_offset,wo);
51        end
52end
53window_offset = window_offset(:)';
54
55N = cell(1,n);
56for j=1:n
57        R = imsize(j)-ws(j)+1;
58        N(j) = {ceil(rand(m,1)*R)};
59end
60N = sub2ind(imsize,N{:});
61
62a = zeros(m,prod(ws));
63for i=1:m
64        a(i,:) = im(N(i)+window_offset);
65end
66
67a = dataset(a);
68a = setfeatsize(a,ws);
69if ~isempty(label)
70        a = setlabels(a,label);
71end
Note: See TracBrowser for help on using the repository browser.