去除水印

Remove watermark

我正在尝试使用 OCR 翻译图像,但水印挡住了我的路。有没有办法去除图片的橙色水印或至少使它更亮?也可以批量处理(文件夹中的所有图像)。

这是去除水印后的效果图。 只是例子。

你可能只是阈值,但切断低像素数文本的平滑实际上会严重损害后续的 ocr。因此,我创建了一个可以消除水印的蒙版,然后将其应用于原始图像(这也会拉出灰色文本边界)。另一个有用的技巧是使用红色通道,因为水印在红色上最饱和 ~245)。请注意,这需要 opencv 和 c++17

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <Windows.h>
#include <string>
#include <filesystem>

namespace fs = std::filesystem;

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    bool debugFlag = true;
    std::string path = "C:/Local Software/voyDICOM/resources/images/wmTesting/";
    for (const auto& entry : fs::directory_iterator(path))
    {
        std::string  fileName = entry.path().string();
        Mat original = imread(fileName, cv::IMREAD_COLOR);
        if (debugFlag) { imshow("original", original); }
        Mat inverted;
        bitwise_not(original, inverted);
        std::vector<Mat> channels;
        split(inverted, channels);

        for (int i = 0; i < 3; i++)
        {
            if (debugFlag) { imshow("chan" + std::to_string(i), channels[i]); }
        }

        Mat bwImg;
        cv::threshold(channels[2], bwImg, 50, 255, cv::THRESH_BINARY);
        if (debugFlag) { imshow("thresh", bwImg); }

        Mat outputImg;
        inverted.copyTo(outputImg, bwImg);

        bitwise_not(outputImg, outputImg);
        if (debugFlag) { imshow("output", outputImg); }

        if (debugFlag) { waitKey(0); }
        else { imwrite(fileName, outputImg); }
    }
}

图像显示掩蔽相对于阈值的好处:

参考:How can I get the list of files in a directory using C or C++?


编辑(添加调试标志以帮助调试),调试输出示例: