

<?php
include("../../header.php");
?>

<h1 style="text-align:center"> Gaussian Texture Inpainting </br> Tutorial </h1>

<div style="margin-left:auto;margin-right:auto;width:550px">

<p> &emsp; This tutorial can be executed in the Matlab console, provided the archive <a href="../codes/gaussian_inpainting_matlab.zip">gaussian_inpainting_matlab.zip</a> has been extracted in the current path.</p>

<pre class="codeinput">close <span class="string">all</span>
clear <span class="string">all</span>

in = <span class="string">'inpainting_input/'</span>;

rng(3); <span class="comment">% initialize random seed</span>
</pre>

<h2>Load input image<a name="2"></a></h2>
<pre class="codeinput">
name = <span class="string">'wood1008_sq_a_reduced'</span>;
u = im2double(imread([in name <span class="string">'.png'</span>]));
[M,N,C] = size(u);
meanu = mean(mean(u,2));

figure
imshow(u)
title(<span class="string">'Original'</span>)
</pre>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_01.png" alt="">



<h2>Create a mask<a name="3"></a></h2>

<pre class="codeinput">
x1 = 40; y1 = 128;
x2 = 216; y2 = 230;
indm = zeros(M,N,C);
indm(y1:y2,x1:x2,:) = 1;

figure
imshow(indm)
title(<span class="string">'Mask'</span>)
</pre>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_02.png" alt="">



<h2>Compute the Conditioning points on the mask border<a name="4"></a></h2>

<pre class="codeinput">indc = get_conditioning_points(indm,3);
  
figure
imshow(double(indc))
title(<span class="string">'Conditioning points'</span>)
</pre>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_03.png" alt=""> <h2>Estimate a Gaussian model outside the mask<a name="5"></a></h2>

<pre class="codeinput">
xo1 = 1; yo1 = 1;
xo2 = N; yo2 = y1-1;
[t,m] = estimate_adsn_model(u(yo1:yo2,xo1:xo2,:),M,N);
uw = draw_rectangle(u,xo1,xo2,yo1,yo2,2);

figure
imshow(uw.*(1-indm))
title(sprintf(<span class="string">'Masked original. ADSN model estimated in the red box'</span>))
</pre>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_04.png" alt="">



<h2>Check the texture model<a name="6"></a></h2>

<pre class="codeinput">
z = adsn_periodic(t,repmat(m,[M N 1]));
  
figure
imshow(z)
title(<span class="string">'Realization of the ADSN model'</span>)
</pre>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_05.png" alt="">




<h2>Inpaint by Gaussian conditional simulation<a name="7"></a></h2>

<pre class="codeinput">
[v,kc,innov] = kriging_inpainting(u.*(1-indm),m,t,indm,indc);

figure
imshow(u.*(1-indm));
title(<span class="string">'Masked texture'</span>)
drawnow

figure
imshow(v);
title(<span class="string">'Inpainted'</span>)
drawnow

figure
imshow(kc);
title(<span class="string">'Kriging component'</span>)
drawnow

figure
imshow(innov);
title(<span class="string">'Innovation component'</span>)
drawnow
</pre>

<pre class="codeoutput">Time to solve the linear system of size 5148 x 5148: 1.727
</pre>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_06.png" alt=""><br/>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_07.png" alt=""><br/>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_08.png" alt=""><br/>

<img vspace="5" hspace="5" src="tuto_gaussian_inpainting_09.png" alt=""><br/>

</div>

<?php
include("../../bottom.php");
?>
  
