C++如何实现MATLAB中的ind2rgb函数,跪求大神解答!

如题,我用MATLAB配置了一张索引表,索引表为 8192*3,如何根据提供的矩阵(512*424)生成一张RGB图像(512*424*3)

http://blog.csdn.net/carson2005/article/details/7614125

bool clSaveImage(char* path, ClImage* bmpImg) // 参考这个函数,根据BMP相应的规则填写正确的RGB值。。

同求答案!下面是MATLAB的实现源码,如果你知道MATLAB基本语法,可以尝试把它转换到C++。

 function [rout,g,b] = ind2rgb(a,cm)
%IND2RGB Convert indexed image to RGB image.
%   RGB = IND2RGB(X,MAP) converts the matrix X and corresponding
%   colormap MAP to RGB (truecolor) format.
%
%   Class Support
%   -------------
%   X can be of class uint8, uint16, or double. RGB is an 
%   M-by-N-by-3 array of class double.
%
%   See also RGB2IND.

%   Clay M. Thompson 9-29-92
%   Copyright 1984-2010 The MathWorks, Inc. 

if ~isfloat(a)
    a = double(a)+1;    % Switch to one based indexing
end

narginchk(2,2);

% Make sure A is in the range from 1 to size(cm,1)
a = max(1,min(a,size(cm,1)));

% Extract r,g,b components
r = zeros(size(a)); r(:) = cm(a,1);
g = zeros(size(a)); g(:) = cm(a,2);
b = zeros(size(a)); b(:) = cm(a,3);

if nargout==3
  rout = r;
else
  rout = zeros([size(r),3]);
  rout(:,:,1) = r;
  rout(:,:,2) = g;
  rout(:,:,3) = b;
end