Matlab中getframe函数的用法

比如这句 F = getframe(2,[85,58,20,20]);这句中的各个数字表示什么意思,忘知道的大侠解答下,感激不尽!

F = getframe(h,rect) specifies
a rectangular area from which to copy the pixmap. rect is
relative to the lower left corner of the figure or axes h,
in pixel units. rect is a four-element vector in the form [left
bottom width height], where width and height define
the dimensions of the rectangle.
本函数是要从图形对象中截取一块出来。其中h是图像句柄,rect是一个四元素向量,代表[a b c d],其中a表示截取区域到图像左端的像素数,b表示截取区域到图像底端的像素数,c表示截取区域水平像素数,d表示截取区域垂直向像素数。
得到的F是一个结构体(struct),包含两个元素:cdata和colormap,其中cdata是截取区域的数据,是一个三维数组,其中第三维的长度是3,即截取到的是区域中RGB的值。colormap是调色板,这个没啥意思。
例如:
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y)
set(gcf,'color',[1 1 1]) %设置背景色为白色
title('测试图像保存')
F=getframe(gcf); % 获取整个窗口内容的图像
F1=getframe; % 获取坐标轴为界的图像
imwrite(F.cdata,'test1.png')
imwrite(F1.cdata,'test2.png')
getframe获得的是一个架构struct类型的数据,
其中cdata子域的内容才可以用imwrite内容保存,用F.cdata表示
getframe(gcf) 即get current figure,获得窗口内图像,包含legend、title以及label。如果不添加gcf,默认为gca(get current axis)。
imwrite 可以保存jpg、png等格式图像,gif是7.0添加的,但是好像没办法保存为动画,只能保存第一帧。
与在图像界面直接利用复制,或用file>save as...保存不同的是,imwrite的背景色为窗口实际颜色,默认为灰色(RGB表示为[.7 .7 .7]),若想保留白色背景图,需添加例子中的set gcf color命令。
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-26
matlab help:

F = getframe(h,rect) specifies
a rectangular area from which to copy the pixmap. rect is
relative to the lower left corner of the figure or axes h,
in pixel units. rect is a four-element vector in the form [left
bottom width height], where width and height define
the dimensions of the rectangle.

本函数是要从图形对象中截取一块出来。其中h是图像句柄,rect是一个四元素向量,代表[a b c d],其中a表示截取区域到图像左端的像素数,b表示截取区域到图像底端的像素数,c表示截取区域水平像素数,d表示截取区域垂直向像素数。
得到的F是一个结构体(struct),包含两个元素:cdata和colormap,其中cdata是截取区域的数据,是一个三维数组,其中第三维的长度是3,即截取到的是区域中RGB的值。colormap是调色板,这个没啥意思。

F = getframe(2,[85,58,20,20]),显然 F.cdata 是一个 20*20*3的数组。

尝试以下代码:
Z = peaks; surf(Z);
F = getframe(gcf,[150 150 100 100]);
figure,imshow(F.cdata);本回答被提问者和网友采纳
第2个回答  2010-03-23
捕获2所指的窗口内左下角坐标为(85,58)且长宽都为20像素的正方形区域的图像