Needed Full code for Color to grayscale and Wiener Algorithm for deblurring and differences between Original and Final Deblurred
Show older comments
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
Walter Roberson
on 9 Nov 2023
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.
Kartikeya
on 9 Nov 2023
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.
Kartikeya
on 11 Nov 2023
DGM
on 12 Nov 2023
What loss graph?
Kartikeya
on 13 Nov 2023
Answers (1)
Drishti
on 24 Sep 2024
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:
- ‘rgb2gray’: https://www.mathworks.com/help/releases/R2023b/matlab/ref/rgb2gray.html
- ‘deconvwnr’: https://www.mathworks.com/help/releases/R2023b/images/ref/deconvwnr.html
- ‘imabsdiff’: https://www.mathworks.com/help/releases/R2023b/images/ref/imabsdiff.html
I hope this resolves the query.
Categories
Find more on Deblurring in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


