3
在下面的代碼段中,我試圖獲取文本邊界框相對於圖像像素座標(行和列)的確切位置,以最終能夠裁剪圖的那部分(從數組img)。然而,我從textBox得到的是不是很有幫助!一些負數!任何人都可以提供我一些提示 如何在Matlab中獲取文字相對於圖行,列的確切位置
hFigure = figure('Color', 'w','position',...
[1600 200 600 250]...
,'MenuBar', 'none', 'ToolBar', 'none');
axis off
axis([0 1 0 1]);
hText=text('String','T','fontsize',100,'color','r',...
'fontname','Times New Roman',...
'HorizontalAlignment','left','VerticalAlignment','bottom',...
'BackgroundColor',[.8 .8 .8],'EdgeColor','b');
set(hText, 'Units','Pixels');
textBox=get(hText, 'Extent');%[left,bottom,width,height]
figBox = get(hFigure,'Position');
imageData = getframe(hFigure);
img = imageData.cdata;
%using textBox and imgBox:
imgText=img(?:?,?:?,3); **% this is what I want to do**
不宜的情節實際上是一個軸?所以你還需要做一個get(gca,'position') – bdecaf 2012-03-29 20:32:45