Changed UniquePalette to use a KDTree for searches.