]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/qtsetblk.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / qtsetblk.m
1 ## Copyright (C) 2004 Josep Mones i Teixidor
2 ##
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.
7 ##
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.
12 ##
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/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{J} = } qtsetblk (@var{I},@var{S},@var{dim},@var{vals})
18 ## Set block values in a quadtree decomposition.
19 ##
20 ## J=qtsetblk(I,S,dim,vals) sets all the @var{dim}-by-@var{dim} blocks
21 ## in the quadtree decomposition (@var{S} returned by qtdecomp) of
22 ## @var{I} to @var{dim}-by-@var{dim} blocks in @var{vals}, which is
23 ## itself a @var{dim}-by-@var{dim}-by-k array. k is the number of
24 ## @var{dim}-by-@var{dim} blocks in the quadtree decomposition.
25 ## @seealso{qtdecomp, qtgetblk}
26 ## @end deftypefn
27
28 ## Author:  Josep Mones i Teixidor <jmones@puntbarra.com>
29
30 function J = qtsetblk(I, S, dim, vals)
31   if (nargin!=4)
32     usage("J=qtsetblk(I,S,dim,vals)");
33   endif
34
35   ## get blocks
36   [ii,ji,v]=find(S);
37
38   ## filter the ones which match dim
39   idx=find(v==dim);
40   if(size(vals,3)<length(idx)) ## we won't complain if k>num blocks
41     error("qtsetblk: k (vals 3rd dimension) is not equal to number of blocks.");
42   endif
43   ii=ii(idx);
44   ji=ji(idx);
45   
46   ## calc end vertex
47   ie=ii+dim-1;
48   je=ji+dim-1;
49
50
51   J=I;
52   for b=1:length(idx)
53     J(ii(b):ie(b),ji(b):je(b))=vals(:,:,b);
54   endfor
55 endfunction
56
57
58 %!demo
59 %! J=qtsetblk(eye(4),qtdecomp(eye(4)),2,ones(2,2,2))
60 %! % Sets upper-right and lower-left blocks of 2*2 zeros to ones
61
62 %!shared A, S
63 %! A=[ 1, 4, 2, 5,54,55,61,62;
64 %!     3, 6, 3, 1,58,53,67,65;
65 %!     3, 6, 3, 1,58,53,67,65;
66 %!     3, 6, 3, 1,58,53,67,65;
67 %!    23,42,42,42,99,99,99,99;    
68 %!    27,42,42,42,99,99,99,99;    
69 %!    23,22,26,25,99,99,99,99;    
70 %!    22,22,24,22,99,99,99,99];
71 %! S=qtdecomp(A,10);
72
73 %!test
74 %! R=A;
75 %! vals=zeros(4,4,2);
76 %! vals(:,:,1)=reshape([1:16],4,4);
77 %! vals(:,:,2)=reshape([21:36],4,4);
78 %! R(1:4,1:4)=reshape([1:16],4,4);
79 %! R(5:8,5:8)=reshape([21:36],4,4);
80 %! assert(qtsetblk(A,S,4,vals),R);
81
82 %!test
83 %! R=A;
84 %! R(1:4,5:8)=1;
85 %! R(7:8,1:4)=1;
86 %! R(5:6,3:4)=1;
87 %! assert(qtsetblk(A,S,2,ones(2,2,7)),R);
88
89 %!test
90 %! R=A;
91 %! R(5:6,1:2)=10;
92 %! assert(qtsetblk(A,S,1,ones(1,1,4)*10),R);
93
94
95
96 %
97 % $Log$
98 % Revision 1.4  2007/03/23 16:14:37  adb014
99 % Update the FSF address
100 %
101 % Revision 1.3  2007/01/04 23:50:47  hauberg
102 % Put seealso before end deftypefn
103 %
104 % Revision 1.2  2007/01/04 23:41:47  hauberg
105 % Minor changes in help text
106 %
107 % Revision 1.1  2006/08/20 12:59:35  hauberg
108 % Changed the structure to match the package system
109 %
110 % Revision 1.1  2004/08/11 19:52:41  jmones
111 % qtsetblk added
112 %
113 %