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

📄 index.html

📁 信号处理系列导航
💻 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>Edge Detection and Heat Diffusion</title>      <meta name="generator" content="MATLAB 7.4">      <meta name="date" content="2008-10-15">      <meta name="m-file" content="index">      <LINK REL="stylesheet" HREF="style.css" TYPE="text/css">   </head>   <body>      <div class="content">         <h1>Edge Detection and Heat Diffusion</h1>         <introduction>            <p>This numerical tour explores local differential operator and their use to perform edge detection and heat diffusion.</p>         </introduction>         <h2>Contents</h2>         <div>            <ul>               <li><a href="#1">Installing toolboxes and setting up the path.</a></li>               <li><a href="#8">Gradient, Laplacian and Edge Detection</a></li>               <li><a href="#14">Heat Diffusion and Blurring</a></li>            </ul>         </div>         <h2>Installing toolboxes and setting up the path.<a name="1"></a></h2>         <p>You need to download the <a href="../toolbox_general.zip">general purpose toolbox</a> and the <a href="../toolbox_signal.zip">signal toolbox</a>.         </p>         <p>You need to unzip these toolboxes in your working directory, so that you have <tt>toolbox_general/</tt> and <tt>toolbox_signal/</tt> in your directory.         </p>         <p><b>For Scilab user:</b> you must replace the Matlab comment '%' by its Scilab counterpart '//'.         </p>         <p><b>Recommandation:</b> You should create a text file named for instance <tt>numericaltour.sce</tt> (in Scilabe) or <tt>numericaltour.m</tt> to write all the Scilab/Matlab command you want to execute. Then, simply run <tt>exec('numericaltour.sce');</tt> (in Scilab) or <tt>numericaltour;</tt> (in Matlab) to run the commands.         </p>         <p>Execute this line only if you are using Matlab.</p><pre class="codeinput">getd = @(p)path(path,p); <span class="comment">% scilab users must *not* execute this</span></pre><p>Then you can add these toolboxes to the path.</p><pre class="codeinput"><span class="comment">% Add some directories to the path</span>getd(<span class="string">'toolbox_signal/'</span>);getd(<span class="string">'toolbox_general/'</span>);</pre><h2>Gradient, Laplacian and Edge Detection<a name="8"></a></h2>         <p>Local differential operators like gradient, divergence and laplacian are the building blocks for variational image processing            using PDEs.         </p>         <p>Load an image</p><pre class="codeinput">n = 256;M = load_image(<span class="string">'boat'</span>,n);</pre><p>You can compute the gradient of an image with <tt>grad</tt> and the divergence of a vector field with <tt>div</tt>. The divergence of the gradient is the Laplacian of the image.         </p><pre class="codeinput"><span class="comment">% gradient</span>G = grad(M);<span class="comment">% magnitude</span>d = sqrt( sum(G.^2,3) );<span class="comment">% laplacian</span>L = div(G);<span class="comment">% display</span>clf;imageplot(d, <span class="string">'Gradient magnitude'</span>, 1,2,1);imageplot(L, <span class="string">'Laplacian'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_01.png"> <p>A very simple edge detector is obtained by simply thresholding the gradient magnitude.</p><pre class="codeinput">clf;imageplot( d&gt;max(d(:))/10, <span class="string">'High threshold'</span>, 1,2,1);imageplot( d&gt;max(d(:))/5, <span class="string">'Low threshold'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_02.png"> <p>The zero crossing of the Laplacian is a well known edge detector. This requires first blurring the image (which is equivalent            to blurring the laplacian). It can be shown, however, that this operator will also return false edges corresponding to local            minima of the gradient magnitude. Moreover, this operator will give poor localization at curved edges.         </p><pre class="codeinput"><span class="comment">% compute the laplacian</span>sigma = 6;Lh = perform_blurring(L, sigma);<span class="comment">% display the level sets</span>clf;plot_levelset(Lh,0,M);</pre><img vspace="5" hspace="5" src="index_03.png"> <p><i>Exercice 1:</i> (the solution is <a href="../private/image_heat/exo1.m">exo1.m</a>) A much better edge detector are the zero-crossings of the second-order directional derivative in the gradient direction.            Compute the Hessian matrix of second derivative (it will be an <tt>n x n x 3</tt> matrix containing d^2/dx^2, d^2/dy^2, d^2/dxdy. The compute the directional derivative in the direction of the gradient,            and display its zero crossing. Warning: the image needs to be blurred before the computation.         </p><pre class="codeinput">exo1;</pre><img vspace="5" hspace="5" src="index_04.png"> <h2>Heat Diffusion and Blurring<a name="14"></a></h2>         <p>Before detailing non-linear total variation, we come back to basics and tries linear diffusion, which corresponds to the heat            equation. A heat diffusion for a time <tt>T</tt> is equivalent to a Gaussian blurring with a filter of variance proportional to <tt>T^2</tt>. It thus mostly destroy the edges in the image.         </p>         <p>The gradient of the square norme of the gradient is minus the Laplacian.</p><pre class="codeinput">G = div(grad(M));</pre><p><i>Exercice 2:</i> (the solution is <a href="../private/image_heat/exo2.m">exo2.m</a>) Compute a Heat diffusion flow by performing a gradient descent of the square norme of the gradient. You can use a step size            <tt>tau=.05</tt> for instance (it needs to be small enough) and the number of iterations is <tt>niter=T/tau</tt>, where <tt>T</tt> is the final time of the flow (should be like 10).         </p><pre class="codeinput">exo2;</pre><img vspace="5" hspace="5" src="index_05.png"> <p class="footer"><br>            Copyright  &reg; 2008 Gabriel Peyre<br></p>      </div>      <!--##### SOURCE BEGIN #####%% Edge Detection and Heat Diffusion% This numerical tour explores local differential operator and their use to% perform edge detection and heat diffusion.%% Installing toolboxes and setting up the path.%%% You need to download the % <../toolbox_general.zip general purpose toolbox>% and the <../toolbox_signal.zip signal toolbox>.%%% You need to unzip these toolboxes in your working directory, so% that you have |toolbox_general/| and |toolbox_signal/| in your% directory.%%% *For Scilab user:* you must replace the Matlab comment '%' by its Scilab% counterpart '//'.%%% *Recommandation:* You should create a text file named for instance% |numericaltour.sce| (in Scilabe) or |numericaltour.m| to write all the% Scilab/Matlab command you want to execute. Then, simply run% |exec('numericaltour.sce');| (in Scilab) or |numericaltour;| (in Matlab)% to run the commands. %%% Execute this line only if you are using Matlab.getd = @(p)path(path,p); % scilab users must *not* execute this%%% Then you can add these toolboxes to the path.% Add some directories to the pathgetd('toolbox_signal/');getd('toolbox_general/');%% Gradient, Laplacian and Edge Detection% Local differential operators like gradient, divergence and laplacian are% the building blocks for variational image processing using PDEs.%%% Load an imagen = 256;M = load_image('boat',n);%%% You can compute the gradient of an image with |grad| and the divergence% of a vector field with |div|. The divergence of the gradient is the% Laplacian of the image.% gradientG = grad(M);% magnituded = sqrt( sum(G.^2,3) );% laplacianL = div(G);% displayclf;imageplot(d, 'Gradient magnitude', 1,2,1);imageplot(L, 'Laplacian', 1,2,2);%%% A very simple edge detector is obtained by simply thresholding the% gradient magnitude.clf;imageplot( d>max(d(:))/10, 'High threshold', 1,2,1);imageplot( d>max(d(:))/5, 'Low threshold', 1,2,2);%%% The zero crossing of the Laplacian is a well known edge detector.% This requires first blurring the image (which is equivalent to blurring% the laplacian). It can be shown, however, that this operator will also% return false edges corresponding to local minima % of the gradient magnitude. Moreover, this operator will give poor localization at curved edges.% compute the laplaciansigma = 6;Lh = perform_blurring(L, sigma);% display the level setsclf;plot_levelset(Lh,0,M);%%% _Exercice 1:_ (the solution is <../private/image_heat/exo1.m exo1.m>)% A much better edge detector are the zero-crossings of the second-order% directional derivative in the gradient direction. Compute the Hessian% matrix of second derivative (it will be an |n x n x 3| matrix containing% d^2/dx^2, d^2/dy^2, d^2/dxdy. The compute the directional derivative in% the direction of the gradient, and display its zero crossing. Warning:% the image needs to be blurred before the computation.exo1;%% Heat Diffusion and Blurring% Before detailing non-linear total variation, we come back to basics and% tries linear diffusion, which corresponds to the heat equation. A heat% diffusion for a time |T| is equivalent to a Gaussian blurring with a% filter of variance proportional to |T^2|. It thus mostly destroy the% edges in the image.%%% The gradient of the square norme of the gradient is minus the Laplacian.G = div(grad(M));%%% _Exercice 2:_ (the solution is <../private/image_heat/exo2.m exo2.m>)% Compute a Heat diffusion flow by performing a gradient descent of the square norme of the gradient.% You can use a step size |tau=.05| for instance (it needs to be small% enough) and the number of iterations is |niter=T/tau|, where |T| is the% final time of the flow (should be like 10).exo2;##### SOURCE END #####-->   </body></html>

⌨️ 快捷键说明

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