colcode2uint32.m
来自「toolbox of BVQX, This is the access betw」· M 代码 · 共 75 行
M
75 行
function outarray = colcode2uint32(inarray)
% colcode2uint32 - convert from colcode to uint32 array
%
% FORMAT: outarray = colcode2uint32(inarray)
%
% Input fields:
%
% inarray Nx4 input array of type colcolde
% (n, 1) = color index or NaN
% (n, 2) = red component (0...255)
% (n, 3) = green component (0...255)
% (n, 4) = blue component (0...255)
%
% Output fields:
%
% outarray Nx1 uint32 array
%
% See also uint322colcode
% Version: v0.6b
% Build: 6122016
% Date: Dec-20 2006, 4:30 PM CET
% Author: Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools
% argument check
if nargin ~= 1 || ...
~isa(inarray, 'double') || ...
~isreal(inarray) || ...
issparse(inarray) || ...
length(size(inarray)) ~= 2 || ...
size(inarray, 2) ~= 4
error( ...
'BVQXtools:BadArgument', ...
'Bad/missing input argument supplied.' ...
);
end
% produce output array
outarray = uint32(zeros(size(inarray, 1), 1));
% leave if empty
if isempty(inarray)
return;
end
% force RGB in RGB(:, [2, 3, 4])
for cc = 2:4
inarray(isinf(inarray(:, cc)), cc) = 0;
inarray(isnan(inarray(:, cc)), cc) = 0;
inarray(inarray(:, cc) < 0 , cc) = 0;
inarray(inarray(:, cc) > 255 , cc) = 255;
end
inarray = fix(inarray);
% rgbcolormod/min, rfactor, gfactor
rgbcolortot = 256 * 16777216;
rgbcolormin = 63 * 16777216;
rfactor = 65536;
gfactor = 256;
% get colors with indices
idxcolor = find(~isnan(inarray(:, 1)));
rgbcolor = find( isnan(inarray(:, 1)));
% set index color
outarray(idxcolor) = uint32( ...
mod(inarray(idxcolor, 1), rgbcolortot));
% fill those correctly
outarray(rgbcolor) = uint32(rgbcolormin + ...
rfactor .* inarray(rgbcolor, 2) + ...
gfactor .* inarray(rgbcolor, 3) + ...
inarray(rgbcolor, 4));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?