Keep tight borders in image and still keep the title when saving

11 views (last 30 days)
I have quite a lot of 224x289 images that I want to save. I want to avoid wasting space with borders. Preferably the resulting images should all have the same size including their colorbar + colorbar title + figure title. Here is the code
figure(1);
imshow(image,range);
title('title');
c = colorbar;
c.Label.String = 'Gray value';
I tried saving with
iptsetpref('ImshowBorder','tight')
saveas(gcf,'name.png')
but it cuts away the title.
When saving with
set(gcf, 'PaperUnits', 'centimeters');
set(gcf, 'PaperPosition', [0 0 15 10]); %x_width=10cm y_width=15cm
saveas(gcf,'fig1.tif')
I tried to find reasonable values for width etc but I cannot for the life of me get the figure to show the colorbar with title AND the figure's title. Something always gets cut.
Can someone tell me how I could set my image size by hand or cut the image so that the margins are outside of my title and colorbar title?
  6 Comments
Nicolas Glienke
Nicolas Glienke on 26 Jul 2018
I have an additional Problem... When I view the figure and expand the window to fit my screen The title is off screen and the 0 and the 4000 on my colorbar are clipped...

Sign in to comment.

Accepted Answer

jonas
jonas on 26 Jul 2018
Edited: jonas on 26 Jul 2018
Use latest version of export_fig . Attached are two images. One is saved with export_fig and one with saveas.
A = imread('cameraman.tif');
imshow(A)
title('title');
c = colorbar;
c.Label.String = 'Gray value';
iptsetpref('ImshowBorder','tight')
%%Save
export_fig(1,'-jpeg','untitled_1')
saveas(1,'untitled_2.jpg')
Turns out export_fig crops the image by default, exactly as you requested.

More Answers (0)

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!