在Matlab中以特定分辨率保存图像
我花了几个小时试图以特定的分辨率(320x240)简单地输出特定的绘图 其中在Matlab中以特定分辨率保存图像,matlab,Matlab,我花了几个小时试图以特定的分辨率(320x240)简单地输出特定的绘图 其中saveas以任意分辨率输出jpg图像导出图仍显示轴 添加轴关闭或轴拉紧也没有帮助。 有人有主意吗 更新: 问题解决了。为了完整起见,这里是我当前的解决方案: xmax = 320; ymax = 240; xmin = 0; ymin = 0; figure; set(gcf,'position',[1060 860 320 240]); subaxis(1,1,1, 'Spacing', 0.01
saveas
以任意分辨率输出jpg图像<代码>导出图仍显示轴
添加轴关闭
或轴拉紧
也没有帮助。
有人有主意吗
更新:问题解决了。为了完整起见,这里是我当前的解决方案:
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
固定图形位置以匹配320x240分辨率是可能的,但使用imresize
更简单(我认为)
以下代码示例,将图形转换为图像,并使用imrezie
将分辨率设置为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
有一个更简单的解决方案 说你有你的图形,gcf,你捕获了框架,只需使用imresize编辑框架的对象属性cdata
frame = getframe(gcf);
frame.cdata = imresize(frame.cdata,[240, 320]);
然后,您可以使用该帧编写视频,该帧现在具有指定的分辨率
writeVideo(VideoObj,frame);
它运行得很好。这实际上帮助我解决了这个问题,非常感谢。为了完整性,我将在我的下发布完整的解决方案(没有轴和填充)question@mcExchange移除填充物并最小化间距是关键。感谢您发布您的解决方案。
writeVideo(VideoObj,frame);