1. 程式人生 > >Matlab中關於影象顯示的幾個命令

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);

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。