0

I'm currently working on program and I need to automatic perform motion un-blurring on a picture. Currently, I make a for loop for LEN and THETA, guessing from LEN 0:50 and THETA from 1:180. There are plenty of motion un-blurred pictures produce in this way - some correct and some are wrong. Now here is my problem: How do I actually determine which set of parameters yields the one most closest to original photo?

I'm thinking of using pixel comparison. Any idea on this?

Here's a pictorial example of what I generated:

http://dl.dropboxusercontent.com/u/81112742/Capture.JPG

rayryeng
  • 102,964
  • 22
  • 184
  • 193
chris chiang
  • 31
  • 1
  • 4

1 Answers1

2

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://stackoverflow.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.

Community
  • 1
  • 1
rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • If I don't have the original image, then this method cannot be done? My actual project is images with different theta and Len will be given then need to automatic unblur it – chris chiang Aug 26 '14 at 07:25
  • @chrischiang Without a reference image, I can't think of any method that will allow you to choose the most optimum settings to unblur your image. There are metrics that measure quality without a reference image, but those are still in major experimentation and are highly subjective. I can't give you a good answer here. – rayryeng Aug 27 '14 at 03:37