Skip to content

Commit

Permalink
Revert changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Apr 8, 2024
1 parent 5845ea2 commit 5faa80b
Showing 1 changed file with 0 additions and 83 deletions.
83 changes: 0 additions & 83 deletions modules/core/test/image-with-dataset/testColorConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,89 +1451,6 @@ TEST_CASE("RGB to HSV conversion", "[image_conversion]")
}
}

// Inspired from https://stackoverflow.com/questions/17892346/how-to-convert-rgb-yuv-rgb-both-ways
void YUVToRGB(double Y, double U, double V, double &R, double &G, double &B)
{
Y -= 16;
U -= 128;
V -= 128;
R = 1.164 * Y + 1.596 * V;
G = 1.164 * Y - 0.391 * U - 0.813 * V;
B = 1.164 * Y + 2.018 * U;

R = R < 0. ? 0. : R;
G = G < 0. ? 0. : G;
B = B < 0. ? 0. : B;
R = R > 255. ? 255. : R;
G = G > 255. ? 255. : G;
B = B > 255. ? 255. : B;
}

void RGBToYUV(const double R, const double G, const double B, double &Y, double &U, double &V)
{
Y = 0.257 * R + 0.504 * G + 0.098 * B + 16;
U = -0.148 * R - 0.291 * G + 0.439 * B + 128;
V = 0.439 * R - 0.368 * G - 0.071 * B + 128;

Y = Y < 0. ? 0. : Y;
U = U < 0. ? 0. : U;
V = V < 0. ? 0. : V;
Y = Y > 255. ? 255. : Y;
U = U > 255. ? 255. : U;
V = V > 255. ? 255. : V;
}

TEST_CASE("YUV to RGB conversion", "[image_conversion]")
{
std::vector< std::vector<unsigned char> > rgb_truth;
rgb_truth.push_back({ 0, 0, 0 });
rgb_truth.push_back({ 255, 255, 255 });
rgb_truth.push_back({ 255, 0, 0 });
rgb_truth.push_back({ 0, 255, 0 });
rgb_truth.push_back({ 0, 0, 255 });
rgb_truth.push_back({ 255, 255, 0 });
rgb_truth.push_back({ 0, 255, 255 });
rgb_truth.push_back({ 255, 0, 255 });
rgb_truth.push_back({ 128, 128, 128 });
rgb_truth.push_back({ 128, 128, 0 });
rgb_truth.push_back({ 128, 0, 0 });
rgb_truth.push_back({ 0, 128, 0 });
rgb_truth.push_back({ 0, 128, 128 });
rgb_truth.push_back({ 0, 0, 128 });
rgb_truth.push_back({ 128, 0, 128 });

size_t size = rgb_truth.size();

std::vector< std::vector<double> > yuv_truth;
for (size_t i = 0; i < size; ++i) {
double y, u, v;
double r = static_cast<double>(rgb_truth[i][0]);
double g = static_cast<double>(rgb_truth[i][1]);
double b = static_cast<double>(rgb_truth[i][2]);
RGBToYUV(r, g, b, y, u, v);
yuv_truth.push_back({ y, u, v });
}
SECTION("RGB -> YUV")
{
for (size_t i = 0; i < size; ++i) {
unsigned char r, g, b;
unsigned char y = static_cast<unsigned char>(yuv_truth[i][0]);
unsigned char u = static_cast<unsigned char>(yuv_truth[i][1]);
unsigned char v = static_cast<unsigned char>(yuv_truth[i][2]);

std::cout << "rgb truth (uchar ): " << (int)rgb_truth[i][0] << " " << (int)rgb_truth[i][1] << " " << (int)rgb_truth[i][2] << std::endl;
std::cout << "yuv truth (double): " << yuv_truth[i][0] << " " << yuv_truth[i][1] << " " << yuv_truth[i][2] << std::endl;
std::cout << "yuv truth (uchar ): " << (int)y << " " << (int)u << " " << (int)v << std::endl;
vpImageConvert::YUVToRGB(y, u, v, r, g, b);
std::cout << "rgb (uchar ): " << (int)r << " " << (int)g << " " << (int)b << std::endl;
double r_truth, g_truth, b_truth;
YUVToRGB(yuv_truth[i][0], yuv_truth[i][1], yuv_truth[i][2], r_truth, g_truth, b_truth);
std::cout << "rgb (double): " << r_truth << " " << g_truth << " " << b_truth << std::endl;

}
}
}

int main(int argc, char *argv[])
{
Catch::Session session; // There must be exactly one instance
Expand Down

0 comments on commit 5faa80b

Please sign in to comment.