Auswertung Experiment

Database tüddelei
DBHanlder läuft gut für DIESE Datanbank struktur...
App begonnen aber weit entfernt von gutem Stand
This commit is contained in:
sioe
2024-11-15 16:51:37 +01:00
parent 553ed19b9f
commit 397cfa61dd
219 changed files with 584 additions and 854 deletions

View File

@@ -0,0 +1,37 @@
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

View File

@@ -0,0 +1,161 @@
<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>inpaint_nans_demo</title>
<meta name="generator" content="MATLAB 7.0.1">
<meta name="date" content="2006-06-28">
<meta name="m-file" content="inpaint_nans_demo"><style>
body {
background-color: white;
margin:10px;
}
h1 {
color: #990000;
font-size: x-large;
}
h2 {
color: #990000;
font-size: medium;
}
p.footer {
text-align: right;
font-size: xx-small;
font-weight: lighter;
font-style: italic;
color: gray;
}
pre.codeinput {
margin-left: 30px;
}
span.keyword {color: #0000FF}
span.comment {color: #228B22}
span.string {color: #A020F0}
span.untermstring {color: #B20000}
span.syscmd {color: #B28C00}
pre.showbuttons {
margin-left: 30px;
border: solid black 2px;
padding: 4px;
background: #EBEFF3;
}
pre.codeoutput {
color: gray;
font-style: italic;
}
pre.error {
color: red;
}
/* Make the text shrink to fit narrow windows, but not stretch too far in
wide windows. On Gecko-based browsers, the shrink-to-fit doesn't work. */
p,h1,h2,div {
/* for MATLAB's browser */
width: 600px;
/* for Mozilla, but the "width" tag overrides it anyway */
max-width: 600px;
/* for IE */
width:expression(document.body.clientWidth > 620 ? "600px": "auto" );
}
</style></head>
<body><pre class="codeinput"><span class="comment">% Surface fit artifact removal</span>
[x,y] = meshgrid(0:.01:1);
z0 = exp(x+y);
znan = z0;
znan(20:50,40:70) = NaN;
znan(30:90,5:10) = NaN;
znan(70:75,40:90) = NaN;
z = inpaint_nans(znan,3);
<span class="comment">% Comparison to griddata</span>
k = isnan(znan);
zk = griddata(x(~k),y(~k),z(~k),x(k),y(k));
zg = znan;
zg(k) = zk;
close <span class="string">all</span>
figure
surf(z0)
title <span class="string">'Original surface'</span>
figure
surf(znan)
title <span class="string">'Artifacts (large holes) in surface'</span>
figure
surf(zg)
title([<span class="string">'Griddata inpainting ('</span>,num2str(sum(isnan(zg(:)))),<span class="string">' NaNs remain)'</span>])
figure
surf(z)
title <span class="string">'Inpainted surface'</span>
figure
surf(zg-z0)
title <span class="string">'Griddata error surface'</span>
figure
surf(z-z0)
title <span class="string">'Inpainting error surface (Note z-axis scale)'</span>
</pre><img vspace="5" hspace="5" src="inpaint_nans_demo_01.png"> <img vspace="5" hspace="5" src="inpaint_nans_demo_02.png"> <img vspace="5" hspace="5" src="inpaint_nans_demo_03.png"> <img vspace="5" hspace="5" src="inpaint_nans_demo_04.png"> <img vspace="5" hspace="5" src="inpaint_nans_demo_05.png"> <img vspace="5" hspace="5" src="inpaint_nans_demo_06.png"> <p class="footer"><br>
Published with MATLAB&reg; 7.0.1<br></p>
<!--
##### SOURCE BEGIN #####
% Surface fit artifact removal
[x,y] = meshgrid(0:.01:1);
z0 = exp(x+y);
znan = z0;
znan(20:50,40:70) = NaN;
znan(30:90,5:10) = NaN;
znan(70:75,40:90) = NaN;
z = inpaint_nans(znan,3);
% Comparison to griddata
k = isnan(znan);
zk = griddata(x(~k),y(~k),z(~k),x(k),y(k));
zg = znan;
zg(k) = zk;
close all
figure
surf(z0)
title 'Original surface'
figure
surf(znan)
title 'Artifacts (large holes) in surface'
figure
surf(zg)
title(['Griddata inpainting (',num2str(sum(isnan(zg(:)))),' NaNs remain)'])
figure
surf(z)
title 'Inpainted surface'
figure
surf(zg-z0)
title 'Griddata error surface'
figure
surf(z-z0)
title 'Inpainting error surface (Note z-axis scale)'
##### SOURCE END #####
-->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,42 @@
% Surface fit artifact removal
[x,y] = meshgrid(0:.01:1);
z0 = exp(x+y);
znan = z0;
znan(20:50,40:70) = NaN;
znan(30:90,5:10) = NaN;
znan(70:75,40:90) = NaN;
z = inpaint_nans(znan,3);
% Comparison to griddata
k = isnan(znan);
zk = griddata(x(~k),y(~k),z(~k),x(k),y(k));
zg = znan;
zg(k) = zk;
close all
figure
surf(z0)
title 'Original surface'
figure
surf(znan)
title 'Artifacts (large holes) in surface'
figure
surf(zg)
title(['Griddata inpainting (',num2str(sum(isnan(zg(:)))),' NaNs remain)'])
figure
surf(z)
title 'Inpainted surface'
figure
surf(zg-z0)
title 'Griddata error surface'
figure
surf(z-z0)
title 'Inpainting error surface (Note z-axis scale)'

View File

@@ -0,0 +1,39 @@
{\rtf1\mac\ansicpg10000\cocoartf102
{\fonttbl\f0\fswiss\fcharset77 Helvetica;}
{\colortbl;\red255\green255\blue255;}
\margl1440\margr1440\vieww10780\viewh13720\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural
\f0\fs24 \cf0 Nomination comments:\
\
Inpaint_nans fills a hole in matlab. (Yes, the pun was intentional.) But there\
is indeed a niche that inpaint_nans falls into.\
\
The alternative to inpaint_nans is griddata (interp1 can be used for the 1-d \
problems) but griddata fails to extrapolate well. Griddata also has serious\
problems when its data already lies on a grid, due to its use of a Delaunay \
triangulation. The other serious problem with the use of griddata is the\
triangulation itself. The shape of the hole to be filled can sometimes result\
in triangles with a poor aspect ratio (long, thin triangles) which are in turn\
poor for interpolation. In fact, Griddata can even leave interior points\
uninterpolated (see the tests.)\
\
A future plan for inpaint_nans is to add an option that will use a locally\
anisotropic membrane model. This will allow better modeling for certain\
classes of wavy surfaces. I'm also highly tempted to remove method 5.\
I've never really liked it, having put it in at the request of one user. It has\
no valid theory behind it in the context of inpaint_nans.\
\
In the interest of openness, I'll also say what inpaint_nans does not do. It\
does not handle non-uniform grids. It is limited by the amount of memory \
in the size of the arrays it can handle, although some of the methods were\
explicitly provided to be more memory efficient than others. Inpaint_nans\
also makes heavy use of sparse matrices, so surprisingly large problems\
are accessible.\
\
Finally, while inpaint_nans does work for 1-d problems, they are not my\
target. Interp1 (with 'spline' as the method) is as accurate, and should be\
faster in general.\
\
John\
}

View File

@@ -0,0 +1,187 @@
%{
The methods of inpaint_nans
Digital inpainting is the craft of replacing missing elements in an
"image" array. A Google search on the words "digita inpainting" will turn
up many hits. I just tried this search and found 18300 hits.
If you wish to do inpainting in matlab, one place to start is with my
inpaint_nans code. Inpaint_nans is on the file exchange:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4551&objectType=file
It looks for NaN elements in an array (or vector) and attempts to interpolate
(or extrapolate) smoothly to replace those elements.
The name "inpainting" itself comes from the world of art restoration.
Damaged paintings are restored by an artist/craftsman skilled in matching
the style of the original artist to fill in any holes in the painting.
In digital inpainting, the goal is to interpolate in from the boundaries
of a hole to smoothly replace an artifact. Obviously, where the hole is
large the digitally inpainted repair may not be an accurate approximation
to the original.
Inpaint_nans itself is really only a boundary value solver. The basic idea
is to formulate a partial differential equation (PDE) that is assumed to
apply in the domain of the artifact to be inpainted. The perimeter of the
hole supplies boundary values for the PDE. Then the PDE is approximated
using finite difference methods (the array elements are assumed to be
equally spaced in each dimension) and then a large (and very sparse) linear
system of equations is solved for the NaN elements in the array.
I've chosen a variety of simple differental equation models the user can
specify to be solved. All the methods current use a basically elliptic
PDE. This means that the resulting linear system will generally be well
conditioned. It does mean that the solution will generally be fairly smooth,
and over large holes, it will tend towards an average of the boundary
elements. These are characteristics of the elliptic PDEs chosen. (My hope
is to expand these options in the future.)
%}
%%
% Lets formulate a simple problem, and see how we could solve it using
% some of these ideas.
A = [0 0 0 0;1 NaN NaN 4;2 3 5 8];
% Although we can't plot this matrix using the functions surf or mesh,
% surely we can visualize what the fudamental shape is.
% There are only two unknown elements, the artifacts that inpaint_nans
% would fill in: A(2,2) and A(2,3).
% For an equally spaced grid, the Laplacian equation (or Poisson's equation
% of heat conduction at steady state if you prefer. Or, for the fickle,
% Ficke's law of diffusion would apply.) All of these result in the PDE
%
% u_xx + u_yy = 0
%
% where u_xx is the second partial derivative of u with respect to x,
% and u_yy is the second partial with respect to y.
%
% Approximating this PDE using finite differences for the partial
% derivatives, implies that at any node in the grid, we could replace
% it by the average of its 4 neighbors. Thus the two NaN elements
% generate two linear equations:
%
% A(2,2) = (A(1,2) + A(3,2) + A(2,1) + A(2,3)) / 4
% A(2,3) = (A(1,3) + A(3,3) + A(2,2) + A(2,4)) / 4
%
% Since we know all the parameters but A(2,2) and A(2,3), substitute their
% known values.
%
% A(2,2) = (0 + 3 + 1 + A(2,3)) / 4
% A(2,3) = (0 + 5 + A(2,2) + 4) / 4
%
% Or,
%
% 4*A(2,2) - A(2,3) = 4
% -A(2,2) + 4*A(2,3) = 9
%
% We can solve for the unkowns now using
u = [4 -1;-1 4]\[4;9]
A(2,2) = u(1);
A(2,3) = u(2);
% and finally plot the surface
close
surf(A)
title 'A simply inpainted surface'
% Neat huh? For an arbitrary number of NaN elements in an array,
% the above scheme is all there is to method 2 of inpaint_nans,
% together with a very slick application of sparse linear algebra
% in Matlab.
% Method 0 is very similar, but I've optimized it to build as
% small a linear system as possible for those cases where an array
% has only a few NaN elements.
% Method 1 is another subtle variation on this scheme, but it
% tries to be slightly smoother at some cost of efficiency, while
% still not modifying the known (non-NaN) elements of the array.
% Method 5 of inpaint_nans is also very similar to method 2, except
% that it uses a simple average of all 8 neighbors of an element.
% Its not actually an approximation to our PDE.
% Method 3 is yet another variation on this theme, except the PDE
% model used is one more suited to a model of a thin plate than for
% heat diffusion. Here the governing PDE is:
%
% u_xxxx + 2*u_xxyy + u_yyyy = 0
%
% again discretized into a linear system of equations.
%%
% Finally, method 4 of inpaint_nans has a different underlying
% model. Pretend that each element in the array was connected to
% its immediate neighbors to the left, right, up, and down by
% "springs". They are also connected to their neighbors at 45
% degree angles by springs with a weaker spring constant. Since
% the potential energy stored in a spring is proportional to its
% extension, we can formulate this again as a linear system of
% equations to be solved. For the example above, we would generate
% the set of equations:
% A(2,2) - A(1,2) = 0
% A(2,2) - A(2,1) = 0
% A(2,2) - A(3,2) = 0
% A(2,2) - A(2,3) = 0
% (A(2,2) - A(1,1))/sqrt(2) = 0
% (A(2,2) - A(1,3))/sqrt(2) = 0
% (A(2,2) - A(3,1))/sqrt(2) = 0
% (A(2,2) - A(3,3))/sqrt(2) = 0
% A(2,3) - A(1,3) = 0
% A(2,3) - A(2,2) = 0
% A(2,3) - A(3,3) = 0
% A(2,3) - A(2,4) = 0
% (A(2,3) - A(1,2))/sqrt(2) = 0
% (A(2,3) - A(1,4))/sqrt(2) = 0
% (A(2,3) - A(3,2))/sqrt(2) = 0
% (A(2,3) - A(3,4))/sqrt(2) = 0
% Substitute for the known elements to get
% A(2,2) - 0 = 0
% A(2,2) - 1 = 0
% A(2,2) - 3 = 0
% A(2,2) - A(2,3) = 0
% (A(2,2) - 0)/sqrt(2) = 0
% (A(2,2) - 0)/sqrt(2) = 0
% (A(2,2) - 2)/sqrt(2) = 0
% (A(2,2) - 5)/sqrt(2) = 0
% A(2,3) - 0 = 0
% A(2,3) - A(2,2) = 0
% A(2,3) - 5 = 0
% A(2,3) - 4 = 0
% (A(2,3) - 0)/sqrt(2) = 0
% (A(2,3) - 0)/sqrt(2) = 0
% (A(2,3) - 3)/sqrt(2) = 0
% (A(2,3) - 8)/sqrt(2) = 0
% This system is also solvable now:
r2 = 1/sqrt(2);
M=[1 0;1 0;1 0;1 -1;r2 0;r2 0;r2 0;r2 0;0 1;-1 1;0 1;0 1;0 r2;0 r2;0 r2;0 r2];
v = M\[0 1 3 0 0 0 2*r2 5*r2 0 0 5 4 0 0 3*r2 8*r2]'
A(2,2) = v(1);
A(2,3) = v(2);
% and finally plot the surface
surf(A)
title 'A simply inpainted surface using a spring model'
%%
% Why did I provide this approach, based on a spring metaphor?
% As you should have observed, methods 2 and 4 are really quite close
% in what they do for internal NaN elements. Its on the perimeter that
% they differ significantly. The diffusion/Laplacian model will
% extrapolate smoothly, and as linearly as possible. The spring model
% will tend to extrapolate as a constant function.

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,43 @@
%% Surface Fit Artifact Removal
%% Construct the Surface
[x,y] = meshgrid(0:.01:1);
z0 = exp(x+y);
close all
figure
surf(z0)
title 'Original surface'
znan = z0;
znan(20:50,40:70) = NaN;
znan(30:90,5:10) = NaN;
znan(70:75,40:90) = NaN;
figure
surf(znan)
title 'Artifacts (large holes) in surface'
%% In-paint Over NaNs
z = inpaint_nans(znan,3);
figure
surf(z)
title 'Inpainted surface'
figure
surf(z-z0)
title 'Inpainting error surface (Note z-axis scale)'
%% Comapre to GRIDDATA
k = isnan(znan);
zk = griddata(x(~k),y(~k),z(~k),x(k),y(k));
zg = znan;
zg(k) = zk;
figure
surf(zg)
title(['Griddata inpainting (',num2str(sum(isnan(zg(:)))),' NaNs remain)'])
figure
surf(zg-z0)
title 'Griddata error surface'

View File

@@ -0,0 +1,24 @@
Copyright (c) 2009, John D'Errico
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

View File

@@ -0,0 +1,178 @@
%% Repair to an image with 50% random artifacts
% Garden at Sainte-Adresse (Monet, 1867)
garden = imread('monet_adresse.jpg');
G = double(garden);
G(rand(size(G))<0.50) = NaN;
Gnan = G;
G(:,:,1) = inpaint_nans(G(:,:,1),2);
G(:,:,2) = inpaint_nans(G(:,:,2),2);
G(:,:,3) = inpaint_nans(G(:,:,3),2);
figure
subplot(1,3,1)
image(garden)
title 'Garden at Sainte-Adresse (Monet)'
subplot(1,3,2)
image(uint8(Gnan))
title 'Corrupted - 50%'
subplot(1,3,3)
image(uint8(G))
title 'Inpainted Garden'
%% Surface fit artifact removal
[x,y] = meshgrid(0:.01:1);
z0 = exp(x+y);
znan = z0;
znan(20:50,40:70) = NaN;
znan(30:90,5:10) = NaN;
znan(70:75,40:90) = NaN;
tic,z = inpaint_nans(znan,3);toc
tic
k = isnan(znan);
zk = griddata(x(~k),y(~k),z(~k),x(k),y(k));
zg = znan;
zg(k) = zk;
toc
figure
surf(z0)
title 'Original surface'
figure
surf(znan)
title 'Artifacts (large holes) in surface'
figure
surf(zg)
title(['Griddata inpainting (',num2str(sum(isnan(zg(:)))),' NaNs remain)'])
figure
surf(z)
title 'Inpainted surface'
figure
surf(zg-z0)
title 'Griddata error surface'
figure
surf(z-z0)
title 'Inpainting error surface (Note z-axis scale)'
%% Comparison of methods
[x,y] = meshgrid(-1:.02:1);
r = sqrt(x.^2 + y.^2);
z = exp(-(x.^2+ y.^2));
z(r>=0.9) = NaN;
z((r<=.5) & (x<0)) = NaN;
figure
pcolor(z);
title 'Surface provided to inpaint_nans'
% Method 0
tic,z0 = inpaint_nans(z,0);toc
% Method 1
tic,z1 = inpaint_nans(z,1);toc
% Method 2
tic,z2 = inpaint_nans(z,2);toc
% Method 3
tic,z3 = inpaint_nans(z,3);toc
% Method 4
tic,z4 = inpaint_nans(z,4);toc
% Method 5
tic,z5 = inpaint_nans(z,5);toc
figure
surf(z0)
colormap copper
hold on
h = surf(z);
set(h,'facecolor','r')
hold off
title 'Method 0 (Red was provided)'
figure
surf(z1)
hold on
h = surf(z);
set(h,'facecolor','r')
hold off
title 'Method 1 (Red was provided)'
figure
surf(z2)
hold on
h = surf(z);
set(h,'facecolor','r')
hold off
title 'Method 2 (Red was provided) - least accurate, but fastest'
figure
surf(z3)
hold on
h = surf(z);
set(h,'facecolor','r')
hold off
title 'Method 3 (Red was provided) - Slow, but accurate'
figure
surf(z4)
hold on
h = surf(z);
set(h,'facecolor','r')
hold off
title 'Method 4 (Red was provided) - designed for constant extrapolation!'
figure
h = surf(z5);
set(h,'facecolor','y')
hold on
h = surf(z);
set(h,'facecolor','r')
hold off
title 'Method 5 (Red was provided)'
%% 1-d "inpainting" using interp1
x = linspace(0,3*pi,100);
y0 = sin(x);
y = y0;
% Drop out 2/3 of the data
y(1:3:end) = NaN;
y(2:3:end) = NaN;
% inpaint_nans
y_inpaint = inpaint_nans(y,1);
% interpolate using interp1
k = isnan(y);
y_interp1c = y;
y_interp1s = y;
y_interp1c(k) = interp1(x(~k),y(~k),x(k),'cubic');
y_interp1s(k) = interp1(x(~k),y(~k),x(k),'spline');
figure
plot(x,y,'ro',x,y_inpaint,'b+')
legend('sin(x), missing 2/3 points','inpaint-nans','Location','North')
figure
plot(x,y0-y_inpaint,'r-',x,y0-y_interp1c,'b--',x,y0-y_interp1s,'g--')
title 'Inpainting residuals'
legend('Inpaint-nans','Pchip','Spline','Location','North')