【问题标题】:How to get DCT-coefficients from Jpeg using Visual C# and LibJpeg.Net如何使用 Visual C# 和 LibJpeg.Net 从 Jpeg 获取 DCT 系数
【发布时间】:2015-02-23 03:12:41
【问题描述】:

我需要在量化后获取 DCT 系数数组以进一步更改位(隐写术)。 我的问题是:可以说,我在图片框中有 jpeg 图像或其他任何东西。我怎样才能访问 dct coef。使用 C# 和 LibJpeg.Net 之类的库来制作这张图片?需要一个代码。在整个网络上找不到任何完整和简单的东西。此外,在 LibJpeg.Net 上看不到任何教程。

经过这一步:

    BitMiracle.LibJpeg.Classic.jpeg_decompress_struct oJpegDecompress = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct();
     System.IO.FileStream oFileStreamImage = new System.IO.FileStream(strImagePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
       oJpegDecompress.jpeg_stdio_src(oFileStreamImage);
        oJpegDecompress.jpeg_read_header(true);            
        BitMiracle.LibJpeg.Classic.jvirt_array<BitMiracle.LibJpeg.Classic.JBLOCK>[] JBlock = oJpegDecompress.jpeg_read_coefficients();

我现在应该做什么来编辑 dct 系数?使用.Access()?我怎么用这个?有什么例子吗?

以下:

short[] block = JBlock[c].Access(x, y);

给出这样的错误:“无法将类型 'BitMiracle.LibJpeg.Classic.JBLOCK[][]' 隐式转换为 'short[]'”

此外,在使用类似的东西时,它会在将“BitMiracle.LibJpeg.Classic.JBLOCK[][]”转换为“System.IConvertible”类型时出错。

或者也许有人知道解决我的问题的另一种简单方法?

【问题讨论】:

  • 本网站旨在帮助调试您已经编写的代码,而不是为您提供代码。尝试自己弄清楚一些事情,然后在无法正常工作时发布您所写的内容。
  • 我在问是否有人已经有工作并且能够分享。如果我没有示例、教程和其他有用的东西,我自己什么都想不出来。
  • varrJBlockOrg from this post 似乎与您有关。
  • 我看到了这段代码,我使用了它,但是关于查看 dct 数组和操纵系数的问题仍然存在。也许我只是无法理解所有这些周期以及在这样的地方发生了什么:varrJBlockNew[i].Access(iY + iTileY * iComponentHeigthInBlocks, 1)[0][iX + iTileX * iComponentWidthInBlocks] = varrJBlockOrg[i].Access(iY, 1)[0][iX];,并且无法满足我的需要。

标签: c# jpeg dct


【解决方案1】:

好吧,我想通了。至少,它回答了我的主要问题。

private void button1_Click(object sender, EventArgs e)
        {
            string path = @"D:\067.jpg";
            var img = new Bitmap(path);
            var jo = img.Width; 
            var joj = img.Height;
            BitMiracle.LibJpeg.Classic.jpeg_decompress_struct oJpegDecompress = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct();
            System.IO.FileStream oFileStreamImage = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            oJpegDecompress.jpeg_stdio_src(oFileStreamImage);
            oJpegDecompress.jpeg_read_header(true);
            BitMiracle.LibJpeg.Classic.jvirt_array<BitMiracle.LibJpeg.Classic.JBLOCK>[] JBlock = oJpegDecompress.jpeg_read_coefficients();
            var ll = JBlock[0].Access(0, 1); // accessing the element
            var oo = 5; // its gonna be new value for coefficient
            for (int i = 0; i < 64; i++) // some cycle
            {
                ll[0][i][0] = Convert.ToInt16(oo); // changes
            }
            oJpegDecompress.jpeg_finish_decompress(); 
            oFileStreamImage.Close();
            /////
            System.IO.FileStream objFileStreamMegaMap = System.IO.File.Create(@"D:\068.jpg");
            BitMiracle.LibJpeg.Classic.jpeg_compress_struct oJpegCompress = new BitMiracle.LibJpeg.Classic.jpeg_compress_struct();
            oJpegCompress.jpeg_stdio_dest(objFileStreamMegaMap);
            oJpegDecompress.jpeg_copy_critical_parameters(oJpegCompress);
            oJpegCompress.Image_height = joj;
            oJpegCompress.Image_width = jo;
            oJpegCompress.jpeg_write_coefficients(JBlock);          
            oJpegCompress.jpeg_finish_compress();
            objFileStreamMegaMap.Close();
            oJpegDecompress.jpeg_abort_decompress();
            oFileStreamImage.Close();
        }

有点马虎,但还是,只是测试...... 使用了here的一些代码

就像你在控制台中看到的那样,输出图像中 0->m_buffer->0->i 下的每个第 0 个元素将等于 5

向我致敬。

【讨论】:

    【解决方案2】:

    我在编写 JPEG 库以验证其正确性时已完成此操作。您只需获取 LIBJPEG 的源代码;确定它在哪里执行您感兴趣的功能(有点困难,因为代码很复杂);设置断点或返回那里。

    【讨论】:

      猜你喜欢
      • 2011-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-27
      相关资源
      最近更新 更多