필터 지우기
필터 지우기

Insert Shape and Inserttext in same Image

조회 수: 7 (최근 30일)
Adrian Pielmeier
Adrian Pielmeier 2018년 6월 12일
댓글: Walter Roberson 2018년 6월 12일
Hello
how can i display my circle and a text in the same Image using imshow ? This is my Code. But it doesnt really work. I only get one of both but not Text and Shape in the Same figure/ image:
%Image
I = imread ('bonds_image.jpg');
%Draw circle with a border line width of 5
RGB = insertShape ( I , 'circle', [527 626 20] , 'LineWidth' , 5 , 'Color' , 'red');
imshow (RGB);
%Insert Bond Text
text_str = 'Bond 1 Draht 38';
position = [532 26];
RGB_text = insertText (I, position, text_str, 'FontSize', 18, 'BoxColor', 'red', 'TextColor', 'black');
imshow (RGB_text);

채택된 답변

Guillaume
Guillaume 2018년 6월 12일
All functions in matlab work the same way, they never modify the input. Instead they return a copy of the input with the required modifications. Hence, when you call insertShape or insertText, your I is never changed. The inserted text or shape is only visible in the returned image. Thus you need to pass that returned image to the next insertXXX to insert both:
I = imread ('bonds_image.jpg');
I_with_circle = insertShape(I , 'circle', [527 626 20] , 'LineWidth' , 5 , 'Color' , 'red');
I_with_circle_and_text = insertText(I_with_circle, [532, 26], 'Bond 1 Draht 38', 'FontSize', 18, 'BoxColor', 'red', 'TextColor', 'black');
imshow(I_with_circle_and_text);
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 6월 12일
... Actually, functions that take handle objects can modify the input. For example,
set(gca, 'Xlim', [1 20])
is a function call that modifies the input object returned by gca instead of returning second new axes.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by