为什么这个带有颜色图的 imagesc-imshow 在 Matlab 中不起作用?
Why this imagesc-imshow with Colormap not Working in Matlab?
我正在考虑并扩展 中关于 到 show/join 两个图像同时在 Matlab 的滑块 中的滑块,具有更改颜色图的能力通过在 Matlab 2016a 中使用 .mat 数据。
因此,我必须使用 imagesc
因为您可以在那里更改颜色图。
我想从包含变量 time
、potential
和 matrix
的 .mat 数据制作图像,以便我可以更改 colormap/etc
使用 1 个 imagesc-imshow 的代码
for k=1:2
% loaded variables from .mat data
img=imagesc(time, potential, matrix);
colormap('jet')
signal=cat(2,signal,img);
end
windowWidth = 320;
hImg = imshow(signal(:,1:1 + windowWidth,:), ... % TODO complication here?
'InitialMagnification', 100, 'Border', 'tight');
% End of the video code here
% Not necessary for the case here!
最后想用imshow
做放大。
输出
Index exceeds matrix dimensions.
Error in masi (line 7)
hImg = imshow(signal(:,1:1 + windowWidth,:), ...
带有 imagesc-write-imshow 的代码 2
如果不以 .png 格式写入光盘并读取 .png 图像结果,我找不到执行 imagesc-imshow 的方法。
所以这里只有 saveas
和 imread
for k=1:2
% loaded variables from .mat data
imagesc(time, potential, matrix);
colormap('jet');
saveas(gcf,'/tmp/Figure','png');
imgRGB=imread(fullfile('/tmp/','Figure.png'));
signal=cat(2,signal,imgRGB);
end
windowWidth = 320;
hImg = imshow(signal(:,1:1 + windowWidth,:), ...
'InitialMagnification', 100, 'Border', 'tight');
通过写入和读取给出正确的输出。
使用 print -RGBImage -rNUMBER 试验总分辨率,
我正在试验 Suever 的总分辨率答案。我发现默认图像结果嘈杂,您可以在滑块视频中轻松看到。
我认为最好的分辨率是-r95。我知道这个信号有95%灵敏度的指标,所以我直接选择了它。测量中存在大约 5-15% 的不确定性,因此 -r85 可能也不错,但我现在不能很好地评估它。
对于我的系统中没有生成图像的分辨率,低边界是 r55 (OS X 13" Macbook Air)。
一些分辨率值和我的经验
GUI 中的 >r124 错误,表示某个上限
Struct contents reference from a non-struct array object.
Error in matlab.graphics.internal.getframeWithDecorations (line 49)
x = bi.getWidth();
Error in alternateGetframe
Error in getframe (line 84)
x = alternateGetframe(parentFig, h, offsetRect, withinClientRect);
Error in masi (line 114)
writeVideo(vid, getframe());
当输入信号的不确定性为 5-15% 时,能够估计 r85、r90 和 r95 之间的分辨率质量会非常好,这样我就不会从我的原始一维信号中分阶段丢失它。
查看每英寸单位数和重影,
我得到了奇怪的结果,发现 [0 0 15 15]
是输出图像大、重影小且没有边界伪影的最佳选择。
我尝试了一些数学因素,如 sqrt(2) 和 pi,但没有成功。
每英寸的默认点数与前者类似,但图像大约小两倍。
如何使用imshow
放大显示imagesc
的结果?
基本的想法似乎是您想要创建一个 RGB 图像,它是使用 imagesc
在屏幕上显示的内容的一个版本,而不 实际保存它先到磁盘。有几个可以做到这一点。
getframe
可以使用 getframe
. This will return a structure that has two fields: cdata
and colormap
获取当前轴的简单屏幕截图。 cdata
字段是您指定图形的 RGB 表示(如果您未指定,则为 gcf
)。
fr = getframe(hfig);
rgbImage = fr.cdata;
这种方法的缺点是 getframe
的输出分辨率只是图形的大小(以像素为单位)。如果您在小屏幕上显示非常大的图像,您显然会在生成的图像中丢失很多细节。
打印
内置print
function is typically used to send information to a printer or image file; however you can specify the output device to be -RGBImage
,这将return一个RGB版本作为输出。
rgbImage = print(hfig, '-RGBImage');
使用 print
的真正好处是您可以 control the resolution 输出图像以及许多其他因素。
biggerRGB = print(hfig, '-RGBImage', '-r300'); % 300 dpi
如果您在创建图形时确定指定尺寸(以英寸为单位),则无论您当时使用的是什么机器,此操作的结果都将是相同的尺寸。
hfig = figure('Units', 'inches', 'Position', [0 0 10 10]);
将此与上面的 -r300
结合使用,结果将始终 为 3000x3000 像素。
我正在考虑并扩展 imagesc
因为您可以在那里更改颜色图。
我想从包含变量 time
、potential
和 matrix
的 .mat 数据制作图像,以便我可以更改 colormap/etc
使用 1 个 imagesc-imshow 的代码
for k=1:2
% loaded variables from .mat data
img=imagesc(time, potential, matrix);
colormap('jet')
signal=cat(2,signal,img);
end
windowWidth = 320;
hImg = imshow(signal(:,1:1 + windowWidth,:), ... % TODO complication here?
'InitialMagnification', 100, 'Border', 'tight');
% End of the video code here
% Not necessary for the case here!
最后想用imshow
做放大。
输出
Index exceeds matrix dimensions.
Error in masi (line 7)
hImg = imshow(signal(:,1:1 + windowWidth,:), ...
带有 imagesc-write-imshow 的代码 2
如果不以 .png 格式写入光盘并读取 .png 图像结果,我找不到执行 imagesc-imshow 的方法。
所以这里只有 saveas
和 imread
for k=1:2
% loaded variables from .mat data
imagesc(time, potential, matrix);
colormap('jet');
saveas(gcf,'/tmp/Figure','png');
imgRGB=imread(fullfile('/tmp/','Figure.png'));
signal=cat(2,signal,imgRGB);
end
windowWidth = 320;
hImg = imshow(signal(:,1:1 + windowWidth,:), ...
'InitialMagnification', 100, 'Border', 'tight');
通过写入和读取给出正确的输出。
使用 print -RGBImage -rNUMBER 试验总分辨率,
我正在试验 Suever 的总分辨率答案。我发现默认图像结果嘈杂,您可以在滑块视频中轻松看到。 我认为最好的分辨率是-r95。我知道这个信号有95%灵敏度的指标,所以我直接选择了它。测量中存在大约 5-15% 的不确定性,因此 -r85 可能也不错,但我现在不能很好地评估它。 对于我的系统中没有生成图像的分辨率,低边界是 r55 (OS X 13" Macbook Air)。 一些分辨率值和我的经验
GUI 中的 >r124 错误,表示某个上限
Struct contents reference from a non-struct array object.
Error in matlab.graphics.internal.getframeWithDecorations (line 49)
x = bi.getWidth();
Error in alternateGetframe
Error in getframe (line 84)
x = alternateGetframe(parentFig, h, offsetRect, withinClientRect);
Error in masi (line 114)
writeVideo(vid, getframe());
当输入信号的不确定性为 5-15% 时,能够估计 r85、r90 和 r95 之间的分辨率质量会非常好,这样我就不会从我的原始一维信号中分阶段丢失它。
查看每英寸单位数和重影,
我得到了奇怪的结果,发现 [0 0 15 15]
是输出图像大、重影小且没有边界伪影的最佳选择。
我尝试了一些数学因素,如 sqrt(2) 和 pi,但没有成功。
每英寸的默认点数与前者类似,但图像大约小两倍。
如何使用imshow
放大显示imagesc
的结果?
基本的想法似乎是您想要创建一个 RGB 图像,它是使用 imagesc
在屏幕上显示的内容的一个版本,而不 实际保存它先到磁盘。有几个可以做到这一点。
getframe
可以使用 getframe
. This will return a structure that has two fields: cdata
and colormap
获取当前轴的简单屏幕截图。 cdata
字段是您指定图形的 RGB 表示(如果您未指定,则为 gcf
)。
fr = getframe(hfig);
rgbImage = fr.cdata;
这种方法的缺点是 getframe
的输出分辨率只是图形的大小(以像素为单位)。如果您在小屏幕上显示非常大的图像,您显然会在生成的图像中丢失很多细节。
打印
内置print
function is typically used to send information to a printer or image file; however you can specify the output device to be -RGBImage
,这将return一个RGB版本作为输出。
rgbImage = print(hfig, '-RGBImage');
使用 print
的真正好处是您可以 control the resolution 输出图像以及许多其他因素。
biggerRGB = print(hfig, '-RGBImage', '-r300'); % 300 dpi
如果您在创建图形时确定指定尺寸(以英寸为单位),则无论您当时使用的是什么机器,此操作的结果都将是相同的尺寸。
hfig = figure('Units', 'inches', 'Position', [0 0 10 10]);
将此与上面的 -r300
结合使用,结果将始终 为 3000x3000 像素。