Matlab 使图像中注释框的背景半透明
我目前正在MATLAB中为卫星图像添加注释。由于每个文本字段下面的颜色可能会有很大差异,因此我想在文本下面使用背景色,以使其更易于查看和阅读 然而,当我这样做时,很多地形变得模糊。我曾想过尝试使每个文本框的背景色都是半透明的,但在尝试想出解决方案时遇到了死胡同 有什么想法吗?我希望有一些UI元素,我可以将“facealpha”设置为0.5。我还需要文本来支持旋转(如下例所示) 下面是一些示例代码和生成的图像。包含卫星数据的工作区也可以在以下链接中找到:Matlab 使图像中注释框的背景半透明,matlab,Matlab,我目前正在MATLAB中为卫星图像添加注释。由于每个文本字段下面的颜色可能会有很大差异,因此我想在文本下面使用背景色,以使其更易于查看和阅读 然而,当我这样做时,很多地形变得模糊。我曾想过尝试使每个文本框的背景色都是半透明的,但在尝试想出解决方案时遇到了死胡同 有什么想法吗?我希望有一些UI元素,我可以将“facealpha”设置为0.5。我还需要文本来支持旋转(如下例所示) 下面是一些示例代码和生成的图像。包含卫星数据的工作区也可以在以下链接中找到: 恐怕你唯一能做到这一点的方法是不给你的注
恐怕你唯一能做到这一点的方法是不给你的注释设置任何颜色,然后在每个注释的背景中放置一个
补丁。比如说:
% Use completely transparent annotations
hA = annotation('textarrow', ..., 'TextBackgroundColor', 'none')
% Place a transparent patch exactly in the background of your annotation
hP = patch(X, Y, 'white', 'EdgeColor', 'none', 'FaceColor', 'white', ...
'alpha', 0.3)
% Ensure that your annotation is on top
uistack(hA, 'top')
当然,最大的问题是确定补丁的正确坐标(X
和Y
)。旋转很简单,只需将坐标乘以一个单位。然而,找到斑块的长度和高度及其中心位置并不是那么容易。您可能会在Matlab central找到一些有用的函数…恐怕唯一的方法是不为注释设置任何颜色,然后在每个注释的背景中放置一个补丁。比如说:
% Use completely transparent annotations
hA = annotation('textarrow', ..., 'TextBackgroundColor', 'none')
% Place a transparent patch exactly in the background of your annotation
hP = patch(X, Y, 'white', 'EdgeColor', 'none', 'FaceColor', 'white', ...
'alpha', 0.3)
% Ensure that your annotation is on top
uistack(hA, 'top')
当然,最大的问题是确定补丁的正确坐标(X
和Y
)。旋转很简单,只需将坐标乘以一个单位。然而,找到斑块的长度和高度及其中心位置并不是那么容易。您可能可以在Matlab central中找到一些有用的函数…它看起来既不像注释
也不像文本
返回具有BackgroundAlpha
属性的对象(它们可能存在,但我无法使用或尝试各种不同的破解方法找到它们)
我自己画了背景,使一些东西起作用了。以下是一个简单的概念证明:
f = figure;
tObj = text(.5, .5, 'text object', 'FontSize', 20);
set(gca,'XLimMode', 'manual', 'YLimMode', 'manual'); % prevent the axes from resizing automatically
p = get(tObj, 'Extent'); %Get the outer position of the text
% now create a patch around the text object
pObj = patch([p(1) p(1) p(1)+p(3) p(1)+p(3)], [p(2) p(2)+p(4) p(2)+p(4) p(2)], 'r');
uistack(tObj, 'top'); % put the text object on top of the patch object
set(pObj , 'FaceAlpha', .2); % set the alpha of the patch face to .2
%Rotate the objects
set(tObj, 'Rotation', 20);
rotate(pObj, [0 0 1], 20);
它看起来既不像annotation
也不像text
返回具有BackgroundAlpha
属性的对象(它们可能存在,但我无法使用或尝试各种不同的破解方法找到它们)
我自己画了背景,使一些东西起作用了。以下是一个简单的概念证明:
f = figure;
tObj = text(.5, .5, 'text object', 'FontSize', 20);
set(gca,'XLimMode', 'manual', 'YLimMode', 'manual'); % prevent the axes from resizing automatically
p = get(tObj, 'Extent'); %Get the outer position of the text
% now create a patch around the text object
pObj = patch([p(1) p(1) p(1)+p(3) p(1)+p(3)], [p(2) p(2)+p(4) p(2)+p(4) p(2)], 'r');
uistack(tObj, 'top'); % put the text object on top of the patch object
set(pObj , 'FaceAlpha', .2); % set the alpha of the patch face to .2
%Rotate the objects
set(tObj, 'Rotation', 20);
rotate(pObj, [0 0 1], 20);
谢谢虽然面片和文本对象在旋转后放置在稍有不同的位置,但看起来很有希望。我怀疑他们可能使用了不同的轴心点。谢谢!虽然面片和文本对象在旋转后放置在稍有不同的位置,但看起来很有希望。我怀疑他们可能使用了不同的轴心点。