2012-03-29 60 views
3

在下面的代碼段中,我試圖獲取文本邊界框相對於圖像像素座標(行和列)的確切位置,以最終能夠裁剪圖的那部分(從數組img)。然而,我從textBox得到的是不是很有幫助!一些負數!任何人都可以提供我一些提示 enter image description here如何在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** 
+0

不宜的情節實際上是一個軸?所以你還需要做一個get(gca,'position') – bdecaf 2012-03-29 20:32:45

回答

0

記住img來自getFrame命令,它不是很清楚'Extent'屬性是否知道在這個框架的座標。裁剪根據這些座標

imagesc(img); 

然後:

如果你想了解的img座標,你可能會更好做。

一旦你使用imagesc,您還可以使用[x,y] = ginput(4);拿到四個觸動點,然後做數學裁剪你如何從產生xy立場想。

至少這就是我要做的。


Also, as a side note here's a link about how to properly use the Extent property.

相關問題