Advertisement
DrAungWinHtut

jpegfrs.m

Apr 25th, 2023
1,115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.44 KB | None | 0 0
  1. % JPEG error analysis and digital image forensic
  2.  
  3. % Load the original image
  4. original_image = imread('original_image.jpg');
  5.  
  6. % Apply JPEG compression with quality factor 75
  7. compressed_image = imresize(original_image, 0.5); % Resize the image to reduce its size
  8. imwrite(compressed_image, 'compressed_image.jpg', 'Quality', 75);
  9.  
  10. % Load the compressed image
  11. compressed_image = imread('compressed_image.jpg');
  12.  
  13. % Calculate the mean squared error (MSE) between the original and compressed images
  14. MSE = immse(original_image, compressed_image);
  15.  
  16. % Display the MSE value
  17. fprintf('MSE: %f\n', MSE);
  18.  
  19. % If the MSE value is higher than a threshold, the image may have been tampered with
  20. if MSE > 100
  21.     fprintf('The image may have been tampered with.\n');
  22. else
  23.     fprintf('The image is probably authentic.\n');
  24. end
  25.  
  26. % Apply a digital forensic technique to detect traces of JPEG compression
  27. DCT = dct2(compressed_image); % Calculate the 2D discrete cosine transform (DCT)
  28. abs_DCT = abs(DCT); % Take the absolute value of the DCT coefficients
  29. mean_DCT = mean(abs_DCT(:)); % Calculate the mean of the absolute DCT coefficients
  30.  
  31. % Display the mean value
  32. fprintf('Mean DCT value: %f\n', mean_DCT);
  33.  
  34. % If the mean DCT value is higher than a threshold, the image may have been compressed with JPEG
  35. if mean_DCT > 10
  36.     fprintf('The image was probably compressed with JPEG.\n');
  37. else
  38.     fprintf('The image was probably not compressed with JPEG.\n');
  39. end
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement