gpt4 book ai didi

opencv - 图像中的错误级别分析

转载 作者:太空宇宙 更新时间:2023-11-03 20:56:06 28 4
gpt4 key购买 nike

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

按照本教程,我以 95% 质量的 jpeg 图像重新保存图像,并使用 absDiff 方法计算源图像和重新保存图像之间的差异,但我得到的结果是零差异。

关于如何计算两个图像之间的差异以获得错误级别的任何帮助,就像教程中的示例图像一样?

最佳答案

获得类似结果的关键是使用压缩率的可变值和比例因子,以便更容易地可视化数据。

这是一个示例:我们有输入图像()和一些参数调整后的处理图像():

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

通过对这段代码进行一些调整,您可以获得更接近的结果。这个项目的源代码可以找到on my Github :

ma​​in.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;
}

这里有一些用于构建此混搭的不错的引用:

关于opencv - 图像中的错误级别分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21464229/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com