How to get exact position of text with respect to figure row, column in Matlab
11 次查看(过去 30 天)
显示 更早的评论
In the following code segment I am trying to get the exact position of the text bounding box with respect to the figure pixel coordinates( row and column) to eventually be able to crop off that part of figure ( from array img ). However what I get from textBox is not very helpful! some negative numbers!! can anyone provide me some tips
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','r');
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**
Please refer to this image:
0 个评论
回答(2 个)
Geoff
2012-3-29
I'm not sure about the general case, but here you could exploit the fact that your image bounds are not white:
[y,x] = find( img(:,:,1)~=255 & img(:,:,2)~=255 & img(:,:,3)~=255 );
tl = min([y x]);
br = max([y x]);
image(img(tl(1):br(1), tl(2):br(2),:));
0 个评论
per isakson
2012-3-29
The parent of an text-object is an axes-object. The extent of the text-object is relative to the axes-object. Use pixels for all objects. This is a start
axis off
axis([0 1 0 1]);
axh = gca;
set( axh, 'units', 'pixel' )
ax_pos = get( axh, 'Position' );
hText=text( 'units', 'pixel', ...
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!