Removing long horizontal/vertical lines from edge image using OpenCV

前端 未结 5 1984
半阙折子戏
半阙折子戏 2020-12-31 12:45

How can I use standard image processing filters (from OpenCV) to remove long horizontal and vertical lines from an image?

The images are B&W so removing means si

5条回答
  •  渐次进展
    2020-12-31 13:16

    How long is "long". Long, as in, lines that run the length of the entire image, or just longer than n pixels?

    If the latter, then you could just use an n+1 X n+1 median or mode filter, and set the corner coefficients to zero, and you'd get the desired effect.

    If you're referring to just lines that run the width of the entire image, just use the memcmp() function against a row of data, and compare it to a pre-allocated array of zeros which is the same length as a row. If they are the same, you know you have a blank line that spans the horizontal length of the image, and that row can be deleted.

    This will be MUCH faster than the element-wise comparisons you are currently using, and is very well explained here:

    Why is memcpy() and memmove() faster than pointer increments?

    If you want to repeat the same operation for vertical lines, just transpose the image, and repeat the operation.

    I know this is more of a system-optimization level approach than an openCV filter like you requested, but it gets the job done fast and safely. You can speed up the calculation even more if you manage to force the image and your empty array to be 32-bit aligned in memory.

提交回复
热议问题