使图像中注释框的背景为半透明 [英] Make background of annotation box in image semi-transparent

查看:85
本文介绍了使图像中注释框的背景为半透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为MATLAB中的卫星图像添加注释.由于每个文本字段下方的颜色变化很大,因此我想在文本下方使用背景色,以使其更易于查看和阅读.

I am currently working on adding annotations to satellite images in MATLAB. Since the color underneath each text field can vary quite a lot, I want to use a background color under the text to make it easier to see and read.

但是,当我这样做时,很多地形都被掩盖了.我虽然试图将每个文本框的背景颜色设置为半透明,但是却想尽一切办法解决这个问题.

However, when I do this, a lot of the terrain gets obscured. I though of trying to make the background color for each text box semi transparent, but hit a dead end trying to come up with a solution.

有什么想法吗?我希望有一些UI元素可以将'facealpha'设置为0.5.我还需要文本来支持旋转(如下面的示例所示).

Any ideas? I was hoping for some UI-element where I could just set the 'facealpha' to maybe 0.5. I also need the text to support being rotated (as can be seen in the examples below).

下面是一些示例代码和生成的图像.带有卫星数据的工作空间也可以在以下链接中找到: 示例工作区

Below is some example code and the resulting image. The workspace with the satellite data can also be found in the link: Example workspace

figure(1);clf
imagesc(xx,yy,Map);

hold on
plot(xInspection,yInspection,'g.-')

% # Two ways of making a rotated text annotation. 
% # Cant make background semi-transparent
testAnno= annotation('textarrow',[0.5 0.5],[0.5 0.5], ...
                'string','textarrow annotation', ...
                'HeadStyle','none','LineStyle', 'none',...
                'TextRotation',asin(directionVec(1))*180/pi,...
                'TextBackgroundColor',[0.7 0.7 0.7]);

testText = text(mean(xInspection),mean(yInspection),'text annotation', ...
        'rotation',asin(directionVec(1))*180/pi, ...
        'HorizontalAlignment','right', ...
        'color',[0 0 0], ...
        'backgroundcolor',[0.7 0.7 0.7], ...
        'fontsize',8);

推荐答案

annotationtext看起来都不返回具有BackgroundAlpha属性的HgObject(它们可能存在,但我无法使用 getundoc 或尝试找到它们各种不同的技巧).

It doesn't look like either annotation or text return HgObjects that have BackgroundAlpha properties (they might exist but I wasn't able to find them using getundoc or by trying various different hacks).

我自己可以通过绘制背景来使某些东西工作.这是一个简单的概念证明:

I was able to get something working by drawing the background myself. Here is a simple proof of concept:

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);

这篇关于使图像中注释框的背景为半透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆