Insert and Remove text from image

61 vues (au cours des 30 derniers jours)
jack
jack le 22 Jan 2016
Commenté : Image Analyst le 20 Avr 2022
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.

Réponses (2)

Image Analyst
Image Analyst le 22 Jan 2016
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 commentaires
DGM
DGM le 20 Avr 2022
Modifié(e) : DGM le 20 Avr 2022
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 le 20 Avr 2022
@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.

Connectez-vous pour commenter.


Image Analyst
Image Analyst le 20 Avr 2022
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