필터 지우기
필터 지우기

Adding a Title to imwrite Command

조회 수: 10 (최근 30일)
Fritz Sonnichsen
Fritz Sonnichsen 2020년 8월 13일
댓글: Rik 2020년 8월 14일
I am trying to do imwrite's adding titles to the output images. I tried the code below but it doesn't work. Probably I am using "plot" constucts that don't apply here. The forum was a bit vague on this. Is there any way to add a title to imwrite?
Thanks
fritz
imwrite (p, gray,outfl)
titl = strcat(''TITLE HERE');
title(titl)
  댓글 수: 1
Rik
Rik 2020년 8월 13일
What do mean exactly with title? Do you want to add a text to the image itself? Do you want to set a char array as one of the EXIF fields?

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

채택된 답변

Johannes Hougaard
Johannes Hougaard 2020년 8월 13일
You have to add the title to your figure before using imwrite.
If it is indeed images (.jpg, .tiff etc) that constitutes your p and gray read from an image using imread I believe this will do the trick
[p,gray] = imread("yourfilenamehere.tif");
newfig = figure;
imshow(p,gray);
title("TITLE HERE");
newimg = getframe(newfig);
imwrite(newimg.cdata,gray,outfl);
If your data p are not an RGB image, but rather a graphic depiction of numeric data in matlab it'd probably be easier to use the print option to save your graph as an image file.
x = linspace(-10,10,111);
p = sin(x);
newfig = figure;
plot(x,p);
title("This is sin(x) in the range -10 to 10");
print(newfig,outfl,'-djpeg'); % If save as .jpg, change to -dpng for .png or -dtiff for .tif
  댓글 수: 2
Fritz Sonnichsen
Fritz Sonnichsen 2020년 8월 14일
OK---it worked--somewhat more lengthy than expected!
Thanks
Fritz
Rik
Rik 2020년 8월 14일
You might also be interested in alternative: convert text to an image and add that on top of your original image. You can use a function like text2im to do that.
If the answer by Johannes solved your issue, don't forget to mark his answer as accepted, if not, feel free to comment with your remaining issues.

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

추가 답변 (1개)

Ferheen Ayaz
Ferheen Ayaz 2020년 8월 13일
I think you may want to do this
F=figure(1)
imshow('1.png')
title('Hello')
frame=getframe(F)
im=frame2im(frame)
imwrite(im,'2.png')

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by