在Matlab中以特定分辨率保存图像 [英] Save image in specific resolution in Matlab

查看:1280
本文介绍了在Matlab中以特定分辨率保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用几个小时来简单地以特定的分辨率(320x240)输出特定的图.

I'm trying for hours to simply output a certain plot in a specific resolution (320x240).

  xmax = 320; ymax = 240;
  xmin = 0; ymin = 0;
  figure;
  set(gcf,'position',[1060 860 320 240]);
  axis([xmin,xmax,ymin,ymax]);
  plot(someLinesAndPointsInTheRange320X240);
  saveas(gca,outName,'jpg');
  export_fig(outName);

saveas以任意分辨率输出jpg图像的位置. export_fig仍在显示轴.

Where saveas output the jpg image in an arbitrary resolution. export_fig is still showing the axes.

添加axis offaxis tight均无济于事. 有人知道吗?

Adding an axis off or axis tight doesn't help either. Has anyone an idea?

更新:
问题已经解决了.为了完整起见,这是我当前的解决方案:

UPDATE:
The problem is solved. Just for completeness here is my current solution:

  xmax = 320; ymax = 240;
  xmin = 0; ymin = 0;
  figure;
  set(gcf,'position',[1060 860 320 240]);
  subaxis(1,1,1, 'Spacing', 0.01, 'Padding', 0, 'Margin', 0);  % Removes padding
  axis([xmin,xmax,ymin,ymax]);
  plot(someLinesAndPointsInTheRange320X240);
  axis([xmin,xmax,ymin,ymax]);

  set(gca,'xtick',[],'ytick',[]); % Removes axis notation
  I = frame2im(getframe(gcf)); %Convert plot to image (true color RGB matrix).
  J = imresize(I, [240, 320], 'bicubic'); %Resize image to resolution 320x240
  imwrite(J, 'outName.jpg'); %Save image to file

推荐答案

可能的解决方案是将图形转换为图像,并使用imresize.

Possible solution is converting figure to image, and use imresize.

可以固定图形位置以匹配320x240分辨率,但是使用imresize更简单(我认为).

Fixing the figure position to match 320x240 resolution is possible, but using imresize is simpler (I think).

以下代码示例,将图形转换为图像,并使用imrezie将分辨率设置为320x240:

The following code sample, convert figure to image, and use imrezie to set resolution to 320x240:

figure;
% xmax = 320; ymax = 240;
% xmin = 0; ymin = 0;  
% set(gcf,'position',[1060 860 320 240]);
% axis([xmin,xmax,ymin,ymax]);

plot(sin(-pi:0.01:pi)); %Example figure
I = frame2im(getframe(gcf)); %Convert plot to image (true color RGB matrix).
J = imresize(I, [240, 320], 'bicubic'); %Resize image to resolution 320x240
imwrite(J, 'J.jpg'); %Save image to file

这篇关于在Matlab中以特定分辨率保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆