Matlab中關於圖像顯示的幾個命令

1.clf

clf deletes from the current figure all graphics objects whose handles are not hidden (i.e., their HandleVisibility property is set to on).

就是刪除當前figure的圖像。下面給個例子:

原始圖像:


經過clf;命令之後的圖像:


2.colormap

通過doc colormap;命令可以看到詳細的解釋。在Matlab中每個figure有且僅有一個colormap, 翻譯過來即是顏色映射。A colormap is an 64-by-3 matrix of real numbers between 0.0 and 1.0. Each row is an RGB vector that defines one color. The kth row of the colormap defines the kth color, where map(k,:) = [r(k) g(k) b(k)]) specifies the intensity of red, green, and blue. 在Matlab命令窗口直接輸入colormap回車就可看到一個64*3的數組。

Matlab中支持的colormap類型有:


默認爲'jet',一般使用'gray'。命令格式:

colormap('gray');

colormap gray;

colormap(gray);

網上有篇關於colormap的博文寫得不錯,可以參考一下:http://blog.sina.com.cn/s/blog_618af1950100eyp4.html

3.axes

The basic purpose of an axes object is to provide a coordinate system for plotted data, axes properties provide considerable control over the way MATLAB displays data. The current axes is the target for functions that draw image, line, patch, rectangle, surface, and text graphics objects.

用於figure中,指定作圖區域。常用的axes的屬性爲'position',命令格式爲:

axes('position',[left bottom width height]);%注意這裏的left,bottom,width,height取值範圍爲[0,1]

例:

axes('position',[.1  .1  .8  .6])
mesh(peaks(20));
axes('position',[.1  .7  .8  .2])
pcolor([1:10;1:10]);


4.imagesc

The imagesc function scales image data to the full range of the current colormap and displays the image. 所以imagesc一般配合colormap和axes一起使用。

imagesc(C,clims) normalizes the values in C to the range specified by clims and displays C as an image. clims is a two-element vector that limits the range of data values in C. These values map to the full range of values in the current colormap. 

實際在使用imagesc函數時,一定要先聲明colormap,因爲imagesc是在colormap中展開的。如果不聲明, 由於colormap默認值是'jet',所以得到的圖像顏色很奇怪。imagesc(C)可以直接在colormap上顯示圖像C,由於支持映射,C可以是[0,1]之間的double數組(比如有的灰度圖/256之後將像素值範圍壓縮到了[0,1]),這時應採用imagesc(C,[0,1]). 當然如果要在指定區域內顯示圖像,可以加上命令axes。

經典流程:

clf;

colormap gray;

axes('position',[a,b,c,d]);

imagesc(frame,[x,y]);

下面補充兩個經常配合這些作圖函數使用的命令:

1.axis equal tight off;

在使用axes命令時會顯示座標系刻度,如果想去掉的話可以在畫完圖之後使用該語句。

2.set函數

set('MenuBar','none');%去掉當前figure窗口的菜單欄。當然set函數的功能非常強大,可以參考doc set。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章