We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Vision: if one of RGB values for dominant color is absent, should default to 0

If you can provide us with as much of the following information as possible it
will help us identify the cause of your issue more quickly.

1.  OS type and version

     macOS Sierra 10.12.1

2.  Python version and virtual environment information `python --version`

    ```
    $ python --version
    Python 2.7.12
    ```

3.  google-cloud-python version `pip show google-cloud`, `pip show google-<service>` or `pip freeze`

    ```
    $ pip freeze | grep google
    google-cloud-core==0.21.0
    google-cloud-vision==0.21.0
    googleapis-common-protos==1.5.0
    ```
4.  Stacktrace if available

    ```
    Traceback (most recent call last):
      File "getpalette.py", line 108, in <module>
        main(args.images)
      File "getpalette.py", line 97, in main
        pixelfy(image_path)
      File "getpalette.py", line 58, in pixelfy
        properties = image.detect_properties()
      File "/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/image.py", line 189, in detect_properties
        return self._detect_annotation(features)
      File "/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/image.py", line 125, in _detect_annotation
        _entity_from_response_type(feature.feature_type, results))
      File "/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/image.py", line 229, in _entity_from_response_type
        ImagePropertiesAnnotation.from_api_repr(results[feature_key]))
      File "/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/color.py", line 40, in from_api_repr
        response['dominantColors']['colors']]
      File "/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/color.py", line 160, in from_api_repr
        color = Color.from_api_repr(response['color'])
      File "/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/color.py", line 90, in from_api_repr
        blue = response['blue']
    KeyError: 'blue'
    ```

5.  Steps to reproduce

    Run the code example against the following image. `python getpalette.py cat.png`

    ![image](https://cloud.githubusercontent.com/assets/247555/20451516/1ac543c4-adaf-11e6-847a-a0913ca2fe12.png)

    Photo by [Chen YiZhou](https://stock.tookapic.com/photos/73879)

6. Code example `getpalette.py`

```
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import division
from __future__ import print_function

import argparse
import io
import os
import os.path

from google.cloud import vision
from PIL import Image


def resize(size, max_dimension=500):
    width, height = size
    if width < height:
        return (int((width / height) * max_dimension), max_dimension)
    return (max_dimension, int((height / width) * max_dimension))


def pixelfy(image_path):
    print(image_path)
    vision_client = vision.Client()
    im = Image.open(image_path)
    im = im.resize(resize(im.size), resample=Image.LANCZOS)
    f = io.BytesIO()
    im.save(f, format='jpeg')
    image = vision_client.image(content=f.getvalue())
    properties = image.detect_properties()
    palette = []

    for property_ in properties:
        for color in property_.colors:
            palette.append(
                (
                    color.color.red,
                    color.color.green,
                    color.color.blue,
                ))
    print(palette)


def main(image_paths):
    for image_path in image_paths:
        pixelfy(image_path)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('images', help='Path to image(s) to get palette.', nargs='+')

    args = parser.parse_args()

    main(args.images)
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `vision/google/cloud/vision/color.py`
Content:
```
1 # Copyright 2016 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """Image properties class representation derived from Vision API response."""
16 
17 
18 class ImagePropertiesAnnotation(object):
19     """Representation of image properties
20 
21     :type colors: list
22     :param colors: List of
23                    :class:`~google.cloud.vision.color.ColorInformation`.
24     """
25     def __init__(self, colors):
26         self._colors = colors
27 
28     @classmethod
29     def from_api_repr(cls, response):
30         """Factory: construct ``ImagePropertiesAnnotation`` from a response.
31 
32         :type response: dict
33         :param response: Dictionary response from Vision API with image
34                          properties data.
35 
36         :rtype: :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`.
37         :returns: Populated instance of ``ImagePropertiesAnnotation``.
38         """
39         colors = [ColorInformation.from_api_repr(color) for color in
40                   response['dominantColors']['colors']]
41         return cls(colors)
42 
43     @property
44     def colors(self):
45         """Colors in an image.
46 
47         :rtype: list of :class:`~google.cloud.vision.color.ColorInformation`
48         :returns: Populated list of ``ColorInformation``.
49         """
50         return self._colors
51 
52 
53 class Color(object):
54     """Representation of RGBA color information.
55 
56     :type red: int
57     :param red: The amount of red in the color as a value in the interval
58                 [0, 255].
59 
60     :type green: int
61     :param green: The amount of green in the color as a value in the interval
62                   [0, 255].
63 
64     :type blue: int
65     :param blue: The amount of blue in the color as a value in the interval
66                  [0, 255].
67 
68     :type alpha: float
69     :param alpha: The fraction of this color that should be applied to the
70                   pixel.
71     """
72     def __init__(self, red, green, blue, alpha):
73         self._red = red
74         self._green = green
75         self._blue = blue
76         self._alpha = alpha
77 
78     @classmethod
79     def from_api_repr(cls, response):
80         """Factory: construct a ``Color`` from a Vision API response.
81 
82         :type response: dict
83         :param response: Color from API Response.
84 
85         :rtype: :class:`~google.cloud.vision.color.Color`
86         :returns: Instance of :class:`~google.cloud.vision.color.Color`.
87         """
88         red = response['red']
89         green = response['green']
90         blue = response['blue']
91         alpha = response.get('alpha')
92 
93         return cls(red, green, blue, alpha)
94 
95     @property
96     def red(self):
97         """Red component of the color.
98 
99         :rtype: int
100         :returns: Red RGB value.
101         """
102         return self._red
103 
104     @property
105     def green(self):
106         """Green component of the color.
107 
108         :rtype: int
109         :returns: Green RGB value.
110         """
111         return self._green
112 
113     @property
114     def blue(self):
115         """Blue component of the color.
116 
117         :rtype: int
118         :returns: Blue RGB value.
119         """
120         return self._blue
121 
122     @property
123     def alpha(self):
124         """Alpha transparency level.
125 
126         :rtype: float
127         :returns: Alpha transparency level.
128         """
129         return self._alpha
130 
131 
132 class ColorInformation(object):
133     """Representation of color information from API response.
134 
135     :type color: :class:`~google.cloud.vision.color.Color`
136     :param color: RGB components of the color.
137 
138     :type score: float
139     :param score: Image-specific score for this color. Value in range [0, 1].
140 
141     :type pixel_fraction: float
142     :param pixel_fraction: Stores the fraction of pixels the color occupies in
143                            the image. Value in range [0, 1].
144     """
145     def __init__(self, color, score, pixel_fraction):
146         self._color = color
147         self._score = score
148         self._pixel_fraction = pixel_fraction
149 
150     @classmethod
151     def from_api_repr(cls, response):
152         """Factory: construct ``ColorInformation`` for a color found.
153 
154         :type response: dict
155         :param response: Color data with extra meta information.
156 
157         :rtype: :class:`~google.cloud.vision.color.ColorInformation`
158         :returns: Instance of ``ColorInformation``.
159         """
160         color = Color.from_api_repr(response['color'])
161         score = response['score']
162         pixel_fraction = response['pixelFraction']
163 
164         return cls(color, score, pixel_fraction)
165 
166     @property
167     def color(self):
168         """RGB components of the color.
169 
170         :rtype: :class:`~google.vision.color.Color`
171         :returns: Instance of ``Color``.
172         """
173         return self._color
174 
175     @property
176     def score(self):
177         """Image-specific score for this color. Value in range [0, 1].
178 
179         :rtype: float
180         :returns: Image score for this color.
181         """
182         return self._score
183 
184     @property
185     def pixel_fraction(self):
186         """Stores the fraction of pixels the color occupies in the image.
187 
188         :rtype: float
189         :returns: Pixel fraction value in range [0, 1].
190         """
191         return self._pixel_fraction
192
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/vision/google/cloud/vision/color.py b/vision/google/cloud/vision/color.py
--- a/vision/google/cloud/vision/color.py
+++ b/vision/google/cloud/vision/color.py
@@ -36,8 +36,9 @@
         :rtype: :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`.
         :returns: Populated instance of ``ImagePropertiesAnnotation``.
         """
-        colors = [ColorInformation.from_api_repr(color) for color in
-                  response['dominantColors']['colors']]
+        raw_colors = response.get('dominantColors', {}).get('colors', ())
+        colors = [ColorInformation.from_api_repr(color)
+                  for color in raw_colors]
         return cls(colors)
 
     @property
@@ -85,10 +86,10 @@
         :rtype: :class:`~google.cloud.vision.color.Color`
         :returns: Instance of :class:`~google.cloud.vision.color.Color`.
         """
-        red = response['red']
-        green = response['green']
-        blue = response['blue']
-        alpha = response.get('alpha')
+        red = response.get('red', 0)
+        green = response.get('green', 0)
+        blue = response.get('blue', 0)
+        alpha = response.get('alpha', 0.0)
 
         return cls(red, green, blue, alpha)
 
@@ -157,9 +158,9 @@
         :rtype: :class:`~google.cloud.vision.color.ColorInformation`
         :returns: Instance of ``ColorInformation``.
         """
-        color = Color.from_api_repr(response['color'])
-        score = response['score']
-        pixel_fraction = response['pixelFraction']
+        color = Color.from_api_repr(response.get('color'))
+        score = response.get('score')
+        pixel_fraction = response.get('pixelFraction')
 
         return cls(color, score, pixel_fraction)

{"golden_diff": "diff --git a/vision/google/cloud/vision/color.py b/vision/google/cloud/vision/color.py\n--- a/vision/google/cloud/vision/color.py\n+++ b/vision/google/cloud/vision/color.py\n@@ -36,8 +36,9 @@\n         :rtype: :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`.\n         :returns: Populated instance of ``ImagePropertiesAnnotation``.\n         \"\"\"\n-        colors = [ColorInformation.from_api_repr(color) for color in\n-                  response['dominantColors']['colors']]\n+        raw_colors = response.get('dominantColors', {}).get('colors', ())\n+        colors = [ColorInformation.from_api_repr(color)\n+                  for color in raw_colors]\n         return cls(colors)\n \n     @property\n@@ -85,10 +86,10 @@\n         :rtype: :class:`~google.cloud.vision.color.Color`\n         :returns: Instance of :class:`~google.cloud.vision.color.Color`.\n         \"\"\"\n-        red = response['red']\n-        green = response['green']\n-        blue = response['blue']\n-        alpha = response.get('alpha')\n+        red = response.get('red', 0)\n+        green = response.get('green', 0)\n+        blue = response.get('blue', 0)\n+        alpha = response.get('alpha', 0.0)\n \n         return cls(red, green, blue, alpha)\n \n@@ -157,9 +158,9 @@\n         :rtype: :class:`~google.cloud.vision.color.ColorInformation`\n         :returns: Instance of ``ColorInformation``.\n         \"\"\"\n-        color = Color.from_api_repr(response['color'])\n-        score = response['score']\n-        pixel_fraction = response['pixelFraction']\n+        color = Color.from_api_repr(response.get('color'))\n+        score = response.get('score')\n+        pixel_fraction = response.get('pixelFraction')\n \n         return cls(color, score, pixel_fraction)\n", "issue": "Vision: if one of RGB values for dominant color is absent, should default to 0\n\r\nIf you can provide us with as much of the following information as possible it\r\nwill help us identify the cause of your issue more quickly.\r\n\r\n1.  OS type and version\r\n\r\n     macOS Sierra 10.12.1\r\n\r\n2.  Python version and virtual environment information `python --version`\r\n\r\n    ```\r\n    $ python --version\r\n    Python 2.7.12\r\n    ```\r\n\r\n3.  google-cloud-python version `pip show google-cloud`, `pip show google-<service>` or `pip freeze`\r\n\r\n    ```\r\n    $ pip freeze | grep google\r\n    google-cloud-core==0.21.0\r\n    google-cloud-vision==0.21.0\r\n    googleapis-common-protos==1.5.0\r\n    ```\r\n4.  Stacktrace if available\r\n\r\n    ```\r\n    Traceback (most recent call last):\r\n      File \"getpalette.py\", line 108, in <module>\r\n        main(args.images)\r\n      File \"getpalette.py\", line 97, in main\r\n        pixelfy(image_path)\r\n      File \"getpalette.py\", line 58, in pixelfy\r\n        properties = image.detect_properties()\r\n      File \"/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/image.py\", line 189, in detect_properties\r\n        return self._detect_annotation(features)\r\n      File \"/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/image.py\", line 125, in _detect_annotation\r\n        _entity_from_response_type(feature.feature_type, results))\r\n      File \"/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/image.py\", line 229, in _entity_from_response_type\r\n        ImagePropertiesAnnotation.from_api_repr(results[feature_key]))\r\n      File \"/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/color.py\", line 40, in from_api_repr\r\n        response['dominantColors']['colors']]\r\n      File \"/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/color.py\", line 160, in from_api_repr\r\n        color = Color.from_api_repr(response['color'])\r\n      File \"/Users/swast/venvs/cloud-vision/lib/python2.7/site-packages/google/cloud/vision/color.py\", line 90, in from_api_repr\r\n        blue = response['blue']\r\n    KeyError: 'blue'\r\n    ```\r\n\r\n5.  Steps to reproduce\r\n\r\n    Run the code example against the following image. `python getpalette.py cat.png`\r\n\r\n    ![image](https://cloud.githubusercontent.com/assets/247555/20451516/1ac543c4-adaf-11e6-847a-a0913ca2fe12.png)\r\n\r\n    Photo by [Chen YiZhou](https://stock.tookapic.com/photos/73879)\r\n\r\n6. Code example `getpalette.py`\r\n\r\n```\r\n# Copyright 2016 Google Inc.\r\n#\r\n# Licensed under the Apache License, Version 2.0 (the \"License\");\r\n# you may not use this file except in compliance with the License.\r\n# You may obtain a copy of the License at\r\n#\r\n#     http://www.apache.org/licenses/LICENSE-2.0\r\n#\r\n# Unless required by applicable law or agreed to in writing, software\r\n# distributed under the License is distributed on an \"AS IS\" BASIS,\r\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\n# See the License for the specific language governing permissions and\r\n# limitations under the License.\r\n\r\nfrom __future__ import division\r\nfrom __future__ import print_function\r\n\r\nimport argparse\r\nimport io\r\nimport os\r\nimport os.path\r\n\r\nfrom google.cloud import vision\r\nfrom PIL import Image\r\n\r\n\r\ndef resize(size, max_dimension=500):\r\n    width, height = size\r\n    if width < height:\r\n        return (int((width / height) * max_dimension), max_dimension)\r\n    return (max_dimension, int((height / width) * max_dimension))\r\n\r\n\r\ndef pixelfy(image_path):\r\n    print(image_path)\r\n    vision_client = vision.Client()\r\n    im = Image.open(image_path)\r\n    im = im.resize(resize(im.size), resample=Image.LANCZOS)\r\n    f = io.BytesIO()\r\n    im.save(f, format='jpeg')\r\n    image = vision_client.image(content=f.getvalue())\r\n    properties = image.detect_properties()\r\n    palette = []\r\n\r\n    for property_ in properties:\r\n        for color in property_.colors:\r\n            palette.append(\r\n                (\r\n                    color.color.red,\r\n                    color.color.green,\r\n                    color.color.blue,\r\n                ))\r\n    print(palette)\r\n\r\n\r\ndef main(image_paths):\r\n    for image_path in image_paths:\r\n        pixelfy(image_path)\r\n\r\n\r\nif __name__ == '__main__':\r\n    parser = argparse.ArgumentParser(\r\n        description=__doc__,\r\n        formatter_class=argparse.RawDescriptionHelpFormatter)\r\n    parser.add_argument('images', help='Path to image(s) to get palette.', nargs='+')\r\n\r\n    args = parser.parse_args()\r\n\r\n    main(args.images)\r\n```\n", "before_files": [{"content": "# Copyright 2016 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Image properties class representation derived from Vision API response.\"\"\"\n\n\nclass ImagePropertiesAnnotation(object):\n    \"\"\"Representation of image properties\n\n    :type colors: list\n    :param colors: List of\n                   :class:`~google.cloud.vision.color.ColorInformation`.\n    \"\"\"\n    def __init__(self, colors):\n        self._colors = colors\n\n    @classmethod\n    def from_api_repr(cls, response):\n        \"\"\"Factory: construct ``ImagePropertiesAnnotation`` from a response.\n\n        :type response: dict\n        :param response: Dictionary response from Vision API with image\n                         properties data.\n\n        :rtype: :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`.\n        :returns: Populated instance of ``ImagePropertiesAnnotation``.\n        \"\"\"\n        colors = [ColorInformation.from_api_repr(color) for color in\n                  response['dominantColors']['colors']]\n        return cls(colors)\n\n    @property\n    def colors(self):\n        \"\"\"Colors in an image.\n\n        :rtype: list of :class:`~google.cloud.vision.color.ColorInformation`\n        :returns: Populated list of ``ColorInformation``.\n        \"\"\"\n        return self._colors\n\n\nclass Color(object):\n    \"\"\"Representation of RGBA color information.\n\n    :type red: int\n    :param red: The amount of red in the color as a value in the interval\n                [0, 255].\n\n    :type green: int\n    :param green: The amount of green in the color as a value in the interval\n                  [0, 255].\n\n    :type blue: int\n    :param blue: The amount of blue in the color as a value in the interval\n                 [0, 255].\n\n    :type alpha: float\n    :param alpha: The fraction of this color that should be applied to the\n                  pixel.\n    \"\"\"\n    def __init__(self, red, green, blue, alpha):\n        self._red = red\n        self._green = green\n        self._blue = blue\n        self._alpha = alpha\n\n    @classmethod\n    def from_api_repr(cls, response):\n        \"\"\"Factory: construct a ``Color`` from a Vision API response.\n\n        :type response: dict\n        :param response: Color from API Response.\n\n        :rtype: :class:`~google.cloud.vision.color.Color`\n        :returns: Instance of :class:`~google.cloud.vision.color.Color`.\n        \"\"\"\n        red = response['red']\n        green = response['green']\n        blue = response['blue']\n        alpha = response.get('alpha')\n\n        return cls(red, green, blue, alpha)\n\n    @property\n    def red(self):\n        \"\"\"Red component of the color.\n\n        :rtype: int\n        :returns: Red RGB value.\n        \"\"\"\n        return self._red\n\n    @property\n    def green(self):\n        \"\"\"Green component of the color.\n\n        :rtype: int\n        :returns: Green RGB value.\n        \"\"\"\n        return self._green\n\n    @property\n    def blue(self):\n        \"\"\"Blue component of the color.\n\n        :rtype: int\n        :returns: Blue RGB value.\n        \"\"\"\n        return self._blue\n\n    @property\n    def alpha(self):\n        \"\"\"Alpha transparency level.\n\n        :rtype: float\n        :returns: Alpha transparency level.\n        \"\"\"\n        return self._alpha\n\n\nclass ColorInformation(object):\n    \"\"\"Representation of color information from API response.\n\n    :type color: :class:`~google.cloud.vision.color.Color`\n    :param color: RGB components of the color.\n\n    :type score: float\n    :param score: Image-specific score for this color. Value in range [0, 1].\n\n    :type pixel_fraction: float\n    :param pixel_fraction: Stores the fraction of pixels the color occupies in\n                           the image. Value in range [0, 1].\n    \"\"\"\n    def __init__(self, color, score, pixel_fraction):\n        self._color = color\n        self._score = score\n        self._pixel_fraction = pixel_fraction\n\n    @classmethod\n    def from_api_repr(cls, response):\n        \"\"\"Factory: construct ``ColorInformation`` for a color found.\n\n        :type response: dict\n        :param response: Color data with extra meta information.\n\n        :rtype: :class:`~google.cloud.vision.color.ColorInformation`\n        :returns: Instance of ``ColorInformation``.\n        \"\"\"\n        color = Color.from_api_repr(response['color'])\n        score = response['score']\n        pixel_fraction = response['pixelFraction']\n\n        return cls(color, score, pixel_fraction)\n\n    @property\n    def color(self):\n        \"\"\"RGB components of the color.\n\n        :rtype: :class:`~google.vision.color.Color`\n        :returns: Instance of ``Color``.\n        \"\"\"\n        return self._color\n\n    @property\n    def score(self):\n        \"\"\"Image-specific score for this color. Value in range [0, 1].\n\n        :rtype: float\n        :returns: Image score for this color.\n        \"\"\"\n        return self._score\n\n    @property\n    def pixel_fraction(self):\n        \"\"\"Stores the fraction of pixels the color occupies in the image.\n\n        :rtype: float\n        :returns: Pixel fraction value in range [0, 1].\n        \"\"\"\n        return self._pixel_fraction\n", "path": "vision/google/cloud/vision/color.py"}], "after_files": [{"content": "# Copyright 2016 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Image properties class representation derived from Vision API response.\"\"\"\n\n\nclass ImagePropertiesAnnotation(object):\n    \"\"\"Representation of image properties\n\n    :type colors: list\n    :param colors: List of\n                   :class:`~google.cloud.vision.color.ColorInformation`.\n    \"\"\"\n    def __init__(self, colors):\n        self._colors = colors\n\n    @classmethod\n    def from_api_repr(cls, response):\n        \"\"\"Factory: construct ``ImagePropertiesAnnotation`` from a response.\n\n        :type response: dict\n        :param response: Dictionary response from Vision API with image\n                         properties data.\n\n        :rtype: :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`.\n        :returns: Populated instance of ``ImagePropertiesAnnotation``.\n        \"\"\"\n        raw_colors = response.get('dominantColors', {}).get('colors', ())\n        colors = [ColorInformation.from_api_repr(color)\n                  for color in raw_colors]\n        return cls(colors)\n\n    @property\n    def colors(self):\n        \"\"\"Colors in an image.\n\n        :rtype: list of :class:`~google.cloud.vision.color.ColorInformation`\n        :returns: Populated list of ``ColorInformation``.\n        \"\"\"\n        return self._colors\n\n\nclass Color(object):\n    \"\"\"Representation of RGBA color information.\n\n    :type red: int\n    :param red: The amount of red in the color as a value in the interval\n                [0, 255].\n\n    :type green: int\n    :param green: The amount of green in the color as a value in the interval\n                  [0, 255].\n\n    :type blue: int\n    :param blue: The amount of blue in the color as a value in the interval\n                 [0, 255].\n\n    :type alpha: float\n    :param alpha: The fraction of this color that should be applied to the\n                  pixel.\n    \"\"\"\n    def __init__(self, red, green, blue, alpha):\n        self._red = red\n        self._green = green\n        self._blue = blue\n        self._alpha = alpha\n\n    @classmethod\n    def from_api_repr(cls, response):\n        \"\"\"Factory: construct a ``Color`` from a Vision API response.\n\n        :type response: dict\n        :param response: Color from API Response.\n\n        :rtype: :class:`~google.cloud.vision.color.Color`\n        :returns: Instance of :class:`~google.cloud.vision.color.Color`.\n        \"\"\"\n        red = response.get('red', 0)\n        green = response.get('green', 0)\n        blue = response.get('blue', 0)\n        alpha = response.get('alpha', 0.0)\n\n        return cls(red, green, blue, alpha)\n\n    @property\n    def red(self):\n        \"\"\"Red component of the color.\n\n        :rtype: int\n        :returns: Red RGB value.\n        \"\"\"\n        return self._red\n\n    @property\n    def green(self):\n        \"\"\"Green component of the color.\n\n        :rtype: int\n        :returns: Green RGB value.\n        \"\"\"\n        return self._green\n\n    @property\n    def blue(self):\n        \"\"\"Blue component of the color.\n\n        :rtype: int\n        :returns: Blue RGB value.\n        \"\"\"\n        return self._blue\n\n    @property\n    def alpha(self):\n        \"\"\"Alpha transparency level.\n\n        :rtype: float\n        :returns: Alpha transparency level.\n        \"\"\"\n        return self._alpha\n\n\nclass ColorInformation(object):\n    \"\"\"Representation of color information from API response.\n\n    :type color: :class:`~google.cloud.vision.color.Color`\n    :param color: RGB components of the color.\n\n    :type score: float\n    :param score: Image-specific score for this color. Value in range [0, 1].\n\n    :type pixel_fraction: float\n    :param pixel_fraction: Stores the fraction of pixels the color occupies in\n                           the image. Value in range [0, 1].\n    \"\"\"\n    def __init__(self, color, score, pixel_fraction):\n        self._color = color\n        self._score = score\n        self._pixel_fraction = pixel_fraction\n\n    @classmethod\n    def from_api_repr(cls, response):\n        \"\"\"Factory: construct ``ColorInformation`` for a color found.\n\n        :type response: dict\n        :param response: Color data with extra meta information.\n\n        :rtype: :class:`~google.cloud.vision.color.ColorInformation`\n        :returns: Instance of ``ColorInformation``.\n        \"\"\"\n        color = Color.from_api_repr(response.get('color'))\n        score = response.get('score')\n        pixel_fraction = response.get('pixelFraction')\n\n        return cls(color, score, pixel_fraction)\n\n    @property\n    def color(self):\n        \"\"\"RGB components of the color.\n\n        :rtype: :class:`~google.vision.color.Color`\n        :returns: Instance of ``Color``.\n        \"\"\"\n        return self._color\n\n    @property\n    def score(self):\n        \"\"\"Image-specific score for this color. Value in range [0, 1].\n\n        :rtype: float\n        :returns: Image score for this color.\n        \"\"\"\n        return self._score\n\n    @property\n    def pixel_fraction(self):\n        \"\"\"Stores the fraction of pixels the color occupies in the image.\n\n        :rtype: float\n        :returns: Pixel fraction value in range [0, 1].\n        \"\"\"\n        return self._pixel_fraction\n", "path": "vision/google/cloud/vision/color.py"}]}