Insert and Remove text from image
조회 수: 62 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
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
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
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
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!