Insert and Remove text from image

61 ビュー (過去 30 日間)
jack
jack 2016 年 1 月 22 日
コメント済み: Image Analyst 2022 年 4 月 20 日
Hi guys,
I need your help in solving the following problem:
I have an image which i would like to add to it text but after i need to delete that text, how would i do that if i use the method described in the following link for adding text to images : http://www.mathworks.com/help/vision/ref/inserttext.html#btp_i7c-1
Moreover how would i add labels to point using plot on images?
Thanks in advance.

回答 (2 件)

Image Analyst
Image Analyst 2016 年 1 月 22 日
That method burns text into the image. If you want to undo it, you'd have to still have the original image and just use that again.
To put text into the overlay, use text(). You can get the handle of that and call delete to remove it. The underlying image is not changed at all
hText = text(x, y, string);
% Get rid of it now
delete(hText);
  5 件のコメント
DGM
DGM 2022 年 4 月 20 日
編集済み: DGM 2022 年 4 月 20 日
if you're using a cell array to hold the handles, you could do:
% create a figure with some text objects in it
x = linspace(0,1,3);
y = x;
labelList = {'banana' 'orange','apple'};
hold on;
for jj = 1:numel(x)
textList{jj} = text(x(jj),y(jj),labelList(jj));
end
pause(2) % pause for dramatic effect
cellfun(@delete,textList) % delete them
But you don't really need to use a cell array for the handles. If you just use a handles array, you can just use delete() by itself.
% create a figure with some text objects in it
x = linspace(0,1,3);
y = x;
labelList = {'banana' 'orange','apple'};
hold on;
for jj = 1:numel(x)
textList(jj) = text(x(jj),y(jj),labelList(jj));
end
pause(2) % pause for dramatic effect
delete(textList)
Image Analyst
Image Analyst 2022 年 4 月 20 日
@Sanders A. see my Answer below on this page. I just added a new Answer.
You can also have functions to delete lines, etc. Just search for 'Type's like 'line', 'xline', etc.

サインインしてコメントする。


Image Analyst
Image Analyst 2022 年 4 月 20 日
To clear all text from an axes, you can use this function I wrote:
%=====================================================================
% Erases all text labels from the specified axes.
function ClearTextFromAxes(handleToAxes)
try
handlesToChildObjectsInAxes = findobj(handleToAxes, 'Type', 'text');
if ~isempty(handlesToChildObjectsInAxes)
delete(handlesToChildObjectsInAxes);
end
catch ME
errorMessage = sprintf('Error in program %s, function %s(), at line %d.\n\nError Message:\n%s', ...
mfilename, ME.stack(1).name, ME.stack(1).line, ME.message);
uiwait(warndlg(errorMessage));
end
return; % from ClearTextFromAxes

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by