# Deblurring an Image using inverse filtering

199 Ansichten (letzte 30 Tage)
sid101 am 5 Aug. 2020
Kommentiert: RAGNAR SA am 30 Okt. 2022
I am trying to deblur an image using inverse filtering that was blurred using a 25x25 gaussian blur function with sigma = 15. I am extracting the blurred image from a .mat file, displaying it which works correctly.
Next I define my gaussian filter and then compute frequency reponse of the filter. To deblur the image, I divide blurred image by frequency response of the filter and take ifft.
The blurred image displays correctly in figure 1, but figure 2 which should display deblurred image displays all purple. I am trying to keep my code as simple and minimal as possible.
What I am doing wrong here? I will appreciate any hints or inputs
m_blur = images.mandrill_blurred; % Extract the first image
imagesc(m_blur); % display the blurred image
h = fspecial('gaussian',[25 25],15); % 25x25 Gaussian blur function with sigma = 15
hf = fft2(h,size(m_blur,1),size(m_blur,2));
m_deblur = real(ifft2(m_blur)./hf); %inverse filter
figure(2)
imagesc(m_deblur) % Display deblurred image
##### 3 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
RAGNAR SA am 30 Okt. 2022
Are still have the final code for your question? after making the changes with help of Rik and the image analyst.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Rik am 5 Aug. 2020
A bit of data exploration shows that you have quite an outlier in your image:
figure(3),clf(3)
histogram(m_deblur)
set(gca,'YScale','log')
axis([-10 140 0.1 max(ylim)])
Once you replace that with a 0, the automatic scaling should work as expected again. In the code below I went a bit further and set the caxis value manually to something that felt about right.
figure(2)
imagesc(m_deblur) % Display deblurred image
caxis([-0.15 0.15])
So in conlusion: this image is not ready yet.
The reason for this is that you didn't put the blurred image in the Fourier domain yet, so the division doesn't make a lot of sense.
m_blur = images.mandrill_blurred; % Extract the first image
imagesc(m_blur); % display the blurred image
h = fspecial('gaussian',[25 25],15); % 25x25 Gaussian blur function with sigma = 15
hf = fft2(h,size(m_blur,1),size(m_blur,2));
m_deblur = real(ifft2(fft2(m_blur)./hf)); %inverse filter
% ^^^^^ ^ ^
% you forgot this
figure(2)
imagesc(m_deblur) % Display deblurred image
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

Image Analyst am 5 Aug. 2020
You have to do the division in Fourier space. You're doing it in the spatial domain, AFTER you've converted your image back to the spatial domain with ifft2().
m_deblur = real(ifft2(m_blur)./hf);
So if m_blur is the spectrum, then ifft2(m_blur) is the spatial domain image. Then hf is the spectrum of h, so in the line above you're dividing a spatial domain array by a frequency domain array. That doesn't make sense. You need to do it like this (adapt names as needed):
freqImage = fft2(spaceDomainImage);
freqFilter = fft2(spaceDomainFilter);
inverseFilteredImage = freqImage ./ freqFilter; % This is still in the frequency domain.
spatialFilteredImage = ifft2(inverseFilteredImage); % Convert it back to spatial domain.
##### 3 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Image Analyst am 12 Nov. 2020
There is no way that you can do an inverse filter to return that extremely blurred image to anything close to the original.

Melden Sie sich an, um zu kommentieren.

### Kategorien

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!