Beispiel #1
0
 /**
  * Compares the histogram object against another histogram object.
  * The lower the returned value is, the closer a match they are.
  *
  * @param Histogram $histogram The histogram object to compare against.
  * @return int The comparison value. Lower means a closer match.
  */
 private function compare_against($histogram)
 {
     $value = 0;
     // If there is no histogram (image couldn't be analyzed), never match anything
     if ($this->histogram == '' || $histogram == '') {
         return self::$match_threshold;
     }
     foreach ($this->histogram as $channel_key => $color_channel) {
         foreach ($color_channel as $bucket_key => $color_bucket) {
             $value += abs($color_bucket - $histogram->get($channel_key, $bucket_key));
             // Stop computing early if the value will never be a match
             if ($value >= self::$match_threshold) {
                 return self::$match_threshold;
             }
         }
     }
     return $value;
 }