<s>
A	O
demosaicing	B-Algorithm
(	O
also	O
de-mosaicing	B-Algorithm
,	O
demosaicking	B-Algorithm
or	O
debayering	B-Algorithm
)	O
algorithm	O
is	O
a	O
digital	B-Algorithm
image	I-Algorithm
process	I-Algorithm
used	O
to	O
reconstruct	O
a	O
full	O
color	O
image	O
from	O
the	O
incomplete	O
color	O
samples	O
output	O
from	O
an	O
image	B-Algorithm
sensor	I-Algorithm
overlaid	O
with	O
a	O
color	B-Algorithm
filter	I-Algorithm
array	I-Algorithm
(	O
CFA	O
)	O
.	O
</s>
<s>
It	O
is	O
also	O
known	O
as	O
CFA	O
interpolation	B-Algorithm
or	O
color	O
reconstruction	O
.	O
</s>
<s>
Most	O
modern	O
digital	B-Device
cameras	I-Device
acquire	O
images	O
using	O
a	O
single	O
image	B-Algorithm
sensor	I-Algorithm
overlaid	O
with	O
a	O
CFA	O
,	O
so	O
demosaicing	B-Algorithm
is	O
part	O
of	O
the	O
processing	B-Algorithm
pipeline	I-Algorithm
required	O
to	O
render	O
these	O
images	O
into	O
a	O
viewable	O
format	O
.	O
</s>
<s>
Many	O
modern	O
digital	B-Device
cameras	I-Device
can	O
save	O
images	O
in	O
a	O
raw	B-Application
format	I-Application
allowing	O
the	O
user	O
to	O
demosaic	B-Algorithm
them	O
using	O
software	O
,	O
rather	O
than	O
using	O
the	O
camera	O
's	O
built-in	O
firmware	B-Application
.	O
</s>
<s>
The	O
aim	O
of	O
a	O
demosaicing	B-Algorithm
algorithm	O
is	O
to	O
reconstruct	O
a	O
full	O
color	O
image	O
(	O
i.e.	O
</s>
<s>
a	O
full	O
set	O
of	O
color	O
triples	O
)	O
from	O
the	O
spatially	O
undersampled	O
color	B-Algorithm
channels	I-Algorithm
output	O
from	O
the	O
CFA	O
.	O
</s>
<s>
A	O
color	B-Algorithm
filter	I-Algorithm
array	I-Algorithm
is	O
a	O
mosaic	O
of	O
color	O
filters	O
in	O
front	O
of	O
the	O
image	B-Algorithm
sensor	I-Algorithm
.	O
</s>
<s>
Commercially	O
,	O
the	O
most	O
commonly	O
used	O
CFA	O
configuration	O
is	O
the	O
Bayer	B-Algorithm
filter	I-Algorithm
illustrated	O
here	O
.	O
</s>
<s>
Since	O
the	O
color	O
subsampling	O
of	O
a	O
CFA	O
by	O
its	O
nature	O
results	O
in	O
aliasing	B-Error_Name
,	O
an	O
optical	O
anti-aliasing	O
filter	O
is	O
typically	O
placed	O
in	O
the	O
optical	O
path	O
between	O
the	O
image	B-Algorithm
sensor	I-Algorithm
and	O
the	O
lens	O
to	O
reduce	O
the	O
false	O
color	O
artifacts	O
(	O
chromatic	O
aliases	B-Error_Name
)	O
introduced	O
by	O
interpolation	B-Algorithm
.	O
</s>
<s>
To	O
reconstruct	O
a	O
full	O
color	O
image	O
from	O
the	O
data	O
collected	O
by	O
the	O
color	O
filtering	O
array	O
,	O
a	O
form	O
of	O
interpolation	B-Algorithm
is	O
needed	O
to	O
fill	O
in	O
the	O
blanks	O
.	O
</s>
<s>
The	O
mathematics	O
here	O
is	O
subject	O
to	O
individual	O
implementation	O
,	O
and	O
is	O
called	O
demosaicing	B-Algorithm
.	O
</s>
<s>
In	O
this	O
example	O
,	O
we	O
use	O
Adobe	B-Operating_System
Photoshop	I-Operating_System
's	O
bicubic	B-Algorithm
interpolation	I-Algorithm
to	O
simulate	O
the	O
circuitry	O
of	O
a	O
Bayer	B-Algorithm
filter	I-Algorithm
device	O
such	O
as	O
a	O
digital	B-Device
camera	I-Device
.	O
</s>
<s>
The	O
image	O
below	O
simulates	O
the	O
output	O
from	O
a	O
Bayer	O
filtered	O
image	B-Algorithm
sensor	I-Algorithm
;	O
each	O
pixel	O
has	O
only	O
a	O
red	O
,	O
green	O
or	O
blue	O
component	O
.	O
</s>
<s>
A	O
digital	B-Device
camera	I-Device
typically	O
has	O
means	O
to	O
reconstruct	O
a	O
whole	O
RGB	O
image	O
using	O
the	O
above	O
information	O
.	O
</s>
<s>
These	O
algorithms	O
are	O
examples	O
of	O
multivariate	O
interpolation	B-Algorithm
on	O
a	O
uniform	O
grid	O
,	O
using	O
relatively	O
straightforward	O
mathematical	O
operations	O
on	O
nearby	O
instances	O
of	O
the	O
same	O
color	O
component	O
.	O
</s>
<s>
The	O
simplest	O
method	O
is	O
nearest-neighbor	O
interpolation	B-Algorithm
which	O
simply	O
copies	O
an	O
adjacent	O
pixel	O
of	O
the	O
same	O
color	B-Algorithm
channel	I-Algorithm
.	O
</s>
<s>
Another	O
simple	O
method	O
is	O
bilinear	O
interpolation	B-Algorithm
,	O
whereby	O
the	O
red	O
value	O
of	O
a	O
non-red	O
pixel	O
is	O
computed	O
as	O
the	O
average	O
of	O
the	O
two	O
or	O
four	O
adjacent	O
red	O
pixels	O
,	O
and	O
similarly	O
for	O
blue	O
and	O
green	O
.	O
</s>
<s>
More	O
complex	O
methods	O
that	O
interpolate	O
independently	O
within	O
each	O
color	O
plane	O
include	O
bicubic	B-Algorithm
interpolation	I-Algorithm
,	O
spline	B-Algorithm
interpolation	I-Algorithm
,	O
and	O
Lanczos	B-Algorithm
resampling	I-Algorithm
.	O
</s>
<s>
Although	O
these	O
methods	O
can	O
obtain	O
good	O
results	O
in	O
homogeneous	O
image	O
regions	O
,	O
they	O
are	O
prone	O
to	O
severe	O
demosaicing	B-Algorithm
artifacts	O
in	O
regions	O
with	O
edges	O
and	O
details	O
when	O
used	O
with	O
pure-color	O
CFAs	O
.	O
</s>
<s>
However	O
,	O
linear	O
interpolation	B-Algorithm
can	O
obtain	O
very	O
good	O
results	O
when	O
combined	O
with	O
a	O
spatio-spectral	O
(	O
panchromatic	O
)	O
CFA	O
.	O
</s>
<s>
One	O
could	O
exploit	O
simple	O
formation	O
models	O
of	O
images	O
for	O
demosaicing	B-Algorithm
.	O
</s>
<s>
This	O
fact	O
was	O
exploited	O
in	O
an	O
image	O
sensitive	O
interpolation	B-Algorithm
for	O
demosaicing	B-Algorithm
.	O
</s>
<s>
More	O
sophisticated	O
demosaicing	B-Algorithm
algorithms	O
exploit	O
the	O
spatial	O
and/or	O
spectral	O
correlation	O
of	O
pixels	O
within	O
a	O
color	O
image	O
.	O
</s>
<s>
Variable	O
Number	O
of	O
Gradients	O
(	O
VNG	O
)	O
interpolation	B-Algorithm
computes	O
gradients	O
near	O
the	O
pixel	O
of	O
interest	O
and	O
uses	O
the	O
lower	O
gradients	O
(	O
representing	O
smoother	O
and	O
more	O
similar	O
parts	O
of	O
the	O
image	O
)	O
to	O
make	O
an	O
estimate	O
.	O
</s>
<s>
It	O
is	O
used	O
in	O
first	O
versions	O
of	O
dcraw	B-Algorithm
,	O
and	O
suffers	O
from	O
color	O
artifacts	O
.	O
</s>
<s>
It	O
has	O
fewer	O
color	O
artifacts	O
on	O
natural	O
images	O
than	O
the	O
Variable	O
Number	O
of	O
Gradients	O
method	O
;	O
it	O
was	O
introduced	O
in	O
dcraw	B-Algorithm
from	O
rel	O
.	O
</s>
<s>
It	O
selects	O
the	O
direction	O
of	O
interpolation	B-Algorithm
so	O
as	O
to	O
maximize	O
a	O
homogeneity	O
metric	O
,	O
thus	O
typically	O
minimizing	O
color	O
artifacts	O
.	O
</s>
<s>
It	O
has	O
been	O
implemented	O
in	O
recent	O
versions	O
of	O
dcraw	B-Algorithm
.	O
</s>
<s>
Aliasing	B-Error_Name
Minimization	O
and	O
Zipper	O
Elimination	O
(	O
AMaZE	O
)	O
designed	O
by	O
Emil	O
J	O
.	O
Martinec	O
is	O
slow	O
but	O
has	O
great	O
performance	O
,	O
especially	O
on	O
low	O
noise	O
captures	O
.	O
</s>
<s>
Implementations	O
of	O
AMaZE	O
can	O
be	O
found	O
in	O
RawTherapee	B-Algorithm
and	O
darktable	B-Language
.	O
</s>
<s>
It	O
has	O
been	O
shown	O
that	O
super-resolution	B-Algorithm
and	O
demosaicing	B-Algorithm
are	O
two	O
faces	O
of	O
the	O
same	O
problem	O
and	O
it	O
is	O
reasonable	O
to	O
address	O
them	O
in	O
a	O
unified	O
context	O
.	O
</s>
<s>
Note	O
that	O
both	O
these	O
problems	O
face	O
the	O
aliasing	B-Error_Name
issue	O
.	O
</s>
<s>
Therefore	O
,	O
especially	O
in	O
the	O
case	O
of	O
video	O
(	O
multi-frame	O
)	O
reconstruction	O
,	O
a	O
joint	O
super-resolution	B-Algorithm
and	O
demosaicing	B-Algorithm
approach	O
provides	O
the	O
optimal	O
solution	O
.	O
</s>
<s>
When	O
one	O
has	O
access	O
to	O
the	O
raw	B-Application
image	I-Application
data	I-Application
from	O
a	O
digital	B-Device
camera	I-Device
,	O
one	O
can	O
use	O
computer	O
software	O
with	O
a	O
variety	O
of	O
different	O
demosaicing	B-Algorithm
algorithms	O
instead	O
of	O
being	O
limited	O
to	O
the	O
one	O
built	O
into	O
the	O
camera	O
.	O
</s>
<s>
A	O
few	O
raw	O
development	O
programs	O
,	O
such	O
as	O
RawTherapee	B-Algorithm
and	O
darktable	B-Language
,	O
give	O
the	O
user	O
an	O
option	O
to	O
choose	O
which	O
algorithm	O
should	O
be	O
used	O
.	O
</s>
<s>
The	O
differences	O
in	O
rendering	O
the	O
finest	O
detail	O
(	O
and	O
grain	O
texture	O
)	O
that	O
come	O
from	O
the	O
choice	O
of	O
demosaicing	B-Algorithm
algorithm	O
are	O
among	O
the	O
main	O
differences	O
between	O
various	O
raw	O
developers	O
;	O
often	O
photographers	O
will	O
prefer	O
a	O
particular	O
program	O
for	O
aesthetic	O
reasons	O
related	O
to	O
this	O
effect	O
.	O
</s>
<s>
The	O
color	O
artifacts	O
due	O
to	O
demosaicing	B-Algorithm
provide	O
important	O
clues	O
for	O
identifying	O
photo	O
forgeries	O
.	O
</s>
