SoftwarePractice.org: Home | Courseware | Wiki | Archive

Deblur.m Code

From SoftwarePractice.org

% FUNCTION 'Deblur.m'
% function [bar_out] = deblur(bar)
val = get(deblur_check,'Value');
if (val == 1)
   %convert the image into gray scale image
   I = rgb2gray(bar);
   % Initialized the Gaussian filter that
   % represents a point-spread function, PSF.
   PSF = fspecial('gaussian',7,10);
   % figure(1);imshow(I);title('Original Image');
   % initialized the array 4 pixels less than the PSF
   UNDERPSF = ones(size(PSF)-4);
   % [J1 P1] = deconvblind(I,UNDERPSF);
   % % figure(2);imshow(J1);title('Deblurring with Undersized PSF');
   % initialized the array 4 pixels bigger than the PSF
   OVERPSF = padarray(UNDERPSF,[4 4],'replicate','both');
   % [J2 P2] = deconvblind(I,OVERPSF);
   % % figure(3);imshow(J2);title('Deblurring with Oversized PSF');
   % initialized the INITPSF with the same size of the PSF
   % INITPSF = padarray(UNDERPSF,[2 2],'replicate','both');
   % [J3 P3] = deconvblind(I,INITPSF);
   % % figure(4);imshow(J3);title('Deblurring with INITPSF');
   % Improving the restortion
   % get the global threshold value of the image
   thresh = graythresh(I);
   WEIGHT = edge(I,'canny',thresh); 
   %To widen the area, we use imdilate and pass in a structuring element, se.
   se = strel('disk',2);
   WEIGHT = 1-double(imdilate(WEIGHT,se));
   % Assigned the value 0 to the pixels close to the bordes
   WEIGHT([1:3 end-[0:2]],:) = 0;
   WEIGHT(:,[1:3 end-[0:2]]) = 0;
   % % figure(5);imshow(WEIGHT);title('Weight array');
   % restoredthe image by calling deconvblind with the WEIGHT array and an increased
   % number of iterations (30). 
   % [J P] = deconvblind(I,INITPSF,30,[],WEIGHT);
   % figure(6);imshow(J);title('Deblurred Image-B4 Additionl tec');
   % Using additional constraints on the PSF restoration
   % function, FUN, below returns a modified PSF array which deconvblind uses
   % for the next iteration.
   P1 = 2;
   P2 = 2;
   FUN = @(PSF) padarray(PSF(P1+1:end-P1,P2+1:end-P2),[P1 P2]);
   % Deconvled using modified PSF array
%     [bar_out PF] = deconvblind(bar_out,OVERPSF,30,[],WEIGHT,FUN);
   [bar_out PF] = deconvblind(I,OVERPSF,30,[],WEIGHT,FUN);
%     bar = imread(JF);        %return the deblur image to the next function
%     figure(7);imshow(JF);title('Deblurred Image-Final');
   imshow (bar_out);
%     imwrite(JF,test_deblur,jpg);
%     imshow(JF);   
% else if deblur not checked then display original image
elseif (val == 0)
   bar = imread(name);
   imshow (bar);
end



Back to Deblurring and Noise

Personal tools