
Matlab中保存图像时,图形窗口大小的控制zz
首先要了解的是Matlab是面向对象的。最高等级的对象是screen,它定义了figure可以用的最大szie。
screen下面是figure。figue就是你画图的时候跳出来的那个新的对话窗口。如果figure变化,screen是不会跟着变化的。但screen变化的话,figure就要跟着变化了。
figure下面是axes。axes是那个窗口里面你要画的东西。axes的大小和位置取决于figure,如果你放大缩小figure的大小的话,里面的图线也会跟着变化的。
set(gca,'position',[])
因此,set (gca,'position',[0.1,0.1,0.9,0.9] );的作用是:
设置坐标轴距离画板(图形窗口figure)边距。
[0.1,0.1,0.9,0.9] 分别为axes在figure中的左边界,下边界,宽度,高度,最小为0,最大为1(左边界,下边界为0,上边界,右边界为1)
见下面的例子:
-----------------------------------------------------------------------------
figure
set (gca,'position',[0.1,0.1,0.9,0.9] );
x=1:0.1:10;
y=sin(x);
plot(x,y)
-----------------------------------------------------------------------------
结果见下图:
set(gcf,'position',[])
一般matlab绘出来图的框架(图形窗口)大都是正方形或者近似正方形的矩形,能不能画一些扁的矩形呢?
使用图形的position属性可以做到。
如set(gcf,'unit','normalized','position',[0.2,0.2,0.,0.32]);的意思是:
对gcf的position进行设置。使其在屏幕上的显示位置是以(0.2,0.2)为原点,长0.,宽0.32。同gca一样,仍然是左边界,下边界为0,
上边界,右边界为1。
另外,gcf的position也可以不是normalized的。如下面的例子:
-----------------------------------------------------------------------------
x=-2*pi:0.1:2*9i;y=sin(x);figure;set (gcf,'Position',[500,500,500,500], 'color','w') %大小设置plot(x,y,'k-') %节点位移图形输出xlim([min(s(:,2)) max(s(:,2))])grid on
-----------------------------------------------------------------------------
其中,
[500,500,500,500]的意思为:原点的位置x,原点的位置y,宽,高,其坐标为points(详见下面),
现在问题还存在:
如果仅设置position的话,打印的时候还是正方形。可以用下面的方法解决:
通常默认情况下,print命令输出图像为 8*5inches,无视屏幕显示尺寸
通过命令行修改的话有三步
1 设置paperposition为manual
set(gcf,'PaperPositionMode', 'manual')
[ auto | {manual} ]
2 设置paperunit
set(gcf,'PaperUnits','inches')
[ {inches} | centimeters | normalized | points ]
3 设置paperposition
set(gcf,'PaperPosition',[left,bottom,width,height])
例如
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'points');
set(gcf, 'PaperPosition', [0 0 0 480]);
还有一个相关命令是papersize
paperposition 是placement,代表图像在paper(感觉就是屏幕screen的意思?)中的所处位置。left和bottom计算好,就可以使图像在paper中居中
papersize是纸张大小;position要比size小的
PaperPosition
four-element rect vector
Location on printed page. A rectangle that determines the location of the figure on the printed page. Specify this rectangle with a vector of the form
rect = [left, bottom, width, height]
where left specifies the distance from the left side of the paper to the left side of the rectangle and bottom specifies the distance from the bottom of the page to the bottom of the rectangle. Together these distances define the lower-left corner of the rectangle. width and height define the dimensions of the rectangle. The PaperUnits property specifies the units used to define this rectangle.
要使图像比例输出与屏幕显示的一致,可以使用如下命令
屏幕显示图像尺寸可以plot时用 set(gcf,'position',[left bottom width height]) 调整,或者print之前拖动窗口手动调整
This example exports a figure at screen size to a 24-bit TIFF file, myfigure.tif.
% set(gcf,'position',[80 100 800 600]) % 如果手动拖放,则不需要这一行命令
set(gcf, 'PaperPositionMode', 'auto') % Use screen size
print -dtiff myfigure
用matlab画了一张图,投稿时要缩小,缩小后字体就会过小或者发虚。我摸索出比较好的方法是如下的代码:%%%%%%%%%%%%%%%%%%%%%%plot your figure before%%%%%%%%%%%%%%%%%%%%%% figure resize
set(gcf,'Position',[100 100 260 220]);
set(gca,'Position',[.13 .17 .80 .74]);
figure_FontSize=8;
set(get(gca,'XLabel'),'FontSize',figure_FontSize,'Vertical','top');
set(get(gca,'YLabel'),'FontSize',figure_FontSize,'Vertical','middle');
set(findobj('FontSize',10),'FontSize',figure_FontSize);
set(findobj(get(gca,'Children'),'LineWidth',0.5),'LineWidth',2);%%%%%%%%%%%%%%%%%%%%%%%%%%%%解释:set(gcf,'Position',[100 100 260 220]);
这句是设置绘图的大小,不需要到word里再调整大小。我给的参数,图的大小是7cmset(gca,'Position',[.13 .17 .80 .74]);
这句是设置xy轴在图片中占的比例,可能需要自己微调。figure_FontSize=8;
set(get(gca,'XLabel'),'FontSize',figure_FontSize,'Vertical','top');
set(get(gca,'YLabel'),'FontSize',figure_FontSize,'Vertical','middle');
set(findobj('FontSize',10),'FontSize',figure_FontSize);这4句是将字体大小改为8号字,在小图里很清晰set(findobj(get(gca,'Children'),'LineWidth',0.5),'LineWidth',2);
这句是将线宽改为2
[转载]【Matlab】 print输出图像大小调整
已有 7803 次阅读 2011-10-20 18:09 |系统分类:科研笔记|关键词:print
通常默认情况下,print命令输出图像为 8*5inches,无视屏幕显示尺寸
通过命令行修改的话有三步
1 设置paperposition为manual
set(gcf,'PaperPositionMode', 'manual')
[ auto | {manual} ]
2 设置paperunit
set(gcf,'PaperUnits','inches')
[ {inches} | centimeters | normalized | points ]
3 设置paperposition
set(gcf,'PaperPosition',[left,bottom,width,height])
例如
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'points');
set(gcf, 'PaperPosition', [0 0 0 480]);
要使图像比例输出与屏幕显示的一致,可以使用如下命令
屏幕显示图像尺寸可以plot时用 set(gcf,'position',[left bottom width height]) 调整,或者print之前拖动窗口手动调整
This example exports a figure at screen size to a 24-bit TIFF file, myfigure.tif.
% set(gcf,'position',[80 100 800 600]) % 如果手动拖放,则不需要这一行命令
set(gcf, 'PaperPositionMode', 'auto') % Use screen size
print -dtiff myfigure
http://www.zdh1909.com/html/matlab/10873.html
matlab中imwrite和saveas的区别
文章来源:不详 作者:佚名
该文章讲述了matlab中imwrite和saveas的区别.
如果只有一幅图,handle设为gcf
如果有多副,handle需单独设置
matlab中imwrite(image_data,['directory\\','filename'])
需要与getframe连用
两个命令都可以用来保存图像,区别在于
1、背景色:saveas保存的图像 背景色自动设置为白色,imwrite保存图像为所见即所得
2、图像大小: saveas无视你设置的图像大小,按默认保存,imwrite保存所见即所得
contrast example:在当前目录下image文件夹下找到两个图像,对比一下
clear
clc
x=0:pi/100:2*pi;
y=sin(x);
h=plot(x,y); % h为plot线的句柄handle
set(gcf,'position',[80,100,400,600])
% 将图像设置为距屏幕左下角 [80,100]像素
% 图像大小设置为400*600像素
set(gcf,'color',[1,1,1]) % 背景色设置为白色
mkdir image
% 在当前文件夹下新建image文件夹,如果已存在会warning,不影响运行
% ========================
% ========================
f=getframe(gcf);
%% 也可以像下面这样用
% [X,map]=getframe(gcf);
http://blog.sina.com.cn/s/blog_810614a00101tmn7.html
matlab 保存高分辨率图像 dpi要在300以上
(2014-03-31 19:16:43)
转载▼
标签:
| 保存图像 | 分类: matlab |
然后就会在MATLAB的工作目录下(一般为work文件夹)生成一个名为
testdpi.tif的图像文件,并且DPI为300(右击/属性/摘要/高级)。
由于.tif格式的图像是没有压缩的,所以文件比较大。
最后,用ACDSee软件将该图像文件转换成JPEG格式就行了。
用ACDSee软件转换生成的格式的文件DPI仍然为300。
我搞了一上午才发现了这套方法。从MATLAB的help里搜索imwrite,发
现的。tiff格式图像是矢量图,没有压缩损失,据说可以任意缩放。用
MATLAB生成的图像文件,先保存成eps或tiff格式的文件,再用ACDSee软件
转换成其他格式的文件,是一个不错的方法
matlab 输出图像可用file-export setup-rendering-resolution-300或600-export-保存为JPEG图片然后在word中插入该图片即可,分辨率越高越清晰,一般用于打印的分辨率要求至少300dpi以上,而你用copy得到的分辨率只有72dpi,所以打印出来很模糊。
缺点:分辨率很高,但图线过细,仍然显的过于虚、不清楚,而且不太容易调整,
http://www.doc88.com/p-03343473495.html
http://wenku.baidu.com/view/dccf4dc20c22590102029dd4.html?from=rec&pos=3&weight=12&lastweight=10&count=5
http://blog.sina.com.cn/s/blog_6fb8aa0d01019icn.html
【matlab】 print输出图像大小调整
(2012-08-23 13:14:21)
转载▼
标签:
| 杂谈 | 分类: MATLAB |
通常默认情况下,print命令输出图像为 8*5inches,无视屏幕显示尺寸
通过命令行修改的话有三步
1 设置paperposition为manual
set(gcf,'PaperPositionMode', 'manual')
[ auto | {manual} ]
2 设置paperunit
set(gcf,'PaperUnits')
[ {inches} | centimeters | normalized | points ]
3 设置paperposition
set(gcf,'PaperPosition',[left,bottom,width,height])
例如
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'points');
set(gcf, 'PaperPosition', [0 0 0 480]);
还有一个相关命令是papersize
paperposition 是placement,代表图像在paper中的所处位置。left和bottom计算好,就可以使图像在paper中居中
papersize是纸张大小;position要比size小的
PaperPosition
four-element rect vector
Location on printed page. A rectangle that determines the location of the figure on the printed page. Specify this rectangle with a vector of the form
rect = [left, bottom, width, height]
where left specifies the distance from the left side of the paper to the left side of the rectangle and bottom specifies the distance from the bottom of the page to the bottom of the rectangle. Together these distances define the lower-left corner of the rectangle. width and height define the dimensions of the rectangle. The PaperUnits property specifies the units used to define this rectangle.?
要使图像比例输出与屏幕显示的一致,可以使用如下命令
屏幕显示图像尺寸可以plot时用 set(gcf,'position',[left bottom width height]) 调整,或者print之前拖动窗口手动调整
This example exports a figure at screen size to a 24-bit TIFF file, myfigure.tif.
set(gcf, 'PaperPositionMode', 'auto') % Use screen size
print -dtiff myfigure
==================================================================================================================================================================================================================================================================
单位("units")属性的默认值为像素(pixels),但是它的属性值还可以为英尺(inches),公分(centimeters),点(points),或归一化坐标(normalixed coordinates)。像素代表了屏幕像素,即在屏幕上可表示出来的最小的对象。典型的计算机屏幕最小分辨为 0×480,在屏幕的每一个位置都有超过 1000 的像素。因为像素数因机算机屏幕的不同而不同,所以指定对象的大小也会随之改变。
归一化坐标是在 0 到1范围内。在归一化坐标中,屏幕的左下角为[0,0]右上角为[1.0, 1.0]。 如果对象的位置归一化坐标系的形式描述,那么不同分辨率的显示器上对象的相对位置是固定的。例如,下面的语句创建了一个图象,把图象放置在屏幕的上部,而不用考虑显示器的大小。
H = figure(1)
set(H,'units', 'normalized','position',[0 .5 .5 .45])
好的编程习惯:如果你想把对象放置在窗口的特定位置,最好的方法是用归一化坐标,因为不用考虑显示器的大小。
