简体   繁体   English

C#将TIFF JPEG压缩转换为TIFF压缩CCITT4会产生很多噪音

[英]C# Converting TIFF JPEG compression to TIFF CompressionCCITT4 gives a lot of noise

For a OCR engine I need to feed the OCR engine with TIFF files with CCITT4 Compression. 对于OCR引擎,我需要通过CCITT4压缩向OCR引擎提供TIFF文件。 Our scanner outputs TIFF files with JPEG compression. 我们的扫描仪以JPEG压缩输出TIFF文件。 I want to convert these files with C#, using System.Drawing.Imaging. 我想使用System.Drawing.Imaging用C#转换这些文件。

This results in images with a lot of Noise. 这会导致图像带有大量噪点。 How can I reduce the noise? 如何降低噪音?

My Code: 我的代码:

        List<byte[]> fRet = new List<byte[]>();
        ImageCodecInfo fImageCodecInfo = GetEncoderInfo("image/tiff");
        EncoderParameters fEncoderParameters = new EncoderParameters(3);
        fEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
        fEncoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, (int)EncoderValue.ScanMethodNonInterlaced);
        fEncoderParameters.Param[2] = new EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, (int)EncoderValue.RenderNonProgressive);

        //

        Image fOrgTiff = Image.FromStream(pInputTiff);
        Guid objGuid = fOrgTiff.FrameDimensionsList[0];
        FrameDimension objDimension = new FrameDimension(objGuid);
        int frameCount = fOrgTiff.GetFrameCount(objDimension);
        for (int i = 0; i < frameCount; i++)
        {
            MemoryStream ms = new MemoryStream();
            fOrgTiff.SelectActiveFrame(objDimension, i);
            fOrgTiff.Save(ms, fImageCodecInfo, fEncoderParameters);
            ms.Position = 0;
            fRet.Add(ms.GetBuffer());
        }
        return fRet;

As Brannon said, Ccitt4 is a binary format (black/white) so your image is automatically binarized. 正如Brannon所说,Ccitt4是二进制格式(黑白),因此您的图像会自动进行二值化处理。 The documentation says: " The Ccitt3, Ccitt4, and Rle require that the PixelFormat value be set to BlackWhite . Setting the PixelFormat to any other value resets the Compression property value to Default. " 文档说:“ Ccitt3,Ccitt4和Rle要求将PixelFormat值设置为BlackWhite 。将PixelFormat设置为任何其他值会将Compression属性值重置为Default。

You can try to reduce the noise by choosing a better binarization threshold. 您可以尝试通过选择更好的二值化阈值来降低噪声。 You can look at algorithms provided by open-source imaging libraries like AForge.Net or EmguCV . 您可以查看开源映像库(例如AForge.NetEmguCV)提供的算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM