shithub: libvpx

Download patch

ref: 6f594bb8c81f9c863495f0dbb3a4d7d78ffa8409
parent: d310225c19d52d26241399fc7d67753f9eac0944
parent: da373475ed24169ee0578f6d79978e7f07348164
author: Angie Chiang <angiebird@google.com>
date: Tue Apr 16 21:49:56 EDT 2019

Merge "Refine vp9_kmeans()"

--- a/vp9/encoder/vp9_encodeframe.c
+++ b/vp9/encoder/vp9_encodeframe.c
@@ -5841,7 +5841,7 @@
 
   // initialize the center points
   for (j = 0; j < k; ++j) {
-    ctr_ls[j] = arr[(size * j) / k].value;
+    ctr_ls[j] = arr[(size * (2 * j + 1)) / (2 * k)].value;
   }
 
   for (itr = 0; itr < 10; ++itr) {
@@ -5851,10 +5851,13 @@
       count[i] = 0;
     }
 
+    // Both the data and centers are sorted in ascending order.
+    // As each data point is processed in order, its corresponding group index
+    // can only increase. So we only need to reset the group index to zero here.
+    group_idx = 0;
     for (i = 0; i < size; ++i) {
-      // place samples into clusters
-      group_idx = 0;
       while (arr[i].value >= boundary_ls[group_idx]) {
+        // place samples into clusters
         ++group_idx;
         if (group_idx == k - 1) {
           break;