MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / HSVToRGB

Function HSVToRGB

tensorflow/compiler/tf2xla/kernels/image_ops.cc:71–94  ·  view source on GitHub ↗

Converts 'input' from HSV format to RGB format.

Source from the content-addressed store, hash-verified

69
70// Converts 'input' from HSV format to RGB format.
71std::array<xla::XlaOp, 3> HSVToRGB(xla::XlaBuilder* b,
72 const std::array<xla::XlaOp, 3>& hsv,
73 DataType dtype) {
74 xla::XlaOp hue = hsv[0];
75 xla::XlaOp saturation = hsv[1];
76 xla::XlaOp value = hsv[2];
77 auto zero = XlaHelpers::Zero(b, dtype);
78 auto one = XlaHelpers::FloatLiteral(b, dtype, 1.0);
79 auto two = XlaHelpers::FloatLiteral(b, dtype, 2.0);
80 auto three = XlaHelpers::FloatLiteral(b, dtype, 3.0);
81 auto four = XlaHelpers::FloatLiteral(b, dtype, 4.0);
82 auto six = XlaHelpers::FloatLiteral(b, dtype, 6.0);
83
84 auto dh = xla::Mul(hue, six);
85 auto dr = xla::Clamp(zero, xla::Sub(xla::Abs(xla::Sub(dh, three)), one), one);
86 auto dg = xla::Clamp(zero, xla::Sub(two, xla::Abs(xla::Sub(dh, two))), one);
87 auto db = xla::Clamp(zero, xla::Sub(two, xla::Abs(xla::Sub(dh, four))), one);
88 auto one_minus_s = xla::Sub(one, saturation);
89
90 auto red = xla::Mul(xla::Add(one_minus_s, xla::Mul(saturation, dr)), value);
91 auto green = xla::Mul(xla::Add(one_minus_s, xla::Mul(saturation, dg)), value);
92 auto blue = xla::Mul(xla::Add(one_minus_s, xla::Mul(saturation, db)), value);
93 return {red, green, blue};
94}
95
96class RGBToHSVOp : public XlaOpKernel {
97 public:

Callers 3

CompileMethod · 0.70
CompileMethod · 0.70
CompileMethod · 0.70

Calls 7

FloatLiteralFunction · 0.85
ZeroFunction · 0.50
MulFunction · 0.50
ClampFunction · 0.50
SubFunction · 0.50
AbsFunction · 0.50
AddClass · 0.50

Tested by

no test coverage detected