Search code examples
google-cloud-storagegoogle-cloud-visiongoogle-vision

How to get the percentage of color from image_properties in google vision api?


I am trying to use Google Vision API for color detection. For this i am using python library. When i fetch image_properties i get a result something like below

colors {
  color {
    red: 52.0
    green: 94.0
    blue: 96.0
  }
  score: 0.11754503101110458
  pixel_fraction: 0.04190981388092041
}

But how to calculate the percentage which in this case comes out to be "18%"

Actual Output of the Google Vision Api


Solution

  • I assume you've gotten this result using Vision demo. This percentage (18%) is calculated by taking the score for each color record and divide it by the sum of all the scores:

    % "percent" = score / (score1 + score2 + score3 + ... + scoreN)