1

I am trying to smooth some contour edges so they're not so jagged. So far I have applied a cv::GuassianBlur() to my contours. I found an interesting stackoverflow answer that might help by using a lookup table with LUT to sort of "threshold" my blurred contours.

However I'm not certain on how to properly write a lookup table. I couldn't find any clear examples how. Any help appreciated. Thanks

Community
  • 1
  • 1
user339946
  • 5,961
  • 9
  • 52
  • 97

1 Answers1

3

You should simply pass an std::vector<char> with 256 elements as the lut parameter. Element with index i in this vector will specify the output value for all pixels with value i.

For instance, if you want to threshold the image at 80 (everything above or equal 80 becomes fully white and everything else becomes fully black), you could write something like this:

std::vector<char> lut(256);
for (int i = 0; i < 256; ++i) {
    lut[i] = i >= 80 ? 255 : 0;
}

cv::LUT(src, lut, dst);
Krzysztof Kosiński
  • 4,225
  • 2
  • 18
  • 23