2019-06-06 14:21:15 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (c) 2015-2018 Skymind, Inc.
|
|
|
|
*
|
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the Apache License, Version 2.0 which is available at
|
|
|
|
* https://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.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
//
|
2019-07-20 07:58:44 +02:00
|
|
|
// @author raver119@gmail.com
|
|
|
|
// @author Yurii Shyrma (iuriish@yahoo.com)
|
2019-06-06 14:21:15 +02:00
|
|
|
//
|
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
#include <system/op_boilerplate.h>
|
|
|
|
#include <math/templatemath.h>
|
|
|
|
#include <array/NDArray.h>
|
2019-06-06 14:21:15 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
namespace sd {
|
2019-07-20 07:58:44 +02:00
|
|
|
namespace ops {
|
2019-06-06 14:21:15 +02:00
|
|
|
namespace helpers {
|
2019-07-20 07:58:44 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
void adjustSaturation(sd::LaunchContext* context, const NDArray *input, const NDArray* factorScalarArr, NDArray *output, const int dimC);
|
2019-07-20 07:58:44 +02:00
|
|
|
|
|
|
|
/*
|
2019-06-06 14:21:15 +02:00
|
|
|
template <typename T>
|
2019-07-17 13:02:01 +02:00
|
|
|
static FORCEINLINE _CUDA_HD void rgb_to_hsv(T r, T g, T b, T* h, T* s, T* v) {
|
2020-03-02 10:49:41 +01:00
|
|
|
T vv = sd::math::nd4j_max<T>(r, sd::math::nd4j_max<T>(g, b));
|
|
|
|
T range = vv - sd::math::nd4j_min<T>(r, sd::math::nd4j_min<T>(g, b));
|
2019-06-06 14:21:15 +02:00
|
|
|
if (vv > 0) {
|
|
|
|
*s = range / vv;
|
|
|
|
} else {
|
|
|
|
*s = 0;
|
|
|
|
}
|
|
|
|
T norm = 1.0f / (6.0f * range);
|
|
|
|
T hh;
|
|
|
|
if (r == vv) {
|
|
|
|
hh = norm * (g - b);
|
|
|
|
} else if (g == vv) {
|
|
|
|
hh = norm * (b - r) + 2.0 / 6.0;
|
|
|
|
} else {
|
|
|
|
hh = norm * (r - g) + 4.0 / 6.0;
|
|
|
|
}
|
|
|
|
if (range <= (T) 0.0) {
|
|
|
|
hh = 0;
|
|
|
|
}
|
|
|
|
if (hh < (T) 0.0) {
|
|
|
|
hh = hh + 1.;
|
|
|
|
}
|
|
|
|
*v = vv;
|
|
|
|
*h = hh;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2019-07-17 13:02:01 +02:00
|
|
|
static FORCEINLINE _CUDA_HD void hsv_to_rgb(T h, T s, T v, T* r, T* g, T* b) {
|
2019-06-06 14:21:15 +02:00
|
|
|
T c = s * v;
|
|
|
|
T m = v - c;
|
|
|
|
T dh = h * 6;
|
|
|
|
T rr, gg, bb;
|
|
|
|
int h_category = static_cast<int>(dh);
|
|
|
|
T fmodu = dh;
|
|
|
|
while (fmodu <= (T) 0)
|
|
|
|
fmodu += (T) 2.0f;
|
2019-07-20 07:58:44 +02:00
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
while (fmodu >= (T) 2.0f)
|
|
|
|
fmodu -= (T) 2.0f;
|
2019-07-20 07:58:44 +02:00
|
|
|
|
2020-03-02 10:49:41 +01:00
|
|
|
T x = c * (1. - sd::math::nd4j_abs<T>(fmodu - 1.));
|
2019-06-06 14:21:15 +02:00
|
|
|
switch (h_category) {
|
|
|
|
case 0:
|
|
|
|
rr = c;
|
|
|
|
gg = x;
|
|
|
|
bb = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
rr = x;
|
|
|
|
gg = c;
|
|
|
|
bb = 0;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
rr = 0;
|
|
|
|
gg = c;
|
|
|
|
bb = x;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
rr = 0;
|
|
|
|
gg = x;
|
|
|
|
bb = c;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
rr = x;
|
|
|
|
gg = 0;
|
|
|
|
bb = c;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
rr = c;
|
|
|
|
gg = 0;
|
|
|
|
bb = x;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rr = 0;
|
|
|
|
gg = 0;
|
|
|
|
bb = 0;
|
|
|
|
}
|
2019-07-20 07:58:44 +02:00
|
|
|
|
2019-06-06 14:21:15 +02:00
|
|
|
*r = rr + m;
|
|
|
|
*g = gg + m;
|
|
|
|
*b = bb + m;
|
|
|
|
}
|
2019-07-20 07:58:44 +02:00
|
|
|
*/
|
2019-06-06 14:21:15 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|