Maintain image size on saving
조회 수: 13 (최근 30일)
이전 댓글 표시
Hello all,
I am having some frustrating problems with saving MATLAB figures and would be very grateful for help.
When I save a figure using the following code the dimensions of the image and its contents are not maintained upon saving:
saveas(gcf, name, 'tiffn'); saveas(gcf, name, 'eps'); saveas(gcf, name, 'jpg');
On the other hand
saveas(gcf,name, 'fig')
DOES maintain the dimensions.
However if I save the figure in these formats by clicking through the file menu of the image window then these dimensions ARE saved in the image files. I have tried changing the default figure size using
set(0,'defaultFigurePosition', [pos(1) pos(2) width, height]),
but although this works for creating the figures at the correct size it doesn't help with the problem above.
I would be grateful for any help with this. Having to click through to save each file individually is not fun!
Thanks
Marta
댓글 수: 0
채택된 답변
Guillaume
2014년 11월 29일
I did report this issue (saveas vs file->save) over a year ago to mathworks and they pointed me to this answer. No idea, if this undocumented function still works in 2014b.
Bottom line, use hgsave
댓글 수: 5
Muhamad Luqman Mohd Nasir
2021년 5월 31일
how can i save multiple pic at once after i do image segmentation with the same image size
Image Analyst
2021년 5월 31일
@Muhamad Luqman Mohd Nasir If you don't want to save them sequentially with imwrite() then I think you'd have to save them all "at once" using save():
save('mutiple pictures.mat', 'image1', 'image2', 'image3');
추가 답변 (1개)
Image Analyst
2014년 11월 29일
The dimensions (size, rows and columns) of the image has nothing to do with it. The image is shrunk of magnified to fit onto the figure. So if your screen was 1600 by 1920 and your image was 3000 by 4000, and your figure was full screen, then it would shrink down the image to something less than 1600 by 1920 (because there's some gray blank padding around the axes/image on the figure). But doing saveas() should save the figure with the number of pixels that the figure is on your screen I would think. Again, forget about what size the image is - that doesn't count at all because it scales that to fit onto your figure.
댓글 수: 4
Image Analyst
2014년 11월 29일
OK, so you don't really mean an image like an image you've displayed on your figure. You're talking about the figure itself, like a screenshot.
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!