3

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 enter image description here

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**
C graphics
  • 7,308
  • 19
  • 83
  • 134

1 Answers1

0

Keep in mind that img comes from the getFrame command and it's not very clear whether the 'Extent' property knows about the coordinates in this frame.

If you want to understand the coordinates of img, you might be better off doing:

imagesc(img);

And then cropping according to those coordinates.

Once you've used imagesc, you can also use [x,y] = ginput(4); to get four click points and then do the math to crop how you want from the resulting x and y positions.

At least that's what I'd do.


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

Chris A.
  • 6,817
  • 2
  • 25
  • 43