我有一个nxn矩阵,例如:
[ 0 1 1 ;
0.2 1 0.1;
0 0.4 0]
我想要想象我的矩阵,我想:
如下图所示:
我怎样才能做到这一点?
答案 0 :(得分:0)
以下解决方案构建色彩映射,并使用ind2rgb
创建RGB图像:
ind2rgb
将X转换为带有创建的色彩映射的RGB图像。检查以下代码示例:
A = [ 0 1 1;...
0.2 1 0.1;...
0 0.4 0];
%N - Number of elements in the color map (e.g 256) applies "quantization level".
N = 256;
%Convert A to "indexed image" in range [0, N].
X = round(A*N);
%Create color map with N elements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%R, G, B (Red, Green, Blue) applies three color components of color map.
R = zeros(N, 1);
G = zeros(N, 1);
B = zeros(N, 1);
%Create array of 100 values in range 0 to 1
V = linspace(0, 1, N);
%All values = 1 to be black
R(V == 1) = 0;
G(V == 1) = 0;
B(V == 1) = 0;
%All values between 0 and 1 (0 < value <1) to be white
R((V > 0) & (V < 1)) = 1;
G((V > 0) & (V < 1)) = 1;
B((V > 0) & (V < 1)) = 1;
%All values = 0 to be a specific color (red for example).
R(V == 0) = 1;
G(V == 0) = 0;
B(V == 0) = 0;
%Concatenate color components, and form Nx3 color map.
cmap = [R, G, B];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Convert A to RGB, using colormap cmap.
RGB = ind2rgb(X, cmap);
imshow(RGB);
解决方案不是最简单的解决方案,但它可用于解决更一般的可视化问题。