deblurring with wiener filter
10 次查看(过去 30 天)
显示 更早的评论
i m trying to blur an image and then deblur it using a wiener filter that i created. but the blurred image shows unexpected results. it appears the image is getting divided into blocks which are then arranged out o order. what's the issue.?
i am trying to create a wiener filer to blur the image. i use a low pass LSI filter and then add gaussian noise to the blurred image. i assume the expected noise to be white and hence has a flat spectral density.
but before i can create by wiener filter to deblur it, the blurring filter(h) gives unexpected results. i am highlighting in bold letters the portion i assume is creating the problem. will the code not workfor those images for which number of rows is not eual to number of columns? in any case, its not working i guess when rows = columns either......please help me in correcting the error. in my code:
h=low pass filter
Snn=noise power
Suu = signal power
Code:
% function wien2(name,xdim,No,Snn)
%
% name = 'input image' (as in 'lenna.256')
% xdim = x dimension of input image (usually 256 or 512)
% No = Variance of Noise
% Snn = Power Spectral Density of Noise (Assumed White)
%
% This function takes an input image, runs it through a LSI filter h,
% and adds Gaussian noise to it. The MSE between the degraded and
% original image is then calculated. Weiner Filtering is then performed
% (using known h) and the degraded image is restored using
% the filter. The MSE between the restored and original image is then
% calculated and returned. Snn is set to a constant (assumes white noise)
%
No = 80;
% Load and Plot image
pict = imread('C:\Documents and Settings\All Users\Documents\My Pictures\Matlab pics\planet.png');
pict=rgb2gray(pict)
;
[xdim xdim]=size(pict)
;
clf
subplot(221)
imagesc(pict);
colormap(gray);
txt = ' before degradation';
title(txt)
axis square
axis off
***% Create LSI degradation model, need it to be phaseless
hi = 3.5^(-2);
h = zeros(256);
xl = 4;
xh = xdim - xl + 2;
h(1:xl,1:xl) = hi;
h(xh:xdim,1:xl) = hi;
h(1:xl,xh:xdim) = hi;
h(xh:xdim,xh:xdim) = hi;
% Create Gaussian noise, mean = 0, variance comes from input (No)
noise = sqrt(No)*randn(xdim,xdim);
% Run image through LSI Filter and then add noise
dpict = imfilter(pict,h);
dpict =double(dpict)+noise;
% Plot degraded image
subplot(222)
imagesc(dpict);
colormap(gray);
txt = [' with additive Gaussian Noise (mean=0, var=' , num2str(No), ')'];
title(txt)
axis square
axis off
0 个评论
回答(1 个)
Image Analyst
2012-7-14
编辑:Image Analyst
2012-7-14
I don't understand what h is. It's just a big image of zeros with values padded around the edge. What's the point of that? Correcting the line
[xdim xdim]=size(pict) ;
to
[rows columns] = size(pict);
and then fixing up h to use rows and columns won't help the fact that h is weird. Your h is not a low pass filter like you wanted. For one thing it's the same size as the image and should be a lot smaller unless you wanted to totally, and I mean totally, erase all image structure, which is why your left side of the image is nothing but uniform noise.
Try it like this:
clc;
close all;
fontSize = 20;
% Read in a standard MATLAB color demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'peppers.png';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage, []);
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
pict=rgb2gray(rgbImage) ;
[rows columns numberOfColorChannels] = size(pict) ;
subplot(221)
imagesc(pict);
colormap(gray);
caption = 'Before degradation';
title(caption, 'FontSize', fontSize);
axis off
% Create Gaussian noise, mean = 0, variance comes from input (No)
No = 80;
noise = sqrt(No)*randn(rows,columns);
subplot(2, 2, 2);
imshow(noise, []);
title('Pure Noise', 'FontSize', fontSize);
% Run image through low pass filter.
windowSize = 15;
h = ones(windowSize, windowSize)/windowSize^2;
% Blur the image by applying the low pass filter.
blurredImage = imfilter(pict,h);
subplot(2, 2, 3);
imshow(blurredImage, []);
title('Low pass filtered image', 'FontSize', fontSize);
% Add Gaussian noise.
degradedImage =double(blurredImage)+noise;
% Display degraded image
subplot(2, 2, 4)
imagesc(degradedImage);
colormap(gray);
caption = sprintf('Degraded image with additive\nGaussian Noise (mean=0, var=%f)', No);
title(caption, 'FontSize', fontSize);
% axis square
axis off
2 个评论
Image Analyst
2012-7-18
I don't know what that is by that specific name. A simple blurring filter centered in the window (kernel) will not cause any shift in the image.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!