r/learncpp • u/Moschte09 • Aug 03 '20
Lookup table for position
Hello. I am trying to speed up my program. I need to iterate over an image for multiple times. For every pixel, I need to calculate if it is in a specified region. If not then I ignore the pixel. The region is defined at the start and does not change.
My code looks like:
for (auto i = 0; i < source_image.rows; ++i)
{
for (auto j = 0; j < source_image.cols; ++j)
{
if (!in_region(i, j)) continue;
// ...
}
}
I thought this could be sped up by using a lookup table. But it does not improve the execution time so I think my implementation was not right. I tried to create an image with the same shape and instead of colors, I save a 1 if it is in the region and a 0 if not.
1
Upvotes
View all comments
Show parent comment
1
u/Moschte09 Aug 03 '20 edited Aug 03 '20
I am using OpenCV. But I need to calculate a value for each pixel in the region. So, for each pixel I call the function XY if the pixel is in the region. But I don‘t know how I could do this with an alternative way.
Edit: I know I can use ROI but my regions are circles. So for example I have one big circle with a radius of 20. Then i split this into four smaller circles. My first region would be a circle with a radius 0 <= r < 5. The second one a circle with radius 5 <= r < 10 and so on.