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

📄 cmpermute.m

📁 有关matlab的电子书籍有一定的帮助希望有用
💻 M
字号:
function [b,map] = cmpermute(a,cm,ndx)
%CMPERMUTE Rearrange colors in colormap.
%   [Y,NEWMAP] = CMPERMUTE(X,MAP) randomly reorders the colors in
%   MAP to produce a new colormap NEWMAP. CMPERMUTE also
%   modifies the values in X to maintain correspondence between
%   the indices and the colormap, and returns the result in
%   Y. The image Y and associated colormap NEWMAP produce the
%   same image as X and MAP.
%
%   [Y,NEWMAP] = CMPERMUTE(X,MAP,INDEX) uses an ordering matrix
%   (such as the second output of SORT) to define the order of
%   colors in the new colormap.
%
%   For example, to order a colormap by luminance, use:
%
%      ntsc = rgb2ntsc(map);
%      [dum,index] = sort(ntsc(:,1));
%      [Y,newmap] = cmpermute(X,map,index);
%
%   Class Support
%   -------------
%   The input image X can be of class uint8 or double. Y is
%   returned as an array of the same class as X.
%
%   Example
%   -------
%   This example orders a colormap by luminance
%
%       load trees
%       ntsc = rgb2ntsc(map);
%       [dum,index] = sort(ntsc(:,1));
%       [Y,newmap] = cmpermute(X,map,index);
%       imshow(X,map), figure, imshow(Y,newmap)
%
%   See also RANDPERM, SORT.

%   Clay M. Thompson 2-19-93
%   Copyright 1993-1998 The MathWorks, Inc.  All Rights Reserved.
%   $Revision: 5.7 $  $Date: 1997/11/24 15:34:16 $

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

if isa(a, 'uint8')
    a = double(a)+1;
    u8out = 1;       % Output a uint8 indexed image
else
    u8out = 0;       % Output a double precision indexed image
end

n = size(cm,1);

if nargin==2, % Use random permutation
  ndx = randperm(n);
end

if length(ndx)~=size(cm,1), 
  error('The length of NDX must equal the number of rows of MAP.');
end

pos(ndx) = 1:n;

b = zeros(size(a));
b(:) = pos(a);
map = cm(ndx,:);

if u8out
    b = uint8(b-1);
end

⌨️ 快捷键说明

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