⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtsetblk.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
字号:
function B = qtsetblk(A,S,dim,val)
%QTSETBLK Set block values in quadtree decomposition.
%   J = QTSETBLK(I,S,DIM,VALS) replaces each DIM-by-DIM block in
%   the quadtree decomposition of I with the corresponding
%   DIM-by-DIM block in VALS. S is the sparse matrix returned by
%   QTDECOMP; it contains the quadtree structure. VALS is a
%   DIM-by-DIM-by-K array, where K is the number of DIM-by-DIM
%   blocks in the quadtree decomposition.
%
%   Class Support
%   -------------
%   I can be of class uint8 or double. S is of class sparse.
%
%   Remarks
%   -------
%   The ordering of the blocks in VALS must match the columnwise
%   order of the blocks in I. For example, if VALS is
%   4-by-4-by-2, VALS(:,:,1) contains the values used to replace
%   the first 4-by-4 block in I, and VALS(:,:,2) contains the
%   values for the second 4-by-4 block.
%
%   Example
%   -------
%       I = [1    1    1    1    2    3    6    6
%            1    1    2    1    4    5    6    8
%            1    1    1    1   10   15    7    7
%            1    1    1    1   20   25    7    7
%           20   22   20   22    1    2    3    4
%           20   22   22   20    5    6    7    8
%           20   22   20   20    9   10   11   12
%           22   22   20   20   13   14   15   16];
%
%       S = qtdecomp(I,5);
%       newvals = cat(3,zeros(4),ones(4));
%       J = qtsetblk(I,S,4,newvals);
%
%   See also QTDECOMP, QTGETBLK.

%   Steven L. Eddins, March 1995
%   Copyright 1993-1998 The MathWorks, Inc.  All Rights Reserved.
%   $Revision: 1.6 $  $Date: 1997/11/24 15:36:10 $

error(nargchk(4,4,nargin))

[M,N] = size(A);

blocks = find(S == dim)';
numBlocks = length(blocks);
if (~isequal([size(val,1) size(val,2) size(val,3)], [dim dim numBlocks]))
    if (prod(size(val)) == numBlocks)
        % Expand values to fill up the dim-by-dim blocks.
        val = repmat(val(:)',[dim^2 1]);
    else
        error('VAL must be DIM-by-DIM-by-NUMBLOCKS array or NUMBLOCKS-length vector');
    end
end
val = val(:);

% Compute block indices for a dim-by-dim block.
rows = (0:dim-1)';
cols = 0:M:(dim-1)*M;
rows = rows(:,ones(1,dim));
cols = cols(ones(dim,1),:);
ind = rows + cols;
ind = ind(:);

% Compute index matrix for block computations.
blocks = blocks(ones(length(ind),1),:);
ind = ind(:, ones(1,numBlocks));
ind = ind + blocks;

B = A;
B(ind) = val;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -