Class: Google::Cloud::Vision::Annotation::Properties::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/vision/annotation/properties.rb

Overview

# Color

Color information consisting of RGB channels, score, and fraction of image the color occupies in the image.

Examples:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

image = vision.image "path/to/logo.jpg"
properties = image.properties

color = properties.colors.first
color.red #=> 247.0
color.green #=> 236.0
color.blue #=> 20.0
color.rgb #=> "f7ec14"
color.alpha #=> 1.0
color.score #=> 0.20301804
color.pixel_fraction #=> 0.0072649573

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeColor

Returns a new instance of Color.



125
126
127
# File 'lib/google/cloud/vision/annotation/properties.rb', line 125

def initialize
  @grpc = nil
end

Instance Attribute Details

#grpcObject



121
122
123
# File 'lib/google/cloud/vision/annotation/properties.rb', line 121

def grpc
  @grpc
end

Class Method Details

.from_grpc(grpc) ⇒ Object

object.



212
213
214
# File 'lib/google/cloud/vision/annotation/properties.rb', line 212

def self.from_grpc grpc
  new.tap { |f| f.instance_variable_set :@grpc, grpc }
end

Instance Method Details

#alphaFloat

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.

Returns:

  • (Float)

    A value in the range [0, 1].



163
164
165
# File 'lib/google/cloud/vision/annotation/properties.rb', line 163

def alpha
  @grpc.color.alpha || 1.0
end

#blueFloat

The amount of blue in the color.

Returns:

  • (Float)

    A value in the interval [0, 255].



152
153
154
# File 'lib/google/cloud/vision/annotation/properties.rb', line 152

def blue
  @grpc.color.blue
end

#greenFloat

The amount of green in the color.

Returns:

  • (Float)

    A value in the interval [0, 255].



143
144
145
# File 'lib/google/cloud/vision/annotation/properties.rb', line 143

def green
  @grpc.color.green
end

#inspectObject



205
206
207
# File 'lib/google/cloud/vision/annotation/properties.rb', line 205

def inspect
  "#<Color #{self}>"
end

#pixel_fractionFloat

Stores the fraction of pixels the color occupies in the image.

Returns:

  • (Float)

    A value in the range [0, 1].



187
188
189
# File 'lib/google/cloud/vision/annotation/properties.rb', line 187

def pixel_fraction
  @grpc.pixel_fraction
end

#redFloat

The amount of red in the color.

Returns:

  • (Float)

    A value in the interval [0, 255].



134
135
136
# File 'lib/google/cloud/vision/annotation/properties.rb', line 134

def red
  @grpc.color.red
end

#rgbObject



167
168
169
170
171
# File 'lib/google/cloud/vision/annotation/properties.rb', line 167

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

#scoreFloat

Image-specific score for this color.

Returns:

  • (Float)

    A value in the range [0, 1].



178
179
180
# File 'lib/google/cloud/vision/annotation/properties.rb', line 178

def score
  @grpc.score
end

#to_hHash

Converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


196
197
198
199
# File 'lib/google/cloud/vision/annotation/properties.rb', line 196

def to_h
  { red: red, green: green, blue: blue, alpha: alpha, rgb: rgb,
    score: score, pixel_fraction: pixel_fraction }
end

#to_sObject



201
202
203
# File 'lib/google/cloud/vision/annotation/properties.rb', line 201

def to_s
  "(colors: #{rgb})"
end