如何将图像从索引转换为RGB颜色usinh matlab?
问题描述:
如何将图像从索引转换为RGB颜色usinh matlab?我以前已将其转换为rgb索引,但是当我使用ind2rgb()
将其转换回rgb时,图像中没有任何更改。如何将图像从索引转换为RGB颜色usinh matlab?
答
%matmap2rgb
%converts a MxN matrix, and a Lx3 matrix to MxNx3 matrix
%syntax: matmap2rgb(mat, map);
function outrgbmat=matmap2rgb(mat, map)
rowVect=map(mat+1,:);
outrgbmat(:,:,1)=reshape(rowVect(:,1),size(mat,1),size(mat,2));
outrgbmat(:,:,2)=reshape(rowVect(:,2),size(mat,1),size(mat,2));
outrgbmat(:,:,3)=reshape(rowVect(:,3),size(mat,1),size(mat,2));
end