function [Id,PSF] = apply_degradetion(Im,Type,varargin); INPUT: Im: Image to be degraded Type: type of degradation to be applied. Implemented degratations are: 'gn' : gaussian white noise (iid) 'blur_gn': blur plus gaussian white noise 'jpeg' : jpeq compression 'salt_pepper': salt and pepper noise The number of arguments depends on the type of degradation: gn: the variance of the noise. blur_gn: the normalized frequency cut (0-1) of the low-pass filter an the variance of the noise jpeg: the quality of the compression (see imwrite) salt_pepper: noise density (see imnoise) OUTPUT: Id: degraded image PSF: the point spread function of the blurring (this can be just a delta function if there is no blurring). LocalRestorationToolbox See J. Gutierrez, F. Ferri and J. Malo '' IEEE TIP Jan. 2006
0001 % function [Id,PSF] = apply_degradetion(Im,Type,varargin); 0002 % 0003 % INPUT: 0004 % Im: Image to be degraded 0005 % Type: type of degradation to be applied. Implemented degratations are: 0006 % 'gn' : gaussian white noise (iid) 0007 % 'blur_gn': blur plus gaussian white noise 0008 % 'jpeg' : jpeq compression 0009 % 'salt_pepper': salt and pepper noise 0010 % The number of arguments depends on the type of degradation: 0011 % gn: the variance of the noise. 0012 % blur_gn: the normalized frequency cut (0-1) of the low-pass filter an the variance of the noise 0013 % jpeg: the quality of the compression (see imwrite) 0014 % salt_pepper: noise density (see imnoise) 0015 % 0016 % OUTPUT: 0017 % Id: degraded image 0018 % PSF: the point spread function of the blurring (this can be just a delta function if there is no blurring). 0019 % 0020 % LocalRestorationToolbox 0021 % See J. Gutierrez, F. Ferri and J. Malo '' IEEE TIP Jan. 2006 0022 % 0023 function [degraded,PSF] = apply_degradetion(Im,type,varargin); 0024 0025 if (strcmpi(type,'gn')) 0026 0027 fc = 2; 0028 Val_min = 0.001; 0029 0030 lim_frec = [0 3]; 0031 0032 variance = varargin{1} 0033 0034 [degraded,PSF,H,noise,Blurred]=degrade(Im,fc,Val_min,lim_frec,variance); 0035 0036 elseif (strcmpi(type,'blur_gn')) 0037 0038 fc = varargin{1}; 0039 Val_min = 0.001; 0040 0041 lim_frec = [0 3]; 0042 0043 variance = varargin{2}; 0044 0045 [degraded,PSF,H,noise,Blurred]=degrade(Im,fc,Val_min,lim_frec,variance); 0046 0047 elseif (strcmpi(type,'jpeg')) 0048 0049 PSF = zeros(11); 0050 PSF(6,6)=1; 0051 0052 imwrite(Im/255,'tmp.jpg','Quality',varargin{1}); 0053 degraded = imread('tmp.jpg'); 0054 0055 elseif (strcmpi(type,'salt_pepper')) 0056 0057 PSF = zeros(11); 0058 PSF(6,6)=1; 0059 degraded = imnoise(Im/255,'salt & pepper', varargin{1}); 0060 degraded = degraded*255; 0061 else 0062 error('The requested degradation is not implemented'); 0063 end 0064 0065 degraded = double(degraded);