【问题标题】:Implementation of Bit-Plane Decomposition c#位平面分解c#的实现
【发布时间】:2018-04-23 20:30:47
【问题描述】:

尝试实现 bpcs 隐写术,我遇到的第一个问题是位平面分解。 我创建了一个方法(GetBitPlaneRed)(仅适用于红色,但其他颜色似乎相同),它根据原始位图和位平面索引(从 1 到 8)创建红白位图.

    private static int GetBit(byte b, int bitIndex)
    {
        return  (b >> bitIndex) & 0x01;
    }


    private static Bitmap GetBitPlaneRed(Bitmap bitmap, int bitPlaneIndex)
    {
        Bitmap newBitmap = new Bitmap(bitmap.Width, bitmap.Height);

        for (int i = 0; i < bitmap.Width; i++)
        {
            for (int j = 0; j < bitmap.Height; j++)
            {
                Color currColor = bitmap.GetPixel(i, j);

                int bit = GetBit(currColor.R, bitPlaneIndex);

                Color newColor = Color.FromArgb(255, 255 * bit, 255 * bit);

                newBitmap.SetPixel(i, j, newColor);
            }
        }
        return newBitmap;
    }

似乎,它适用于 MSB(最高有效位),但对于其他位平面,它不是那么正确。这里有一些结果图片,我必须与正确的图片进行比较。

[编辑]“正确的结果”来自科学articleEiji Kawaguchi 撰写的关于 BPCS 隐写术,所以我相信这个来源。此外,似乎错误在于我保存位平面图像的方式,所以我在这里添加了一些代码和平,我保存我的位平面图像。 还添加了原始图像。

    private static void SaveBitPlanes()
    {           
        string filePath = "monalisa.jpg";            
        string ext = System.IO.Path.GetExtension(filePath);

        Bitmap bitmap = new Bitmap(filePath);
        ImageFormat imageFormat = bitmap.RawFormat;

        for (int i = 0; i < 8; i++)
        {
            Bitmap newBitmap = GetBitPlaneRed(bitmap, i);  
            newBitmap.Save("bitPlaneRed" + i + ext, imageFormat);
        }           
    }

原图:

我的MSB平面结果:

我的位平面 #3 的结果:

我的位平面 #7 的结果:

正确的结果:

如果有任何帮助或建议,我将不胜感激。

【问题讨论】:

  • 我认为您唯一的问题是您使用的是原始源的 jpeg 重新保存,而不是实际源...您的位平面 #7 图像清楚地显示了实际区域上的 jpeg 伪影纯黑色,并且您显示的“正确结果”图像中有明显的 jpeg 压缩损坏迹象。
  • 代码存在运算符优先级错误,请改用(1 &lt;&lt; (bitIndex - 1))
  • @HansPassant 感谢您发现这个错误,但不幸的是,这并没有改变任何事情
  • Arithmetic operations have higher priority than bitshifts,所以括号不会改变任何东西。你能提供a minimal, complete and verifiable example 来复制你的问题吗?我们需要您加载的原始图像,以及对您不满意的特定位平面的函数调用。您从哪里得到这些声称正确的结果?
  • @Reti43 根据您的建议编辑了帖子。

标签: c# image algorithm image-processing


【解决方案1】:

在这个问题存在期间我发现了所有重要的东西。

  • 我在主帖中写的所有代码都是正确的。
  • 图像差异与 jpeg 压缩或任何 其他压缩。它适用于任何文件格式。
  • 为什么我的结果与那些结果不相似 文章是我使用了低质量的图像作为来源。我试过之后 其他一些高质量的图像,结果看起来很漂亮 详细。
  • 感谢大家帮助我弄清楚所有这些要点!

【讨论】:

    猜你喜欢
    • 2015-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多