How to get the exact position of text relative to a line of a drawing, a column in Matlab

In the next segment of code I am trying to get the exact position of the text bounding rectangle relative to the pixel coordinates (row and column), so that I end up removing that part of the shape (from the img array). However, what I get from the textBox is not very helpful! some negative numbers !! can someone give me some advice enter image description here

hFigure = figure('Color', 'w','position',...
[1600 200 600 250]...
,'MenuBar', 'none', 'ToolBar', 'none');

axis off
axis([0 1 0 1]); 

   'fontname','Times New Roman',...
 '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**



source to share

1 answer

Keep in mind this is img

coming from the command getFrame

and it is not very clear if the property knows 'Extent'

about the coordinates in this frame.

If you want to understand the coordinates img

, you might be better off:



And then cropping according to those coordinates.

Once you have used imagesc

, you can also use [x,y] = ginput(4);

to get the four click points and then do the math to crop as you want from the resulting positions x

and y


At least what I would do.

Also, as a reference, take a look at how to use the property correctly Extent




All Articles