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

📄 colcode2uint32.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -