2008年9月28日 星期日

IMSHOW: Display image

IMSHOW 指令就是將影像顯示在 figure window 之中。不過, 由於影像的格式與類型實在是太多, 太複雜了, 因此, 如果你在 command window 之中, 用 help 查詢 IMSHOW 指令, 你會看到非常多種下不同參數的 IMSHOW 指令。若從另一種角度來看, 這不正也顯示出 IMSHOW 指令的功能強大嗎?
imshow(w)

FIGURE: Create figure window

FIGURE, by itself, creates a new figure window, and returns its handle.
FIGURE(H) makes H the current figure, forces it to become visible, and raises it above all other figures on the screen. If Figure H does not exist, and H is an integer, a new figure is created with handle H.
FIGURE 就是建立一個放置圖片或圖表的視窗。一般來說, 如果你要顯示一張圖片, 直接打
imshow(w)
MATLAB 會自動產生一個 figure 1 視窗, 然後直接將 w 這張圖片放上去,



如果我們繼續鍵入
imshow(x)
MATLAB 會將圖片 x 放到 figure 1 視窗, 取代原先的圖片 w ,



若想要將圖片 x 放到 figure 2 之中, 就必須先用 FIGURE 指令產生一個新的 figure window 然後再執行 imshow(x) 指令。
imshow(w);
figure, imshow(x);
 

IMREAD: Read image from graphics file

把 IMREAD 這個指令拆解, 就是 image read, 就是從影像檔案中讀入影像資料到 workspace 中, 在 MATLAB 整合環境的 Command Window 中鍵入 help imread, 你會看到關於 IMREAD 指令的完整說明。底下就是出現在說明文字中的第一段:
A = IMREAD(FILENAME,FMT) reads a grayscale or color image from the file specified by the string FILENAME, where the string FMT specifies the format of the file.
我們直接用例子說明。請下載範例影像 wombats.tif 與 twins.tif 後, 在 Command Window 鍵入:
w=imread('wombats.tif');
你會發現在 workspace 視窗中, 已經多了一列資料, 告訴你 w 這個矩陣變數的大小就是 256 * 256, 每個元素的資料型態是 uint8, 換句話說就是長度為 8 位元的 unsigned integer, 沒有正負號的整數。因此, 可表示的數值範圍為 0 ~ 255 的正整數。

 
由於 wombats.tif 是一張灰階影像 ( grayscale image ), 因此, w 是一個二維矩陣。接著, 我們鍵入
x=imread('twins.tif');
觀察 workspace 就會發現多了一個三維陣列 x。