How to get exact position of text with respect to figure row, column in Matlab
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Geoff
el 29 de Mzo. de 2012
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 comentarios
per isakson
el 29 de Mzo. de 2012
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 comentarios
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!