Save Image with drawn shape not with original resolution

11 ビュー (過去 30 日間)
Ellen Zhang
Ellen Zhang 2018 年 10 月 19 日
コメント済み: Ellen Zhang 2018 年 10 月 25 日
Hi there, I was trying to save an image with color drawn shape (such as a rectangular) as tiff or png file. However the saved image is not as the same resolution as the orignal image, seems being compressed a lot. Here are the steps:
1. read in an image with size 7000*2000 uint 8. Matlab shows "Image is too big to fit on screen; displaying at 8%." 2. draw a red rectangular 3. Save the fig using "export_fig" or "InsertInImage" function. The saved image appears with much lower resolution comparing to the original grayscale image.
Could you please advice what would be the best way to save such image? Thank you, Ellen

採用された回答

tesarj13
tesarj13 2018 年 10 月 23 日
Save image with imwrite function!
  3 件のコメント
tesarj13
tesarj13 2018 年 10 月 23 日
Ok. I don't know how do you insert shapes, but it is easy with insertShape function:
A = uint8(rand(7000,2000)*255);% sample image with your resolution
A = insertShape(A,'rectangle',[1000 2000 1000...
500],'LineWidth',30,'color','red');
Now you can save it with imwrite:
imwrite(A,'image_by_imwrite.png')
Or you can save whole figure to image with desired resolution adjusted by last parameter, which is dpi.
fig = figure;% create figure
imshow(A)
print(fig,'image.png','-dpng','-r1000'); %1000 dpi
Ellen Zhang
Ellen Zhang 2018 年 10 月 25 日
That works. Thank you very much! I was using 'rectangular' to draw boxes and 'export_fig" to save images. 'insertShape" works better in this case.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by