📄 index.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>Introduction to Image Processing</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>Introduction to Image Processing</h1> <introduction> <p>This numerical tour explores some basic image processing tasks.</p> </introduction> <h2>Contents</h2> <div> <ul> <li><a href="#1">Installing toolboxes and setting up the path.</a></li> <li><a href="#8">Image Loading and Displaying</a></li> <li><a href="#11">Image Modification</a></li> <li><a href="#15">Fourier Transform</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>Image Loading and Displaying<a name="8"></a></h2> <p>Several functions are implemented to load and display images.</p> <p>First we load an image.</p><pre class="codeinput"><span class="comment">% path to the images</span>name = <span class="string">'lena'</span>;n = 256;M = load_image(name, []);M = rescale(crop(M,n));</pre><p>We can display it. It is possible to zoom on it, extract pixels, etc.</p><pre class="codeinput">clf;imageplot(M, <span class="string">'Original'</span>, 1,2,1);imageplot(crop(M,50), <span class="string">'Zoom'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_01.png"> <h2>Image Modification<a name="11"></a></h2> <p>An image is a 2D array, that can be modified as a matrix.</p><pre class="codeinput">clf;imageplot(-M, <span class="string">'-M'</span>, 1,2,1);imageplot(M(n:-1:1,:), <span class="string">'Flipped'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_02.png"> <p>Blurring is achieved by computing a convolution with a kernel.</p><pre class="codeinput"><span class="comment">% compute the low pass kernel</span>k = 9;h = ones(k,k);h = h/sum(h(:));<span class="comment">% compute the convolution</span>Mh = perform_convolution(M,h);<span class="comment">% display</span>clf;imageplot(M, <span class="string">'Image'</span>, 1,2,1);imageplot(Mh, <span class="string">'Blurred'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_03.png"> <p>Several differential and convolution operators are implemented.</p><pre class="codeinput">G = grad(M);clf;imageplot(G(:,:,1), <span class="string">'d/dx'</span>, 1,2,1);imageplot(G(:,:,2), <span class="string">'d/dy'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_04.png"> <h2>Fourier Transform<a name="15"></a></h2> <p>The 2D Fourier transform can be used to perform low pass approximation and interpolation (by zero padding).</p> <p>Compute and display the Fourier transform (display over a log scale). The function <tt>fftshift</tt> is useful to put the 0 low frequency in the middle. After <tt>fftshift</tt>, the zero frequency is located at position (n/2+1,n/2+1). </p><pre class="codeinput">Mf = fft2(M);Lf = fftshift(log( abs(Mf)+1e-1 ));clf;imageplot(M, <span class="string">'Image'</span>, 1,2,1);imageplot(Lf, <span class="string">'Fourier transform'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_05.png"> <p><i>Exercice 1:</i> (the solution is <a href="../private/image_introduction/exo1.m">exo1.m</a>) To avoid boundary artifacte and estimate really the frequency content of the image (and not of the artifacts!), one needs to multiply <tt>M</tt> by a smooth windowing function <tt>h</tt> and compute <tt>fft2(M.*h)</tt>. Use a sine windowing function. Can you interpret the resulting filter ? </p><pre class="codeinput">exo1;</pre><img vspace="5" hspace="5" src="index_06.png"> <p><i>Exercice 2:</i> (the solution is <a href="../private/image_introduction/exo2.m">exo2.m</a>) Perform low pass filtering by removing the high frequencies of the spetrcum. What do you oberve ? </p><pre class="codeinput">exo2;</pre><img vspace="5" hspace="5" src="index_07.png"> <p>It is possible to do image interpolating by adding high frequencies</p><pre class="codeinput">p = 64;n = p*4;M = load_image(<span class="string">'boat'</span>, 2*p); M = crop(M,p);Mf = fftshift(fft2(M));MF = zeros(n,n);sel = n/2-p/2+1:n/2+p/2;sel = sel;MF(sel, sel) = Mf;MF = fftshift(MF);Mpad = real(ifft2(MF));clf;imageplot( crop(M), <span class="string">'Image'</span>, 1,2,1);imageplot( crop(Mpad), <span class="string">'Interpolated'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_08.png"> <p>A better way to do interpolation is to use cubic-splines. It avoid ringing artifact because the spline kernel has a smaller support with less oscillations. </p><pre class="codeinput">Mspline = image_resize(M,n,n);clf;imageplot( crop(Mpad), <span class="string">'Fourier (sinc)'</span>, 1,2,1);imageplot( crop(Mspline), <span class="string">'Spline'</span>, 1,2,2);</pre><img vspace="5" hspace="5" src="index_09.png"> <p class="footer"><br> Copyright ® 2008 Gabriel Peyre<br></p> </div> <!--##### SOURCE BEGIN #####%% Introduction to Image Processing% This numerical tour explores some basic image processing tasks.%% 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/');%% Image Loading and Displaying% Several functions are implemented to load and display images.%%% First we load an image.% path to the imagesname = 'lena';n = 256;M = load_image(name, []);M = rescale(crop(M,n));%%% We can display it. It is possible to zoom on it, extract pixels, etc.clf;imageplot(M, 'Original', 1,2,1);imageplot(crop(M,50), 'Zoom', 1,2,2);%% Image Modification%%% An image is a 2D array, that can be modified as a matrix.clf;imageplot(-M, '-M', 1,2,1);imageplot(M(n:-1:1,:), 'Flipped', 1,2,2);%%% Blurring is achieved by computing a convolution with a kernel.% compute the low pass kernelk = 9;h = ones(k,k);h = h/sum(h(:));% compute the convolutionMh = perform_convolution(M,h);% displayclf;imageplot(M, 'Image', 1,2,1);imageplot(Mh, 'Blurred', 1,2,2);%%% Several differential and convolution operators are implemented.G = grad(M);clf;imageplot(G(:,:,1), 'd/dx', 1,2,1);imageplot(G(:,:,2), 'd/dy', 1,2,2);%% Fourier Transform% The 2D Fourier transform can be used to perform low pass approximation% and interpolation (by zero padding).%%% Compute and display the Fourier transform (display over a log scale).% The function |fftshift| is useful to put the 0 low frequency in the% middle. After |fftshift|, the zero frequency is located at position% (n/2+1,n/2+1).Mf = fft2(M);Lf = fftshift(log( abs(Mf)+1e-1 ));clf;imageplot(M, 'Image', 1,2,1);imageplot(Lf, 'Fourier transform', 1,2,2);%%% _Exercice 1:_ (the solution is <../private/image_introduction/exo1.m exo1.m>)% To avoid boundary artifacte and estimate really the frequency content of% the image (and not of the artifacts!), one needs to multiply |M| by a% smooth windowing function |h| and compute |fft2(M.*h)|. Use a sine% windowing function. Can you interpret the resulting filter ?exo1;%%% _Exercice 2:_ (the solution is <../private/image_introduction/exo2.m exo2.m>)% Perform low pass filtering by removing the high frequencies of the% spetrcum. What do you oberve ?exo2;%%% It is possible to do image interpolating by adding high frequenciesp = 64;n = p*4;M = load_image('boat', 2*p); M = crop(M,p);Mf = fftshift(fft2(M));MF = zeros(n,n);sel = n/2-p/2+1:n/2+p/2;sel = sel;MF(sel, sel) = Mf;MF = fftshift(MF);Mpad = real(ifft2(MF));clf;imageplot( crop(M), 'Image', 1,2,1);imageplot( crop(Mpad), 'Interpolated', 1,2,2);%%% A better way to do interpolation is to use cubic-splines.% It avoid ringing artifact because the spline kernel has a smaller support% with less oscillations.Mspline = image_resize(M,n,n);clf;imageplot( crop(Mpad), 'Fourier (sinc)', 1,2,1);imageplot( crop(Mspline), 'Spline', 1,2,2);##### SOURCE END #####--> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -