matlab 三维图像配准,[转载]Matlab实现多种图像配准(转)
本文講述如何利用Matlab Image Processing Toolbox中的圖像配準(zhǔn)工具實(shí)現(xiàn)線性正投影、仿射、投影、多項(xiàng)式、分段線性、局部加權(quán)平均配準(zhǔn)的過程。
實(shí)驗(yàn)平臺(tái)
X86 PC,Windows XP sp2, Matlab 7.1
資源的獲取
matlab工具的使用方法:查看幫助mage Processing Toolbox User's Guide——Image registration。
涉及配準(zhǔn)方法簡(jiǎn)介
該工具箱提供的配準(zhǔn)方法均需手工選擇圖像間的匹配點(diǎn)對(duì)(control points pair),均屬于交互配準(zhǔn)方法。其基本過程為:讀入圖像數(shù)據(jù)->在兩副圖像上選擇足夠匹配點(diǎn)->選擇配準(zhǔn)算法,計(jì)算變換參數(shù)->變換圖像。
假設(shè)input image(輸入圖像)為欲進(jìn)行配準(zhǔn)的圖像,base image為配準(zhǔn)是的參考圖像。以下是我參考matlab幫助給出了簡(jiǎn)介。
1.線性正投影(linear conformal):最簡(jiǎn)單。平面映射成平面。
當(dāng)輸入輸入圖像與參考圖像對(duì)比,只是存在全局的平移、旋轉(zhuǎn)、縮放或其三者組合的差別時(shí)(正方形仍對(duì)應(yīng)正方形),選擇此配準(zhǔn)方法。此方法至少需要2對(duì)匹配點(diǎn)。
2.仿射(affine):將平行線轉(zhuǎn)換成平行線。
當(dāng)輸入圖像形狀存在切變現(xiàn)象(正方形對(duì)應(yīng)平行四邊形),選此法。至少需3對(duì)匹配點(diǎn)。
3.投影(projective):將直線映射成直線。
如果輸入圖像呈現(xiàn)傾斜,翹起現(xiàn)象,選此法。至少需4對(duì)匹配點(diǎn)。
4.多項(xiàng)式(polynomial):將直線映射成曲線。
如果輸入圖像出現(xiàn)不規(guī)則曲變,采用此法。Matlab中提供有2、3、4次冪的實(shí)現(xiàn),分別至少需要6,10,10對(duì)匹配點(diǎn)。
5.分段線性(piecewise linear)
如果輸入圖像的各個(gè)局部之間的退化模式明顯不一樣,選此法。至少需要4對(duì)匹配點(diǎn)。
6.局部加權(quán)平均(local weighted mean)
與分段線性一致,但效果較之好。至少需要6對(duì)(推薦12對(duì))匹配點(diǎn)。
實(shí)驗(yàn)步驟
1.讀取圖像數(shù)據(jù)。
因?yàn)樵磮D像以矩陣形式存在一個(gè)二進(jìn)制的文件里,用fread可將其讀取到變量矩陣中。將讀取文件編制成一個(gè)子函數(shù)(RTIread.m),源代碼如下:
function imMatrix=RTIread(FILENAME,SIZE)
%RTIreadRead the image matrix from binary "Registration Test Image" file.
%imMatrix=RTIread(FILENAME,SIZE) opens the file FILENAME, and reads the
%number of elements specified by SIZE.
%
%FILENAME is a string containing the name of the file to be opened.
%Valid entries for SIZE are:
%Nread N elements into a column vector.
%infread to the end of the file.
%[M,N]read elements to fill an M-by-N matrix, in column order.
%N can be inf, but M can't.
%
%It returns the image matrix.
fid=fopen(FILENAME,'r');
imMatrix=fread(fid,SIZE,'uint8=>uint8');
fclose(fid);
%image(imMatrix);
這里我們選取了兩張600×600的圖片,文件名為“casitas84”和“casitas86”。運(yùn)行以下代碼讀取圖像矩陣:
% 1. Read the images into the MATLAB
workspace.
base=RTIread('casitas84',[600,600]);
input=RTIread('casitas86',[600,600]);
2.選取匹配點(diǎn)(control points)。
根據(jù)預(yù)定的配準(zhǔn)方法,選定足夠的匹配點(diǎn)對(duì)。運(yùn)行下列代碼:
% 2.Specify control point pairs n the images and
save.
cpselect(input,base);%please
select 15 points for test.
出現(xiàn)GUI界面。
操作很簡(jiǎn)單,只需注意選點(diǎn)要均勻布開,以增加其代表性。選定完畢,File-> Save Points to
Workspace將數(shù)據(jù)保存到工作區(qū)中。Workspace立刻多出兩個(gè)N×2的數(shù)組(其中N為選定的匹配點(diǎn)對(duì)數(shù)),分別為input_points和base_points,如:
input_points =
119.5185193.5926
168.9012242.9753
105.9383140.5062
459.0247131.8642
313.3457257.7901
292.3580165.1975
276.308633.0988
283.7160380.0123
76.3086297.2963
135.567983.7160
360.2593313.3457
94.8272446.6790
70.1358354.0864
181.2469361.4938
381.2469460.2593
252.8519433.0988
3.利用十字相關(guān)法調(diào)整選定了的匹配點(diǎn)。
這步可選。運(yùn)行代碼:
% 3.Fine-tune the control points using
cross-correlation.
input_points_corr =
cpcorr(input_points,base_points,input,base); %optimism the
points
input_points_corr為優(yōu)化后在輸入圖片的對(duì)應(yīng)匹配點(diǎn)。
4.計(jì)算變換公式的參數(shù)。
利用cp2tform,選定變換類型(即配準(zhǔn)方法),計(jì)算變換參數(shù)。以下只需選定一種即可。
% 4.Specify the type of transformation to be used
and infer its parameters
% (1) not Fine-tune points
Tlinear =
cp2tform(input_points,base_points,'linear conformal');
Taffine =
cp2tform(input_points,base_points,'affine');
Tprojective =
cp2tform(input_points,base_points,'projective');
Tpolynomial2 =
cp2tform(input_points,base_points,'polynomial',2);
Tpolynomial3 =
cp2tform(input_points,base_points,'polynomial',3);
Tpolynomial4 =
cp2tform(input_points,base_points,'polynomial',4);
Tpiecewise =
cp2tform(input_points,base_points,'piecewise linear');
Tlwm =
cp2tform(input_points,base_points,'lwm');
% (2)Fine-tune points
fTlinear =
cp2tform(input_points_corr,base_points,'linear
conformal');
fTaffine =
cp2tform(input_points_corr,base_points,'affine');
fTprojective =
cp2tform(input_points_corr,base_points,'projective');
fTpolynomial2 =
cp2tform(input_points_corr,base_points,'polynomial',2);
fTpolynomial3 =
cp2tform(input_points_corr,base_points,'polynomial',3);
fTpolynomial4 =
cp2tform(input_points_corr,base_points,'polynomial',4);
fTpiecewise =
cp2tform(input_points_corr,base_points,'piecewise
linear');
fTlwm =
cp2tform(input_points_corr,base_points,'lwm');
諸如Tlinear的變量為一個(gè)稱為TFORM的數(shù)據(jù)結(jié)構(gòu),尚沒做仔細(xì)研究:
Tlinear =
ndims_in:
2
ndims_out:
2
forward_fcn:
@fwd_affine
inverse_fcn:
@inv_affine
tdata:
[1x1 struct]
5.變換圖像。
% 5.Transform the unregistered image to bring it
into alignment.
title('image registration polynomial
method');
subplot(2,2,1);
imshow(base);
title('Base image');
subplot(2,2,2);
imshow(input);
title('Input image');
subplot(2,2,3);
imshow(imtransform(input,Tpolynomial2));
title('registered image');
subplot(2,2,4);
imshow(imtransform(input,fTpolynomial2));
title('registered image(fine-tune
points)');
結(jié)果如下:
總結(jié)
1.image和imshow區(qū)別。前者視base,input此類二維圖片矩陣為索引圖像,在系統(tǒng)的index庫(kù)中選取顏色。
2.選擇適當(dāng)?shù)姆椒▉斫⑥D(zhuǎn)換參數(shù),并非算法越復(fù)雜越好,應(yīng)參考成像因素(退化因素)。
3.尚沒有看出十字相關(guān)法的好處。
4.
利用cpselect選擇匹配點(diǎn),cpselect可以返回一個(gè)GUI句柄。欲實(shí)現(xiàn)如下功能:當(dāng)打開cpselect GUI
時(shí),m文件程序暫停運(yùn)行,關(guān)閉之后繼續(xù)執(zhí)行。因?yàn)閷?duì)GUI編程不懂,?使用了waitfor,pause函數(shù)都沒法實(shí)現(xiàn)。嘗試中……
總結(jié)
以上是生活随笔為你收集整理的matlab 三维图像配准,[转载]Matlab实现多种图像配准(转)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 21朵水仙花算法java,柏拉图说,如果
- 下一篇: matlab resample上采样,r