图像中的错误级别分析 [英] Error level analysis in Image

查看:587
本文介绍了图像中的错误级别分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算图像的ELA?我想使用opencv http://fotoforensics.com/tutorial-ela.php

How do I compute ELA for an image? I would like to get similar ELA image using opencv http://fotoforensics.com/tutorial-ela.php

根据本教程,我以95%的jpeg图像质量对图像进行了修复,并使用absDiff方法计算源图像和修复后的图像之间的差异,但我得到的只是零差异.

As per this tutorial, I resaved the image at 95% quality jpeg image and using absDiff method to compute the difference between the source image and the resaved image but all I am getting is zero difference.

是否有任何关于如何计算两个图像之间的差异以便像本教程中的示例图像那样获得错误级别的帮助?

Any help on how to compute the difference between two images so as to obtain the error level just like sample images in the tutorial?

推荐答案

获得类似结果的关键是对压缩率使用可变值,并使用比例因子以使其更易于可视化数据.

The key to achieve a similar result is to use a variable value for the compression rate and a scale factor to make it easier to visualize the data.

这是一个例子:经过一些参数调整( right ):

Here's an example: we have the input image (left) and the processed image after some parameter adjustments (right):

如预期的那样,带有圣诞帽的区域呈现出与图像其余部分不同的压缩率.此结果与 FotoForensics 呈现的结果非常相似:

As expected, the region with the christmas hat presents a different compression rate from the rest of the image. This result is very similar to what FotoForensics presents:

通过对该代码进行一些调整,您可以获得更接近的结果.可以在我的Github上

With a few tweaks on this code you can achieve an even closer result. The source code of this project can be found on my Github:

main.cpp :

#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector> 

// Control
int scale = 15,
    quality = 75;

// Image containers
cv::Mat input_image,
    compressed_image;

void processImage(int, void*)
{
   // Setting up parameters and JPEG compression
   std::vector<int> parameters;
   parameters.push_back(CV_IMWRITE_JPEG_QUALITY);
   parameters.push_back(quality);
   cv::imwrite("temp.jpg", input_image, parameters);

   // Reading temp image from the disk
   compressed_image = cv::imread("temp.jpg");

   if (compressed_image.empty())
   {
      std::cout << "> Error loading temp image" << std::endl;
      exit(EXIT_FAILURE);
   }

   cv::Mat output_image = cv::Mat::zeros(input_image.size(), CV_8UC3);

   // Compare values through matrices
   for (int row = 0; row < input_image.rows; ++row)
   {
    const uchar* ptr_input = input_image.ptr<uchar>(row);
    const uchar* ptr_compressed = compressed_image.ptr<uchar>(row);
    uchar* ptr_out = output_image.ptr<uchar>(row);

        for (int column = 0; column < input_image.cols; column++)
        {
            // Calc abs diff for each color channel multiplying by a scale factor
            ptr_out[0] = abs(ptr_input[0] - ptr_compressed[0]) * scale;
            ptr_out[1] = abs(ptr_input[1] - ptr_compressed[1]) * scale;
            ptr_out[2] = abs(ptr_input[2] - ptr_compressed[2]) * scale;

            ptr_input += 3;
            ptr_compressed += 3;
            ptr_out += 3;
        }
    }

    // Shows processed image
    cv::imshow("Error Level Analysis", output_image);
} 

int main (int argc, char* argv[])
{
   // Verifica se o número de parâmetros necessário foi informado
   if (argc < 2)
   {
     std::cout << "> You need to provide an image as parameter" << std::endl;
     return EXIT_FAILURE;
   }

   // Read the image
   input_image = cv::imread(argv[1]);

   // Check image load
   if (input_image.empty())
   {
      std::cout << "> Error loading input image" << std::endl;
      return EXIT_FAILURE;
   }

   // Set up window and trackbar
   cv::namedWindow("Error Level Analysis", CV_WINDOW_AUTOSIZE);
   cv::imshow("Error Level Analysis", input_image);
   cv::createTrackbar("Scale", "Error Level Analysis", &scale, 100, processImage);
   cv::createTrackbar("Quality", "Error Level Analysis", &quality, 100, processImage);

   // Press 'q' to quit
   while (char(cv::waitKey(0)) != 'q') {};

   return EXIT_SUCCESS;
} 

以下是用于构建此混搭的一些不错的参考:

Here are some nice references that were used to build this mash-up:

  • ELA with HTML5
  • FotoForensics Tutorial
  • Blackhat USA '07 Paper

这篇关于图像中的错误级别分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆