无论如何在 MATLAB 中加粗 imagesc 的某些区域?
Is there anyway to bold certain regions of imagesc in MATLAB?
以下矩阵是从 imagesc(rand(10,10)) 派生的,作为一个纯粹的例子。
我想知道在 MATLAB 中是否有办法为某些元素提供粗体黑色边框?我在 MS paint 中做了一个糟糕的例子只是为了说明这一点。
您可以只使用 plot
在任何您想要的地方绘制线条。
imagesc(rand(10,10)), hold on
plot([1.5,1.5],[0,10],'black','LineWidth',3)
然后按照您想要的方式定义边界框。
我认为更好的替代方法是使用 patch
,例如:
imagesc(rand(10,10)), hold on
vert = 0.5+[0 0; 1 0; 1 1; 0 1]; % x and y vertex coordinates
fac = [1 2 3 4]; % vertices to connect to make square
patch('Faces',fac,'Vertices',vert,'FaceColor','none','LineWidth',2)
vert2 = 0.5+[5 6; 5 8; 9 8; 9 5; 7 5; 7 6]; % x and y vertex coordinates
fac2 = [1 2 3 4 5 6 ]; % vertices to connect to make the other closed polygon
patch('Faces',fac2,'Vertices',vert2,'FaceColor','none','LineWidth',2)
请注意,我将 0.5 添加到顶点坐标的原因是因为在 imagesc
中,bin 以整数值为中心,因此 bin 边缘在 0.5 值上。
以下矩阵是从 imagesc(rand(10,10)) 派生的,作为一个纯粹的例子。
我想知道在 MATLAB 中是否有办法为某些元素提供粗体黑色边框?我在 MS paint 中做了一个糟糕的例子只是为了说明这一点。
您可以只使用 plot
在任何您想要的地方绘制线条。
imagesc(rand(10,10)), hold on
plot([1.5,1.5],[0,10],'black','LineWidth',3)
然后按照您想要的方式定义边界框。
我认为更好的替代方法是使用 patch
,例如:
imagesc(rand(10,10)), hold on
vert = 0.5+[0 0; 1 0; 1 1; 0 1]; % x and y vertex coordinates
fac = [1 2 3 4]; % vertices to connect to make square
patch('Faces',fac,'Vertices',vert,'FaceColor','none','LineWidth',2)
vert2 = 0.5+[5 6; 5 8; 9 8; 9 5; 7 5; 7 6]; % x and y vertex coordinates
fac2 = [1 2 3 4 5 6 ]; % vertices to connect to make the other closed polygon
patch('Faces',fac2,'Vertices',vert2,'FaceColor','none','LineWidth',2)
请注意,我将 0.5 添加到顶点坐标的原因是因为在 imagesc
中,bin 以整数值为中心,因此 bin 边缘在 0.5 值上。