I'm using forEach function to access pixels in parallel like so:

// build look up table
cv::Mat dst=cv::imread(argv[1]); //png image 1288*728

unsigned char lut[256];
for (int i = 0; i < 256; i++)
    lut[i] = cv::saturate_cast<uchar>(pow((float)(i / 255.0), fGamma) * 255.0f); //pow: power exponent

    [&lut](cv::Vec3b &pixel, const int* po) -> void
        pixel[0] = lut[(pixel[0])];
        pixel[1] = lut[(pixel[1])];
        pixel[2] = lut[(pixel[2])];

My question is how can I make sure that it is accessing pixels in parallel?

I'm processing RGB images so I would like to make sure it is working in parallel.

And also in lambda expression without forEach function:

std::vector<std::vector<int> > histSum(3, std::vector<int>(256,0));
  [&histSum](cv::Vec3b &pixel, const int* po) -> void

std::vector<int> A(3, 255);
auto A_estim_lambda([&A, rows, cols, &histSum]{

    for (auto index = rows*cols/500; index>histSum[0][A[0]]; --A[0])
         index -= histSum[0][A[0]];
    for (auto index = rows*cols/500; index>histSum[1][A[1]]; --A[1])
         index -= histSum[1][A[1]];
    for (auto index = rows*cols/500; index>histSum[2][A[2]]; --A[2])
         index -= histSum[2][A[2]];

return A;

auto AA=A_estim_lambda();

I'm not sure if this is processing in parallel and also I think I can write the last three loops in one loop but I don't know how or if it is possible.

Do you have any other remarks about my code?


g++ -std=c++1z -Wall -Ofast -march=native test3.cpp -o test3 `pkg-config --cflags --libs opencv`
  • \$\begingroup\$ It's hard to say very much, given that you have no declarations for dst, pow and more. \$\endgroup\$ – Toby Speight Dec 12 '17 at 16:36
  • \$\begingroup\$ @TobySpeight Sorry! I just edited my post \$\endgroup\$ – Ja_cpp Dec 12 '17 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.