Blurry images blurry images in MATLAB
I am currently working on a program and I need to automatically execute motion without blurring the image. I am currently looping for
for LEN
and THETA
, guessing from LEN
0:50
and THETA
from 1:180
. There are many movements that non-blurry images produce in this way - some are correct and some are wrong. Now here's my problem: how can I determine which set of parameters gives the closest thing to the original photo?
I am thinking about using pixel comparison. Any idea on this?
Here's a pictorial example of what I've created:
source to share
If you have access to the original clean image, I would calculate the Peak to Noise Ratio (PSNR) for all the images you create, then select the one with the highest PSNR . Amro has posted a very good post on how to calculate this for images and can be found here: fooobar.com/questions/2156539 / ...
However, for self-limitation, I'll post the code to do this here. Let's say your original image is stored in a variable I
, and let's say your reconstructed (not blurred) image is stored in a variable K
. So to calculate PSNR, you first need to calculate Mean Squared Error and then use it to calculate PSNR. In other words:
mse = mean(mean((im2double(I) - im2double(K)).^2, 1), 2);
psnr = 10 * log10(1 ./ mean(mse,3));
Equations for MSE and PSNR:
Source: Wikipedia
So, to use this in your code, your loops for
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 cycle will go through each pair LEN
and THETA
, a LEN_final
, THETA_final
will be the parameters that gave you the best reconstruction (blurring) of the image.
source to share