Skip to content

Commit 5faa80b

Browse files
committed
Revert changes
1 parent 5845ea2 commit 5faa80b

File tree

1 file changed

+0
-83
lines changed

1 file changed

+0
-83
lines changed

modules/core/test/image-with-dataset/testColorConversion.cpp

-83
Original file line numberDiff line numberDiff line change
@@ -1451,89 +1451,6 @@ TEST_CASE("RGB to HSV conversion", "[image_conversion]")
14511451
}
14521452
}
14531453

1454-
// Inspired from https://stackoverflow.com/questions/17892346/how-to-convert-rgb-yuv-rgb-both-ways
1455-
void YUVToRGB(double Y, double U, double V, double &R, double &G, double &B)
1456-
{
1457-
Y -= 16;
1458-
U -= 128;
1459-
V -= 128;
1460-
R = 1.164 * Y + 1.596 * V;
1461-
G = 1.164 * Y - 0.391 * U - 0.813 * V;
1462-
B = 1.164 * Y + 2.018 * U;
1463-
1464-
R = R < 0. ? 0. : R;
1465-
G = G < 0. ? 0. : G;
1466-
B = B < 0. ? 0. : B;
1467-
R = R > 255. ? 255. : R;
1468-
G = G > 255. ? 255. : G;
1469-
B = B > 255. ? 255. : B;
1470-
}
1471-
1472-
void RGBToYUV(const double R, const double G, const double B, double &Y, double &U, double &V)
1473-
{
1474-
Y = 0.257 * R + 0.504 * G + 0.098 * B + 16;
1475-
U = -0.148 * R - 0.291 * G + 0.439 * B + 128;
1476-
V = 0.439 * R - 0.368 * G - 0.071 * B + 128;
1477-
1478-
Y = Y < 0. ? 0. : Y;
1479-
U = U < 0. ? 0. : U;
1480-
V = V < 0. ? 0. : V;
1481-
Y = Y > 255. ? 255. : Y;
1482-
U = U > 255. ? 255. : U;
1483-
V = V > 255. ? 255. : V;
1484-
}
1485-
1486-
TEST_CASE("YUV to RGB conversion", "[image_conversion]")
1487-
{
1488-
std::vector< std::vector<unsigned char> > rgb_truth;
1489-
rgb_truth.push_back({ 0, 0, 0 });
1490-
rgb_truth.push_back({ 255, 255, 255 });
1491-
rgb_truth.push_back({ 255, 0, 0 });
1492-
rgb_truth.push_back({ 0, 255, 0 });
1493-
rgb_truth.push_back({ 0, 0, 255 });
1494-
rgb_truth.push_back({ 255, 255, 0 });
1495-
rgb_truth.push_back({ 0, 255, 255 });
1496-
rgb_truth.push_back({ 255, 0, 255 });
1497-
rgb_truth.push_back({ 128, 128, 128 });
1498-
rgb_truth.push_back({ 128, 128, 0 });
1499-
rgb_truth.push_back({ 128, 0, 0 });
1500-
rgb_truth.push_back({ 0, 128, 0 });
1501-
rgb_truth.push_back({ 0, 128, 128 });
1502-
rgb_truth.push_back({ 0, 0, 128 });
1503-
rgb_truth.push_back({ 128, 0, 128 });
1504-
1505-
size_t size = rgb_truth.size();
1506-
1507-
std::vector< std::vector<double> > yuv_truth;
1508-
for (size_t i = 0; i < size; ++i) {
1509-
double y, u, v;
1510-
double r = static_cast<double>(rgb_truth[i][0]);
1511-
double g = static_cast<double>(rgb_truth[i][1]);
1512-
double b = static_cast<double>(rgb_truth[i][2]);
1513-
RGBToYUV(r, g, b, y, u, v);
1514-
yuv_truth.push_back({ y, u, v });
1515-
}
1516-
SECTION("RGB -> YUV")
1517-
{
1518-
for (size_t i = 0; i < size; ++i) {
1519-
unsigned char r, g, b;
1520-
unsigned char y = static_cast<unsigned char>(yuv_truth[i][0]);
1521-
unsigned char u = static_cast<unsigned char>(yuv_truth[i][1]);
1522-
unsigned char v = static_cast<unsigned char>(yuv_truth[i][2]);
1523-
1524-
std::cout << "rgb truth (uchar ): " << (int)rgb_truth[i][0] << " " << (int)rgb_truth[i][1] << " " << (int)rgb_truth[i][2] << std::endl;
1525-
std::cout << "yuv truth (double): " << yuv_truth[i][0] << " " << yuv_truth[i][1] << " " << yuv_truth[i][2] << std::endl;
1526-
std::cout << "yuv truth (uchar ): " << (int)y << " " << (int)u << " " << (int)v << std::endl;
1527-
vpImageConvert::YUVToRGB(y, u, v, r, g, b);
1528-
std::cout << "rgb (uchar ): " << (int)r << " " << (int)g << " " << (int)b << std::endl;
1529-
double r_truth, g_truth, b_truth;
1530-
YUVToRGB(yuv_truth[i][0], yuv_truth[i][1], yuv_truth[i][2], r_truth, g_truth, b_truth);
1531-
std::cout << "rgb (double): " << r_truth << " " << g_truth << " " << b_truth << std::endl;
1532-
1533-
}
1534-
}
1535-
}
1536-
15371454
int main(int argc, char *argv[])
15381455
{
15391456
Catch::Session session; // There must be exactly one instance

0 commit comments

Comments
 (0)