2012-11-05 56 views
1

我目前正在MATLAB中爲衛星圖像添加註釋。由於每個文本字段下方的顏色可能會有很大差異,因此我希望在文本下方使用背景顏色,以便於查看和閱讀。使圖像中的註釋框背景半透明

但是,當我這樣做時,很多地形變得模糊。我雖然試圖讓每個文本框的背景顏色都是半透明的,但卻試圖想出一個解決方案。

任何想法?我希望有一些UI元素,我可以將「facealpha」設置爲0.5。我還需要文本來支持被旋轉(如下面的例子所示)。

下面是一些示例代碼和生成的圖像。與衛星數據的工作空間,也可以在鏈接中找到: 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); 

enter image description here

回答

4

它看起來不像annotationtext返回HgObjects具有BackgroundAlpha屬性(它們可能存在,但我無法找到它們使用getundoc或嘗試各種不同的黑客)。

我能夠通過自己繪製背景來獲得工作。這裏是一個簡單的概念證明:

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

謝謝!看起來很有前途,儘管補丁和文本對象在旋轉後放置在稍微不同的地方。我懷疑他們可能使用不同的樞軸點。 – Vidar

2

恐怕你可以做到這一點的唯一方法是任何顏色不設置爲您的註釋,然後在每個註釋的背景中放置一個patch。因此,像這樣:

% 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') 

但是,當然,最大的問題是確定補丁(XY)的正確座標。只需將座標乘以rotation matrix即可輕鬆旋轉。然而,找到貼片的長度和高度及其中心位置並不容易。您可能能夠找到一些有用的功能,爲此在Matlab中...