matlab—影像分析基礎
Read and Show an image
imread() imshow()
I = imread('pout.tif'); %read imshow(I); %show
一張圖片有 rgb 三種顏色,每個點就是一個矩陣的數值,而這個數值就代表著 rgb,所以我們操作一個圖片,也就相當於操作一個矩陣內的數值,或者說,修改矩陣內的數值,也就相當於修改圖片
接下來做一個操作,將這個矩陣內行數和列數能被 2 整除的,將這一行和列內的值全部變為 0
for i = 1 : size(i,1) for j = 1 : size(i,2) if(rem(i,2) == 0 || rem(j,2) == 0) I(i,j) = 0; end end end
Imageinfo
如果想要查詢有關於一張圖片的相關資訊,可以使用函式 imageinfo
,其呼叫格式為: imageinfo('string')
,其中 string 為圖片的名稱 (包含字尾名)
imageinfo('pout.tif')
Imtool
imtool
函式主要是用來檢視一個圖片的每個畫素對應的數值
imtool('pout.tif')
Image Processing
immultiply()
immultiply
函式的呼叫格式為: Immultiply(I,x)
,其含義是,將影象對應的矩陣 I 內的所有數值乘以 x
I = imread('rice.png'); subplot(1,2,1); imshow(I); J = immultiply(I,1.5); subplot(1,2,2); imshow(J);
imadd()
imadd
函式的作用是將兩張影像相加,其呼叫格式為: imadd(I,J)
,I 的含義是一個影像對應的矩陣,J 是另一個影像對應的矩陣,但是使用 imadd()
函式有一個限制條件,就是 I,J 必須是同型的矩陣,否則無法相加
I = imread('rice.png'); J = imread('cameraman.tif'); K = imadd(I,J); subplot(1,3,1);imshow(I); subplot(1,3,2);imshow(J); subplot(1,3,3);imshow(K);
imhist()
imhist()
函式的作用是將一個圖片的數值分析出來並做成一個柱狀圖,其呼叫格式為: imhist(I)
I = imread('pout.tif'); imhist(I);
稍微解釋一下這個圖,橫座標是 0-255,縱座標是頻數,表示這個值有多少個
histeq()
通過分析上面的圖,我們發現他在某一個區間數值比較集中,而其他數值幾乎就沒有,這種影象的數值分佈並不是很均勻,所以如果我們想要它分佈更加均勻,就可以使用 histeq
函式,起呼叫格式為: histeq(I)
I = imread('pout.tif'); I2 = histeq(I); subplot(1,4,1);imhist(I); subplot(1,4,2);imshow(I); subplot(1,4,3);imshow(I2); subplot(1,4,4);imhist(I2);
imrotate()
imrotate
函式的作用是旋轉一個影象,其呼叫格式為: imrotate(I,theta,’bilinear’)
, theta
表示旋轉的角度, billinear
照寫即可
I = imread('rice.png'); subplot(1,2,1); imshow(I); J = imrotate(I,35,'bilinear'); subplot(1,2,2); imshow(J);

還有一些對影像的操作,這裡就不講了,下面附一張圖,有需要的可以自行Google
