且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

确定用于在MATLAB中对运动模糊图像进行模糊处理的正确参数

更新时间:2022-10-18 21:00:27

If you have access to the original clean image, I would compute the Peak Signal to Noise Ratio (PSNR) for all of the images you have generated, then choose the one with the highest PSNR. Amro posted a very nice post on how to compute this for images and can be found here: https://***.com/a/16265510/3250829

However, for self-containment, I'll post the code to do it here. Supposing that your original image is stored in the variable I, and supposing your reconstructed (un-blurred) image is stored in the variable K. Therefore, to calculate the PSNR, you would need to calculate the Mean Squared Error first, then use it to calculate the PSNR. In other words:

mse = mean(mean((im2double(I) - im2double(K)).^2, 1), 2);
psnr = 10 * log10(1 ./ mean(mse,3));

The equations for MSE and PSNR are:

Source: Wikipedia


As such, to use this in your code, your for loops should look something like this:

psnr_max = -realmax;
for LEN = 0 : 50
    for THETA = 1 : 180
        %// Unblur the image
        %//...
        %//...
        %// Compute PSNR
        mse = mean(mean((im2double(I) - im2double(K)).^2, 1), 2);
        psnr = 10 * log10(1 ./ mean(mse,3));
        if (psnr > psnr_max) %// Get largest PSNR and get the
            LEN_final = LEN; %// parameters that made this so
            THETA_final = THETA;
            psnr_max = psnr;
        end
    end
end


This loop will go through each pair of LEN and THETA, and LEN_final, THETA_final will be those parameters that gave you the best reconstruction (un-blurring) of the image.