Source code for psnr of image using matlab?

1 answer

Answer

1219990

2026-04-20 12:45

+ Follow

To compute the Peak Signal-to-Noise Ratio (PSNR) of an image in MATLAB, you can use the following code:

<code class="language-matlab">function psnr_value = compute_psnr(original, distorted)

mse = mean((original(:) - distorted(:)).^2); % Calculate Mean Squared Error if mse == 0 psnr_value = Inf; % If no difference, PSNR is infinite else max_pixel = max(original(:)); % Maximum pixel value psnr_value = 10 * log10(max_pixel^2 / mse); % Calculate PSNR end end

</code>

Call the function with two images as inputs: compute_psnr(original_image, distorted_image).

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.