<s>
Median	B-Algorithm
cut	I-Algorithm
is	O
an	O
algorithm	B-Algorithm
to	I-Algorithm
sort	I-Algorithm
data	I-Algorithm
of	O
an	O
arbitrary	O
number	O
of	O
dimensions	O
into	O
series	O
of	O
sets	O
by	O
recursively	O
cutting	O
each	O
set	O
of	O
data	O
at	O
the	O
median	O
point	O
along	O
the	O
longest	O
dimension	O
.	O
</s>
<s>
Median	B-Algorithm
cut	I-Algorithm
is	O
typically	O
used	O
for	O
color	B-Algorithm
quantization	I-Algorithm
.	O
</s>
<s>
For	O
example	O
,	O
to	O
reduce	O
a	O
64k-colour	O
image	O
to	O
256	O
colours	O
,	O
median	B-Algorithm
cut	I-Algorithm
is	O
used	O
to	O
find	O
256	O
colours	O
that	O
match	O
the	O
original	O
data	O
well	O
.	O
</s>
<s>
Suppose	O
we	O
have	O
an	O
image	O
with	O
an	O
arbitrary	O
number	O
of	O
pixels	B-Algorithm
and	O
want	O
to	O
generate	O
a	O
palette	B-Data_Structure
of	O
16	O
colors	O
.	O
</s>
<s>
Put	O
all	O
the	O
pixels	B-Algorithm
of	O
the	O
image	O
(	O
that	O
is	O
,	O
their	O
RGB	O
values	O
)	O
in	O
a	O
bucket	B-Algorithm
.	O
</s>
<s>
Find	O
out	O
which	O
color	O
channel	O
(	O
red	O
,	O
green	O
,	O
or	O
blue	O
)	O
among	O
the	O
pixels	B-Algorithm
in	O
the	O
bucket	B-Algorithm
has	O
the	O
greatest	O
range	O
,	O
then	O
sort	O
the	O
pixels	B-Algorithm
according	O
to	O
that	O
channel	O
's	O
values	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
blue	O
channel	O
has	O
the	O
greatest	O
range	O
,	O
then	O
a	O
pixel	B-Algorithm
with	O
an	O
RGB	O
value	O
of	O
is	O
less	O
than	O
a	O
pixel	B-Algorithm
with	O
an	O
RGB	O
value	O
of	O
,	O
because	O
.	O
</s>
<s>
After	O
the	O
bucket	B-Algorithm
has	O
been	O
sorted	O
,	O
move	O
the	O
upper	O
half	O
of	O
the	O
pixels	B-Algorithm
into	O
a	O
new	O
bucket	B-Algorithm
.	O
</s>
<s>
(	O
It	O
is	O
this	O
step	O
that	O
gives	O
the	O
median	B-Algorithm
cut	I-Algorithm
algorithm	O
its	O
name	O
;	O
the	O
buckets	O
are	O
divided	O
into	O
two	O
at	O
the	O
median	O
of	O
the	O
list	O
of	O
pixels	B-Algorithm
.	O
)	O
</s>
<s>
This	O
process	O
can	O
be	O
repeated	O
to	O
further	O
subdivide	O
the	O
set	O
of	O
pixels	B-Algorithm
:	O
choose	O
a	O
bucket	B-Algorithm
to	O
divide	O
(	O
e.g.	O
,	O
the	O
bucket	B-Algorithm
with	O
the	O
greatest	O
range	O
in	O
any	O
color	O
channel	O
)	O
and	O
divide	O
it	O
into	O
two	O
.	O
</s>
<s>
After	O
the	O
desired	O
number	O
of	O
buckets	O
have	O
been	O
produced	O
,	O
average	O
the	O
pixels	B-Algorithm
in	O
each	O
bucket	B-Algorithm
to	O
get	O
the	O
final	O
color	O
palette	B-Data_Structure
.	O
</s>
