Class: Gcloud::Vision::Annotation::Properties::Color
- Inherits:
-
Object
- Object
- Gcloud::Vision::Annotation::Properties::Color
- Defined in:
- lib/gcloud/vision/annotation/properties.rb
Overview
# Color
Color information consisting of RGB channels, score, and fraction of image the color occupies in the image.
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#alpha ⇒ Float
The amount this color that should be applied to the pixel.
-
#blue ⇒ Float
The amount of blue in the color.
-
#green ⇒ Float
The amount of green in the color.
-
#initialize ⇒ Color
constructor
A new instance of Color.
- #inspect ⇒ Object
-
#pixel_fraction ⇒ Float
Stores the fraction of pixels the color occupies in the image.
-
#red ⇒ Float
The amount of red in the color.
- #rgb ⇒ Object
-
#score ⇒ Float
Image-specific score for this color.
-
#to_h ⇒ Hash
Converts object to a hash.
-
#to_hash ⇒ Hash
Converts object to a hash.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Color
Returns a new instance of Color.
143 144 145 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 143 def initialize @gapi = {} end |
Instance Attribute Details
#gapi ⇒ Object
139 140 141 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 139 def gapi @gapi end |
Class Method Details
.from_gapi(gapi) ⇒ Object
238 239 240 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 238 def self.from_gapi gapi new.tap { |f| f.instance_variable_set :@gapi, gapi } end |
Instance Method Details
#alpha ⇒ Float
The amount this color that should be applied to the pixel. A value of 1.0 corresponds to a solid color, whereas a value of 0.0 corresponds to a completely transparent color.
181 182 183 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 181 def alpha @gapi["color"]["alpha"] || 1.0 end |
#blue ⇒ Float
The amount of blue in the color.
170 171 172 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 170 def blue @gapi["color"]["blue"] end |
#green ⇒ Float
The amount of green in the color.
161 162 163 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 161 def green @gapi["color"]["green"] end |
#inspect ⇒ Object
232 233 234 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 232 def inspect "#<Color #{self}>" end |
#pixel_fraction ⇒ Float
Stores the fraction of pixels the color occupies in the image.
205 206 207 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 205 def pixel_fraction @gapi["pixelFraction"] end |
#red ⇒ Float
The amount of red in the color.
152 153 154 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 152 def red @gapi["color"]["red"] end |
#rgb ⇒ Object
185 186 187 188 189 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 185 def rgb red.to_i.to_s(16).rjust(2, "0") + green.to_i.to_s(16).rjust(2, "0") + blue.to_i.to_s(16).rjust(2, "0") end |
#score ⇒ Float
Image-specific score for this color.
196 197 198 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 196 def score @gapi["score"] end |
#to_h ⇒ Hash
Converts object to a hash. All keys will be symbolized.
214 215 216 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 214 def to_h to_hash end |
#to_hash ⇒ Hash
Converts object to a hash. All keys will be symbolized.
223 224 225 226 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 223 def to_hash { red: red, green: green, blue: blue, alpha: alpha, rgb: rgb, score: score, pixel_fraction: pixel_fraction } end |
#to_s ⇒ Object
228 229 230 |
# File 'lib/gcloud/vision/annotation/properties.rb', line 228 def to_s "(colors: #{rgb})" end |