imslice.m

来自「有关matlab的电子书籍有一定的帮助希望有用」· M 代码 · 共 54 行

M
54
字号
function [r,c] = imslice(siz,k)
%IMSLICE Return index into image deck.
%   ELEM = IMSLICE([M N P],K) returns the element positions
%   of the image slice K in an M-by-N-by-P image deck.  IMSLICE
%   is used to extract or insert images into an image deck.  For
%   instance,
%       D(imslice([m n p],2)) = A;
%   inserts the image A into image slice 2 of the deck D.  Likewise,
%       A = D(imslice([m n p],3));
%   extracts image slice 3 from the deck D.  More than one image
%   can be extracted at once if K is a vector.  For example,
%       DNEW = D(imslice([m n p],3:5));
%   extracts the deck DNEW (with 3 images) from the deck D.
%
%   Image decks are a set of images arranged row-wise in a matrix.
%   An image deck containing the 3 images (A1,A2,A3) can be created
%   using D = [A1,A2,A2];
%   
%   Note: image decks are grandfathered.  Users are encouraged to
%   use MATLAB's 3-D array capability instead.
%
%   Example
%   -------
%   Use this command to convert an image deck D with size vector
%   SIZ to a 3-D array:
%
%        D2 = reshape(D,SIZ);

%   Clay M. Thompson 5-12-93
%   Copyright 1993-1998 The MathWorks, Inc.  All Rights Reserved.
%   $Revision: 5.5 $  $Date: 1997/11/24 15:35:36 $

error(nargchk(2,2,nargin));

if any( (k<0) | (k>siz(3)) ), error('Index K out of range.'); end
i = 1:siz(1); j = 1:siz(2);

if nargout==2
  [kk,jj] = meshgrid(k,j);
  r = i';
  c = jj + (kk-1)*siz(2);
  c = c(:);

else
  [jj,ii,kk] = meshgrid(j,i,k);
  r = reshape(ii + (jj-1)*siz(1) + (kk-1)*prod(siz(1:2)), ...
              siz(1),siz(2)*length(k));
  
end




⌨️ 快捷键说明

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