Needed Full code for Color to grayscale and Wiener Algorithm for deblurring and differences between Original and Final Deblurred
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Drishti
il 24 Set 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.
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!