在MATLAB imagesc函数中显示网格线

AJA*_*AJA 3 matlab image matlab-figure

我一直在尝试使用imagesc函数显示纯黑色网格线,这样每个像素周围都有一个黑色边界.我尝试了一些方法,但似乎无论如何,线条总是通过像素.作为一个例子,对于imagesc(randn(21,21)),我试图得到一个图,其中每个正方形(即像素)这里有一个黑色边框.

我在这里找到了一个解决方案:在matlab中,如何在图像上绘制网格,但我不确定如何使用imagec,而不是a.jpg图像.

我也尝试使用hold on功能手动放置线条.但是每个解决方案,似乎网格线都穿过像素的中间.任何帮助,将不胜感激.谢谢.

Jen*_*sen 5

请尝试以下方法:

imagesc(randn(21,21))
hold on;
for i = 1:22
   plot([.5,21.5],[i-.5,i-.5],'k-');
   plot([i-.5,i-.5],[.5,21.5],'k-');
end
Run Code Online (Sandbox Code Playgroud)

编辑:事物是像素的中心位于整数格点,所以要勾勒像素,你需要使用以.5结尾的坐标.


Lui*_*ndo 5

pcolor 完全是这样的:

pcolor(randn(15,21))
axis image %// equal scale on both axes
axis ij %// use if you want the origin at the top, like with imagesc
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 一个根本的区别是`pcolor`为顶点而不是单元格着色,而`imagesc`为单元格着色......一个人应该注意简单地从`imagesc`到'pcolor`因为内容将被移位; 检查它:`figure; pcolor(hadamard(20)); title('pcolor'); set(gca,'YDir','Reverse'); figure; imagesc(hadamard(20))` (4认同)