我有两件事要在同一张图中显示:a surf绘图和灰度图像。它们必须显示在同一个图中,并且绘图必须是彩色的。如果我先显示绘图并逐步执行代码,则绘图会以彩色显示,但是当显示灰度图像时,一切都会变成灰度图像。
注意:我尝试更改颜色图,但它也会更改灰度图像。有什么办法可以让绘图变成彩色吗?
这是我的代码片段:
figure;
subplot(1,2,1);
surf(data), shading interp;
subplot(1,2,2);
imshow(grayimg);
最佳答案
问题在于,Matlab 仅支持每个图形一个颜色图,您尝试使用两个:gray
用于图像,jet
用于冲浪图。
解决方法是欺骗 Matlab 相信图像是彩色的;)
figure;
subplot(1,2,1); surf(data); shading interp;
subplot(1,2,2); imshow( grayimg(:,:,[1 1 1]) ); % this is the trick: you convert one channel image to RGB image with all pixels shades of gray...
关于matlab - 如何在 MATLAB 中的同一个图中同时显示 RGB 和灰度图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24615135/