Needed Full code for Color to grayscale and Wiener Algorithm for deblurring and differences between Original and Final Deblurred

Needed Full code for Color to grayscale and Wiener Algorithm for deblurring and differences between Original and Final Deblurred
% Load the original image
Ioriginal = imread('greyface1.jpg');
imshow(Ioriginal);
title('Original Image');
% Define the motion blur point spread function (PSF)
PSF = fspecial('motion', 21, 11);
% Convert the original image to double
Ioriginal = im2double(Ioriginal);
% Apply motion blur to the original image
blurred = imfilter(Ioriginal, PSF, 'conv', 'circular');
imshow(blurred);
title('Blurred Image');
% Restore the blurred image without noise
wnr1 = deconvwnr(blurred, PSF);
% Calculate the absolute differences between the original and restored images
err = imabsdiff(Ioriginal, wnr1);
% Display the restored image
imshow(wnr1);
title('Restored Blurred Image');
% Create a histogram of the absolute differences
figure;
histogram(err);
title('Histogram of Absolute Differences');

6 Comments

We are not here to provide full programs for you.
If you have bugs in your code, describe the error message and we will assist you in understanding the error message.
@Walter Roberson I have directly did from Grayscale image but first i need to Convert RGB to Grayscale and then at last i need to find the difference like how much image data loss happened like that.
For RGB to grayscale, decide what you mean by "gray". This answer covers most things.
IPT rgb2gray() and im2gray() use BT601 luma, if that's what you want.
I don't have a toolbox-independent replacement for deconvwnr(), though you can open it and figure out how it works.
@DGM Like suppose if i take original image and final output how much difference happened by pixel by pixel i want to get

Sign in to comment.

Answers (1)

Hi Kartikeya,
To convert the RGB image to Grayscale, you can utilize the ‘rgb2gray’ function available in MATLAB.
Refer to the implementation below to convert the RGB image to Grayscale.
% Convert RGB image to grayscale
imgGray = rgb2gray(imgRGB);
For deblurring the image using Wiener Algorithm, you can utilize ‘deconvwnr’ function which deconvolves the image using Wiener filter algorithm.
Following example clarifies the implementation of ‘deconvwnr’ function:
% Deblur the image using Wiener filter
estimatedNSR = 0.01; % Estimated noise-to-signal power ratio
imgDeblurred = deconvwnr(imgBlurred, h, estimatedNSR);
Furthermore, to check the pixel-by-pixel difference in the original image and final output image, you can leverage the ‘imabsdiff’ function and visualize it using a histogram.
You can refer to the below given code snippet:
% Calculate pixel-by-pixel difference
difference = imabsdiff(imgGray, imgDeblurred);
% Plot histogram of differences
figure;
histogram(difference(:), 'BinWidth', 1);
title('Histogram of Pixel Differences');
xlabel('Difference Value');
ylabel('Frequency');
For more information, you can refer to the following MathWorks Documentation:
I hope this resolves the query.

Asked:

on 9 Nov 2023

Answered:

on 24 Sep 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!