<s>
An	O
octree	B-Data_Structure
is	O
a	O
tree	B-Application
data	I-Application
structure	I-Application
in	O
which	O
each	O
internal	O
node	O
has	O
exactly	O
eight	O
children	B-Data_Structure
.	O
</s>
<s>
Octrees	B-Data_Structure
are	O
most	O
often	O
used	O
to	O
partition	O
a	O
three-dimensional	O
space	O
by	O
recursively	O
subdividing	O
it	O
into	O
eight	O
octants	O
.	O
</s>
<s>
Octrees	B-Data_Structure
are	O
the	O
three-dimensional	O
analog	O
of	O
quadtrees	B-Data_Structure
.	O
</s>
<s>
Octrees	B-Data_Structure
are	O
often	O
used	O
in	O
3D	O
graphics	O
and	O
3D	O
game	O
engines	O
.	O
</s>
<s>
Each	O
node	O
in	O
an	O
octree	B-Data_Structure
subdivides	O
the	O
space	O
it	O
represents	O
into	O
eight	O
octants	O
.	O
</s>
<s>
In	O
a	O
point	O
region	O
(	O
PR	O
)	O
octree	B-Data_Structure
,	O
the	O
node	O
stores	O
an	O
explicit	O
three-dimensional	O
point	O
,	O
which	O
is	O
the	O
"	O
center	O
"	O
of	O
the	O
subdivision	O
for	O
that	O
node	O
;	O
the	O
point	O
defines	O
one	O
of	O
the	O
corners	O
for	O
each	O
of	O
the	O
eight	O
children	B-Data_Structure
.	O
</s>
<s>
In	O
a	O
matrix-based	O
(	O
MX	O
)	O
octree	B-Data_Structure
,	O
the	O
subdivision	O
point	O
is	O
implicitly	O
the	O
center	O
of	O
the	O
space	O
the	O
node	O
represents	O
.	O
</s>
<s>
The	O
root	B-Application
node	I-Application
of	O
a	O
PR	O
octree	B-Data_Structure
can	O
represent	O
infinite	O
space	O
;	O
the	O
root	B-Application
node	I-Application
of	O
an	O
MX	O
octree	B-Data_Structure
must	O
represent	O
a	O
finite	O
bounded	O
space	O
so	O
that	O
the	O
implicit	O
centers	O
are	O
well-defined	O
.	O
</s>
<s>
Note	O
that	O
octrees	B-Data_Structure
are	O
not	O
the	O
same	O
as	O
k-d	B-Data_Structure
trees	I-Data_Structure
:	O
k-d	B-Data_Structure
trees	I-Data_Structure
split	O
along	O
a	O
dimension	O
and	O
octrees	B-Data_Structure
split	O
around	O
a	O
point	O
.	O
</s>
<s>
Also	O
k-d	B-Data_Structure
trees	I-Data_Structure
are	O
always	O
binary	O
,	O
which	O
is	O
not	O
the	O
case	O
for	O
octrees	B-Data_Structure
.	O
</s>
<s>
By	O
using	O
a	O
depth-first	B-Algorithm
search	I-Algorithm
the	O
nodes	O
are	O
to	O
be	O
traversed	O
and	O
only	O
required	O
surfaces	O
are	O
to	O
be	O
viewed	O
.	O
</s>
<s>
The	O
octree	B-Data_Structure
color	B-Algorithm
quantization	I-Algorithm
algorithm	O
,	O
invented	O
by	O
Gervautz	O
and	O
Purgathofer	O
in	O
1988	O
,	O
encodes	O
image	O
color	O
data	O
as	O
an	O
octree	B-Data_Structure
up	O
to	O
nine	O
levels	O
deep	O
.	O
</s>
<s>
Octrees	B-Data_Structure
are	O
used	O
because	O
and	O
there	O
are	O
three	O
color	O
components	O
in	O
the	O
RGB	O
system	O
.	O
</s>
<s>
The	O
bottom	O
level	O
of	O
the	O
octree	B-Data_Structure
consists	O
of	O
leaf	B-Application
nodes	I-Application
that	O
accrue	O
color	O
data	O
not	O
represented	O
in	O
the	O
tree	O
;	O
these	O
nodes	O
initially	O
contain	O
single	O
bits	O
.	O
</s>
<s>
If	O
much	O
more	O
than	O
the	O
desired	O
number	O
of	O
palette	O
colors	O
are	O
entered	O
into	O
the	O
octree	B-Data_Structure
,	O
its	O
size	O
can	O
be	O
continually	O
reduced	O
by	O
seeking	O
out	O
a	O
bottom-level	O
node	O
and	O
averaging	O
its	O
bit	O
data	O
up	O
into	O
a	O
leaf	O
node	O
,	O
pruning	O
part	O
of	O
the	O
tree	O
.	O
</s>
<s>
Once	O
sampling	O
is	O
complete	O
,	O
exploring	O
all	O
routes	O
in	O
the	O
tree	O
down	O
to	O
the	O
leaf	B-Application
nodes	I-Application
,	O
taking	O
note	O
of	O
the	O
bits	O
along	O
the	O
way	O
,	O
will	O
yield	O
approximately	O
the	O
required	O
number	O
of	O
colors	O
.	O
</s>
<s>
The	O
example	O
recursive	O
algorithm	O
outline	O
below	O
(	O
MATLAB	B-Language
syntax	O
)	O
decomposes	O
an	O
array	O
of	O
3-dimensional	O
points	O
into	O
octree	B-Data_Structure
style	O
bins	O
.	O
</s>
<s>
The	O
implementation	O
begins	O
with	O
a	O
single	O
bin	O
surrounding	O
all	O
given	O
points	O
,	O
which	O
then	O
recursively	O
subdivides	O
into	O
its	O
8	O
octree	B-Data_Structure
regions	O
.	O
</s>
<s>
Taking	O
the	O
full	O
list	O
of	O
colors	O
of	O
a	O
24-bit	O
RGB	O
image	O
as	O
point	O
input	O
to	O
the	O
Octree	B-Data_Structure
point	O
decomposition	O
implementation	O
outlined	O
above	O
,	O
the	O
following	O
example	O
show	O
the	O
results	O
of	O
octree	B-Data_Structure
color	B-Algorithm
quantization	I-Algorithm
.	O
</s>
<s>
The	O
first	O
image	O
is	O
the	O
original	O
(	O
532818	O
distinct	O
colors	O
)	O
,	O
while	O
the	O
second	O
is	O
the	O
quantized	O
image	O
(	O
184	O
distinct	O
colors	O
)	O
using	O
octree	B-Data_Structure
decomposition	O
,	O
with	O
each	O
pixel	O
assigned	O
the	O
color	O
at	O
the	O
center	O
of	O
the	O
octree	B-Data_Structure
bin	O
in	O
which	O
it	O
falls	O
.	O
</s>
<s>
Alternatively	O
,	O
final	O
colors	O
could	O
be	O
chosen	O
at	O
the	O
centroid	O
of	O
all	O
colors	O
in	O
each	O
octree	B-Data_Structure
bin	O
,	O
however	O
this	O
added	O
computation	O
has	O
very	O
little	O
effect	O
on	O
the	O
visual	O
result	O
.	O
</s>
