Octave 中每个子图的单独颜色图
Separate colormap for each subplot in Octave
Matlab 提供了为每个子图设置单独的颜色图的功能。 Octave docs
描述的相同功能
即以下短语:
Function File: cmap = colormap (hax, …)
If the first argument hax is an axes handle, then the colormap for the parent figure of hax is queried or set.
但是,当我尝试 运行 遵循代码时,出于某种原因,我最终为所有子图设置了单一颜色图。
clear -all;
clc;
img = zeros(128, 128);
img(64,64) = 0.2;
rad = radon(img);
x = 1;
y = 4;
s1 = subplot(y,x,1); imagesc(img);
colormap(s1, gray);
s2 = subplot(y,x,2); imagesc(rad);
colormap(s2, hot);
colorbar;
line_img = zeros(128, 128);
line_img(64, 32:64) = 0.5;
line_img(63, 32:64) = 0.4;
line_img(63, 32:64) = 0.2;
line_rad = radon(line_img);
s3 = subplot(y,x,3); imshow(line_img);
colormap(s3, gray);
s4 = subplot(y,x,4); imagesc(line_rad);
colormap(s4, hot);
colorbar;
感谢任何帮助。我希望在 "hot" 中有灰度源图像和氡变换图像。出于某种原因,我得到的第一个子图有点像灰度(实际上不是,因为我用值 0.2 初始化点并且八度为它提供纯白色,而我期待相当深的灰色),剩下的图像似乎已设置 "hot" 颜色图。
如果你仔细阅读文档中的那一行,你会发现如果你传递一个轴句柄,父图的 颜色图就会改变。这与具有不同颜色图的每个轴不同,因为它们都在同一个图中。
Function File: cmap = colormap (hax, …)
If the first argument hax is an axes handle, then the colormap for the parent figure of hax is queried or set.
目前,Octave 不支持这个最近才在 MATLAB 中引入的功能。
解决此问题的方法是在使用 imshow
显示之前将您的图像转换为 RGB 图像,然后图形的颜色图就无关紧要了。您可以先将其转换为索引图像(使用 gray2ind
),然后使用 ind2rgb
转换为 RGB。
% To display the grayscale image
rgb = ind2rgb(gray2ind(img), gray);
imshow(rgb);
附带说明一下,您的第一个灰度图像显示为全白的原因是如果 imshow
的输入类型为 double
,则所有值都应为介于 0 和 1 之间。如果您想更改此行为,您可以使用 imshow
的第二个输入来指定您想要缩放颜色限制以匹配您的数据
imshow(img, [])
Matlab 提供了为每个子图设置单独的颜色图的功能。 Octave docs
描述的相同功能即以下短语:
Function File: cmap = colormap (hax, …) If the first argument hax is an axes handle, then the colormap for the parent figure of hax is queried or set.
但是,当我尝试 运行 遵循代码时,出于某种原因,我最终为所有子图设置了单一颜色图。
clear -all;
clc;
img = zeros(128, 128);
img(64,64) = 0.2;
rad = radon(img);
x = 1;
y = 4;
s1 = subplot(y,x,1); imagesc(img);
colormap(s1, gray);
s2 = subplot(y,x,2); imagesc(rad);
colormap(s2, hot);
colorbar;
line_img = zeros(128, 128);
line_img(64, 32:64) = 0.5;
line_img(63, 32:64) = 0.4;
line_img(63, 32:64) = 0.2;
line_rad = radon(line_img);
s3 = subplot(y,x,3); imshow(line_img);
colormap(s3, gray);
s4 = subplot(y,x,4); imagesc(line_rad);
colormap(s4, hot);
colorbar;
感谢任何帮助。我希望在 "hot" 中有灰度源图像和氡变换图像。出于某种原因,我得到的第一个子图有点像灰度(实际上不是,因为我用值 0.2 初始化点并且八度为它提供纯白色,而我期待相当深的灰色),剩下的图像似乎已设置 "hot" 颜色图。
如果你仔细阅读文档中的那一行,你会发现如果你传递一个轴句柄,父图的 颜色图就会改变。这与具有不同颜色图的每个轴不同,因为它们都在同一个图中。
Function File:
cmap = colormap (hax, …)
If the first argument hax is an axes handle, then the colormap for the parent figure of hax is queried or set.
目前,Octave 不支持这个最近才在 MATLAB 中引入的功能。
解决此问题的方法是在使用 imshow
显示之前将您的图像转换为 RGB 图像,然后图形的颜色图就无关紧要了。您可以先将其转换为索引图像(使用 gray2ind
),然后使用 ind2rgb
转换为 RGB。
% To display the grayscale image
rgb = ind2rgb(gray2ind(img), gray);
imshow(rgb);
附带说明一下,您的第一个灰度图像显示为全白的原因是如果 imshow
的输入类型为 double
,则所有值都应为介于 0 和 1 之间。如果您想更改此行为,您可以使用 imshow
的第二个输入来指定您想要缩放颜色限制以匹配您的数据
imshow(img, [])