Save a figure as .bmp or .png WITHOUT background

12 ビュー (過去 30 日間)
MathReallyWorks
MathReallyWorks 2017 年 5 月 30 日
コメント済み: Sigal Cohen 2018 年 2 月 25 日
Hello everyone,
I have extracted this text from an image and removed all the extra parts apart from the text:
Now, I need to save this image as .bmp or .png using
saveas(gcf,'0','bmp');
But, this function saves the image in this way (i.e A white background is also included):
(Please look closely for that white background)
But, my purpose is to save this image without that white background such that it looks like this:
(I have cropped above image in a photo editor for better explanation of my problem)
Can anyone help me in achieving this?
Thanks in advance.

採用された回答

Jan
Jan 2017 年 5 月 30 日
Use imwrite with the image data, not imsave or saveas, which both try to save the contents of the figure.
  2 件のコメント
MathReallyWorks
MathReallyWorks 2017 年 5 月 30 日
編集済み: MathReallyWorks 2017 年 5 月 30 日
Thanks Jan Simon.
Sigal Cohen
Sigal Cohen 2018 年 2 月 25 日
Hi Jan Simon,
I tried to use imwrite to save without background, but I get this error:
*Error using imwrite (line 420) Expected DATA to be one of these types:
numeric, logical
Instead its type was matlab.ui.Figure.*
The figure I want to save is one of 40 figures in a for loop, and it's written as follows:
imwrite(figure(i),fullfile('D:\ISI', Exp, Acquisition,['' num2str(i) '.tif']));
So each figure is saved with chronological numbering (i=1:40).
I attached the file saved when I use the command 'saveas', with the background I don't need.
What is the problem? Can you help me please?
Thank you, Sigal.

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

その他の回答 (1 件)

Rik
Rik 2017 年 5 月 30 日
If you have the image as a binary matrix, you can use imsave to save it to file.
If you do not, you can load your current result with imread, crop it and write it out with imsave.
  1 件のコメント
MathReallyWorks
MathReallyWorks 2017 年 5 月 30 日
Thank you buddy!

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

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by