1 ## Copyright (C) 2004 Josep Mones i Teixidor
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2 of the License, or
6 ## (at your option) any later version.
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ## GNU General Public License for more details.
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {[@var{vals}] = } qtgetblk (@var{I},@var{S},@var{dim})
18 ## @deftypefnx {Function File} {[@var{vals},@var{idx}] = } qtgetblk (@var{I},@var{S},@var{dim})
19 ## @deftypefnx {Function File} {[@var{vals},@var{r},@var{c}] = } qtgetblk (@var{I},@var{S},@var{dim})
20 ## Obtain block values from a quadtree decomposition.
22 ## [vals]=qtgetblk(I,S,dim) returns a dim-by-dim-by-k array in
23 ## @var{vals} which contains the dim-by-dim blocks in the quadtree
24 ## decomposition (@var{S}, which is returned by qtdecomp) of @var{I}. If
25 ## there are no blocks, an empty matrix is returned.
27 ## [vals,idx]=qtgetblk(I,S,dim) returns @var{vals} as described above.
28 ## In addition, it returns @var{idx}, a vector which contains the linear
29 ## indices of the upper left corner of each block returned (the same
30 ## result as find(full(S)==dim)).
32 ## [vals,r,c]=qtgetblk(I,S,dim) returns @var{vals} as described, and two
33 ## vectors, @var{r} and @var{c}, which contain the row and column
34 ## coordinates of the blocks returned.
36 ## @seealso{qtdecomp, qtsetblk}
39 ## Author: Josep Mones i Teixidor <jmones@puntbarra.com>
41 function [varargout] = qtgetblk(I, S, dim)
43 usage("[vals,r,c]=qtgetblk(I,S,dim), [vals,idx]=qtgetblk(I,S,dim)");
46 usage("[vals,r,c]=qtgetblk(I,S,dim), [vals,idx]=qtgetblk(I,S,dim)");
52 ## filter the ones which match dim
63 ## copy to a dim-by-dim-by-k array
64 vals=zeros(dim,dim,length(idx));
66 vals(:,:,i)=I(r(i):r(i)+dim-1,c(i):c(i)+dim-1);
75 varargout{2}=(c-1)*rows(I)+r;
82 %! [vals,r,c]=qtgetblk(eye(4),qtdecomp(eye(4)),2)
83 %! % Returns 2 blocks, at [1,3] and [3,1] (2*2 zeros blocks)
86 %! A=[ 1, 4, 2, 5,54,55,61,62;
87 %! 3, 6, 3, 1,58,53,67,65;
88 %! 3, 6, 3, 1,58,53,67,65;
89 %! 3, 6, 3, 1,58,53,67,65;
90 %! 23,42,42,42,99,99,99,99;
91 %! 27,42,42,42,99,99,99,99;
92 %! 23,22,26,25,99,99,99,99;
93 %! 22,22,24,22,99,99,99,99];
97 %! [va]=qtgetblk(A,S,8);
98 %! [vb,r,c]=qtgetblk(A,S,8);
99 %! [vc,i]=qtgetblk(A,S,8);
110 %! [va]=qtgetblk(A,S,4);
111 %! [vb,r,c]=qtgetblk(A,S,4);
112 %! [vc,i]=qtgetblk(A,S,4);
115 %! assert(i, find(full(S)==4));
119 %! R(:,:,1)=A(1:4,1:4);
120 %! R(:,:,2)=A(5:8,5:8);
124 %! [va]=qtgetblk(A,S,2);
125 %! [vb,r,c]=qtgetblk(A,S,2);
126 %! [vc,i]=qtgetblk(A,S,2);
129 %! assert(i, find(full(S)==2));
130 %! assert(r,[7;5;7;1;3;1;3]);
131 %! assert(c,[1;3;3;5;5;7;7]);
133 %! R(:,:,1)=A(7:8,1:2);
134 %! R(:,:,2)=A(5:6,3:4);
135 %! R(:,:,3)=A(7:8,3:4);
136 %! R(:,:,4)=A(1:2,5:6);
137 %! R(:,:,5)=A(3:4,5:6);
138 %! R(:,:,6)=A(1:2,7:8);
139 %! R(:,:,7)=A(3:4,7:8);
144 % Revision 1.4 2007/03/23 16:14:37 adb014
145 % Update the FSF address
147 % Revision 1.3 2007/01/04 23:50:47 hauberg
148 % Put seealso before end deftypefn
150 % Revision 1.2 2007/01/04 23:41:47 hauberg
151 % Minor changes in help text
153 % Revision 1.1 2006/08/20 12:59:35 hauberg
154 % Changed the structure to match the package system
156 % Revision 1.3 2006/01/02 20:53:42 pkienzle
157 % Reduce number of shared variables in tests
159 % Revision 1.2 2004/08/11 19:52:41 jmones