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

3 Ansichten (letzte 30 Tage)
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 Kommentare
Kartikeya
Kartikeya am 13 Nov. 2023
@DGM Like suppose if i take original image and final output how much difference happened by pixel by pixel i want to get

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Drishti
Drishti am 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:
I hope this resolves the query.

Community Treasure Hunt

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

Start Hunting!

Translated by