⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lucasperso.html

📁 Lukas Kanade Multi resolution program in matlab language.
💻 HTML
字号:
<!DOCTYPE html  PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"><html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd">   <head>      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">         <!--This HTML is auto-generated from an M-file.To make changes, update the M-file and republish this document.      -->      <title>LucasPerso</title>      <meta name="generator" content="MATLAB 7.4">      <meta name="date" content="2008-05-30">      <meta name="m-file" content="LucasPerso"><style>body {  background-color: white;  margin:10px;}h1 {  color: #990000;   font-size: x-large;}h2 {  color: #990000;  font-size: medium;}/* Make the text shrink to fit narrow windows, but not stretch too far in wide windows. */ p,h1,h2,div.content div {  max-width: 600px;  /* Hack for IE6 */  width: auto !important; width: 600px;}pre.codeinput {  background: #EEEEEE;  padding: 10px;}@media print {  pre.codeinput {word-wrap:break-word; width:100%;}} span.keyword {color: #0000FF}span.comment {color: #228B22}span.string {color: #A020F0}span.untermstring {color: #B20000}span.syscmd {color: #B28C00}pre.codeoutput {  color: #666666;  padding: 10px;}pre.error {  color: red;}p.footer {  text-align: right;  font-size: xx-small;  font-weight: lighter;  font-style: italic;  color: gray;}  </style></head>   <body>      <div class="content">         <h2>Contents</h2>         <div>            <ul>               <li><a href="#2">Algorithme de Lucas &amp; Kanade</a></li>               <li><a href="#3">Chargement des images</a></li>               <li><a href="#4">Filtrage</a></li>               <li><a href="#5">Calcul en 1D</a></li>               <li><a href="#6">Calcul 2D</a></li>            </ul>         </div><pre class="codeinput"><span class="comment">% Gaetan Boehringer, Bruno Jacquot &amp; Fr&eacute;d&eacute;ric Piegay</span></pre><h2>Algorithme de Lucas &amp; Kanade<a name="2"></a></h2>         <h2>Chargement des images<a name="3"></a></h2><pre class="codeinput">clear <span class="string">all</span>;close <span class="string">all</span>;clc;<span class="comment">% Lecture des images</span>im1o=double(imread(<span class="string">'LKtest3im1.bmp'</span>));im2o=double(imread(<span class="string">'LKtest3im2.bmp'</span>));[Lim,Cim]=size(im1o);<span class="comment">% Affichage des images</span>figure;subplot(1,2,1); imagesc(im1o);axis <span class="string">equal</span>; colormap(gray);title(<span class="string">'Image initiale'</span>);subplot(1,2,2); imagesc(im2o);axis <span class="string">equal</span>; colormap(gray); title (<span class="string">'Image d&eacute;cal&eacute;e'</span>);</pre><img vspace="5" hspace="5" src="LucasPerso_01.png"> <h2>Filtrage<a name="4"></a></h2><pre class="codeinput">h = fspecial(<span class="string">'gaussian'</span>,10,3);im1 = imfilter(im1o,h);im2 = imfilter(im2o,h);<span class="comment">% Affichage des images filtr&eacute;es</span>figure;subplot(1,2,1); imagesc(im1);axis <span class="string">equal</span>; colormap(gray);title(<span class="string">'Image initiale filtr&eacute;e'</span>);subplot(1,2,2); imagesc(im2);axis <span class="string">equal</span>; colormap(gray);title(<span class="string">'Image d&eacute;cal&eacute;e filtr&eacute;e'</span>);</pre><img vspace="5" hspace="5" src="LucasPerso_02.png"> <h2>Calcul en 1D<a name="5"></a></h2>         <p>Affichage d'un profil</p><pre class="codeinput"><span class="comment">% Extraction de la ligne centrale de chacune des images</span>y1=im1(:,Cim/2)';y2=im2(:,Cim/2)';[L,C]=size(y1);<span class="comment">% Affichage</span>figure;plot(y1,<span class="string">'b'</span>);hold <span class="string">on</span>;plot(y2,<span class="string">'m'</span>); title(<span class="string">'Affichage du profil de la ligne des 2 images'</span>);grady=zeros(1,C);ypf=conv(y1,(1/12)*[-1 8 0 -8 1]); <span class="comment">% On applique un filtre &agrave; cette ligne</span>grady=ypf(3:C+2); <span class="comment">% On supprime le bord</span><span class="comment">% Gradient temporel et calcul de u (valeur du d&eacute;placement selon y)</span>gradt=y2-y1;u=gradt*pinv(grady)</pre><pre class="codeoutput">u =   -0.1921</pre><img vspace="5" hspace="5" src="LucasPerso_03.png"> <h2>Calcul 2D<a name="6"></a></h2><pre class="codeinput"><span class="comment">% Calcul des gradients</span>f=[-1,8,0,-8,1]/12;im1fx=filter2(f,im1,<span class="string">'same'</span>); <span class="comment">% Gradient selon y</span>im1fy=filter2(f',im1,<span class="string">'same'</span>); <span class="comment">% Gradient selon x</span>imt=im2-im1; <span class="comment">% Gradient temporel</span><span class="comment">% Affichage des gradients</span>figure;subplot(1,3,1); imagesc(im1fx);axis <span class="string">equal</span>; colormap(gray);title (<span class="string">'Gradient selon x'</span>);subplot(1,3,2); imagesc(im1fy);axis <span class="string">equal</span>; colormap(gray);title (<span class="string">'Gradient selon y'</span>);subplot(1,3,3); imagesc(imt);axis <span class="string">equal</span>; colormap(gray);title (<span class="string">'Gradient temporel'</span>);<span class="comment">% Gestion des bords : suppression du bord  (&eacute;paisseur 10 pixels)</span>bord=10;Ix1=im1fx(bord:Lim-bord,bord:Lim-bord);Iy1=im1fy(bord:Lim-bord,bord:Lim-bord);It=imt(bord:Lim-bord,bord:Lim-bord);<span class="comment">% Transfert vecteurs colonnes</span>Ix_y=[Ix1(:),Iy1(:)];It=It(:);<span class="comment">% Calcul de u et v</span>Ix_yINV=pinv(Ix_y);fprintf(<span class="string">'Lucas Kanade : le d&eacute;placement est de (pixels) :\n'</span>)-Ix_yINV*It <span class="comment">% Calcul du vecteur d&eacute;placement avec l'algorithme de Lucas &amp; Kanade</span><span class="comment">% Corr&eacute;lation</span>fprintf(<span class="string">'Interpolation : le d&eacute;placement est de (pixels) :\n'</span>)[xmax,ymax]=depnormcorr(im1o,im2o);dep=[-xmax,-ymax]  <span class="comment">% Calcul du vecteur d&eacute;placement par la fonction de corr&eacute;lation</span><span class="comment">% Avec la m&eacute;thode de Lucas &amp; Kanade, on obtient des r&eacute;sultats sensiblement</span><span class="comment">% identiques &agrave; ceux obtenus avec la m&eacute;thode de corr&eacute;lation.</span></pre><pre class="codeoutput">Lucas Kanade : le d&eacute;placement est de (pixels) :ans =   -1.9454    0.0029Interpolation : le d&eacute;placement est de (pixels) :dep =   -1.9735   -1.0435</pre><img vspace="5" hspace="5" src="LucasPerso_04.png"> <p class="footer"><br>            Published with MATLAB&reg; 7.4<br></p>      </div>      <!--##### SOURCE BEGIN #####% Gaetan Boehringer, Bruno Jacquot & Frédéric Piegay
%% Algorithme de Lucas & Kanade

%% Chargement des images

clear all;
close all;
clc;

% Lecture des images
im1o=double(imread('LKtest3im1.bmp'));
im2o=double(imread('LKtest3im2.bmp'));
[Lim,Cim]=size(im1o);

% Affichage des images
figure;
subplot(1,2,1); imagesc(im1o);axis equal; colormap(gray);title('Image initiale');
subplot(1,2,2); imagesc(im2o);axis equal; colormap(gray); title ('Image décalée');

%% Filtrage

h = fspecial('gaussian',10,3);
im1 = imfilter(im1o,h);
im2 = imfilter(im2o,h);

% Affichage des images filtrées
figure;
subplot(1,2,1); imagesc(im1);axis equal; colormap(gray);title('Image initiale filtrée');
subplot(1,2,2); imagesc(im2);axis equal; colormap(gray);title('Image décalée filtrée');

%% Calcul en 1D
% Affichage d'un profil

% Extraction de la ligne centrale de chacune des images
y1=im1(:,Cim/2)';
y2=im2(:,Cim/2)';
[L,C]=size(y1);

% Affichage
figure;
plot(y1,'b');
hold on;
plot(y2,'m'); title('Affichage du profil de la ligne des 2 images');

grady=zeros(1,C);
ypf=conv(y1,(1/12)*[-1 8 0 -8 1]); % On applique un filtre à cette ligne
grady=ypf(3:C+2); % On supprime le bord

% Gradient temporel et calcul de u (valeur du déplacement selon y)
gradt=y2-y1;
u=gradt*pinv(grady)

%% Calcul 2D

% Calcul des gradients
f=[-1,8,0,-8,1]/12;
im1fx=filter2(f,im1,'same'); % Gradient selon y
im1fy=filter2(f',im1,'same'); % Gradient selon x
imt=im2-im1; % Gradient temporel

% Affichage des gradients
figure;
subplot(1,3,1); imagesc(im1fx);axis equal; colormap(gray);title ('Gradient selon x');
subplot(1,3,2); imagesc(im1fy);axis equal; colormap(gray);title ('Gradient selon y');
subplot(1,3,3); imagesc(imt);axis equal; colormap(gray);title ('Gradient temporel');

% Gestion des bords : suppression du bord  (épaisseur 10 pixels)
bord=10;
Ix1=im1fx(bord:Lim-bord,bord:Lim-bord);
Iy1=im1fy(bord:Lim-bord,bord:Lim-bord);
It=imt(bord:Lim-bord,bord:Lim-bord);

% Transfert vecteurs colonnes
Ix_y=[Ix1(:),Iy1(:)];
It=It(:);

% Calcul de u et v
Ix_yINV=pinv(Ix_y);
fprintf('Lucas Kanade : le déplacement est de (pixels) :\n')
-Ix_yINV*It % Calcul du vecteur déplacement avec l'algorithme de Lucas & Kanade

% Corrélation
fprintf('Interpolation : le déplacement est de (pixels) :\n')
[xmax,ymax]=depnormcorr(im1o,im2o);
dep=[-xmax,-ymax]  % Calcul du vecteur déplacement par la fonction de corrélation


% Avec la méthode de Lucas & Kanade, on obtient des résultats sensiblement
% identiques à ceux obtenus avec la méthode de corrélation.
##### SOURCE END #####-->   </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -