function [Id,PSF] = apply_degradetion_2(Im,Type,varargin); APPLY_DEGRADATON_2 degrades the input image according to some degradation model. The available degradation models include: * 'wt_gn' : White Gaussian Noise * 'col_gn' : Colored Gaussian Noise * 'blur_wt_gn' : Blur plus white Gaussian Noise * 'blur_col_gn': Blur plus colored Gaussian Noise * 'jpeg' : JPEG degradation due to compression * 'salt_pepper': Salt and Pepper Noise. The number of input arguments depends on the degradation model They have to be included in the described order: * 'wt_gn' : White Gaussian Noise Needs (1) the variance of the noise * 'col_gn' : Colored Gaussian Noise Needs (1) the frequency band limits of the noise [f_min f_max] expresed in normalized units (in the range [0,1], where 1 is the Nyquist frequency). (2) The variance of the noise * 'blur_wt_gn' : Blur plus white Gaussian Noise Needs (1) the cut-off frequency of the blurring operator (in normalized units). (2) the minimum value of the blurring operator (in the range [0,1]). In order to preserve some information of high frequency components, the user can introduce a minimum value for the amplitude of the blurring filter (maximum attenuation factor). Value 0 means that the Gaussian low-pass operator will not be modified. (3) The variance of the noise. * 'blur_col_gn': Blur plus colored Gaussian Noise Needs (1) the frequency band limits of the noise [f_min f_max] expresed in normalized units (in the range [0,1], where 1 is the Nyquist frequency). (2) the cut-off frequency of the blurring operator (in normalized units). (3) the minimum value of the blurring operator (in the range [0,1]). In order to preserve some information of high frequency components, the user can introduce a minimum value for the amplitude of the blurring filter (maximum attenuation factor). Value 0 means that the Gaussian low-pass operator will not be modified. (4) The variance of the noise. * 'jpeg' : JPEG degradation due to compression Needs (1) the quality parameter (see imwrite) * 'salt_pepper': Salt and Pepper Noise. Needs (1) 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). SYNTAX: [degraded,PSF] = apply_degradetion_2(Im,'Degradat_Model',Param1,Param2,...); J. Gutierrez, V. Laparra, G. Camps and J. Malo. "VistaRestoreTools: an image restoration toolbox for Matlab", http://www.uv.es/vista/vistavalencia/software.html
0001 % function [Id,PSF] = apply_degradetion_2(Im,Type,varargin); 0002 % 0003 % APPLY_DEGRADATON_2 degrades the input image according to some 0004 % degradation model. The available degradation models include: 0005 % 0006 % * 'wt_gn' : White Gaussian Noise 0007 % * 'col_gn' : Colored Gaussian Noise 0008 % * 'blur_wt_gn' : Blur plus white Gaussian Noise 0009 % * 'blur_col_gn': Blur plus colored Gaussian Noise 0010 % * 'jpeg' : JPEG degradation due to compression 0011 % * 'salt_pepper': Salt and Pepper Noise. 0012 % 0013 % The number of input arguments depends on the degradation model 0014 % They have to be included in the described order: 0015 % 0016 % * 'wt_gn' : White Gaussian Noise 0017 % Needs (1) the variance of the noise 0018 % * 'col_gn' : Colored Gaussian Noise 0019 % Needs (1) the frequency band limits of the noise 0020 % [f_min f_max] expresed in normalized units 0021 % (in the range [0,1], where 1 is the 0022 % Nyquist frequency). 0023 % (2) The variance of the noise 0024 % 0025 % * 'blur_wt_gn' : Blur plus white Gaussian Noise 0026 % Needs (1) the cut-off frequency of the blurring 0027 % operator (in normalized units). 0028 % (2) the minimum value of the blurring operator 0029 % (in the range [0,1]). 0030 % In order to preserve some information of 0031 % high frequency components, the user can 0032 % introduce a minimum value for the amplitude 0033 % of the blurring filter (maximum attenuation 0034 % factor). 0035 % Value 0 means that the Gaussian low-pass 0036 % operator will not be modified. 0037 % (3) The variance of the noise. 0038 % 0039 % * 'blur_col_gn': Blur plus colored Gaussian Noise 0040 % Needs (1) the frequency band limits of the noise 0041 % [f_min f_max] expresed in normalized units 0042 % (in the range [0,1], where 1 is the 0043 % Nyquist frequency). 0044 % (2) the cut-off frequency of the blurring 0045 % operator (in normalized units). 0046 % (3) the minimum value of the blurring operator 0047 % (in the range [0,1]). 0048 % In order to preserve some information of 0049 % high frequency components, the user can 0050 % introduce a minimum value for the amplitude 0051 % of the blurring filter (maximum attenuation 0052 % factor). 0053 % Value 0 means that the Gaussian low-pass 0054 % operator will not be modified. 0055 % (4) The variance of the noise. 0056 % 0057 % * 'jpeg' : JPEG degradation due to compression 0058 % Needs (1) the quality parameter (see imwrite) 0059 % 0060 % * 'salt_pepper': Salt and Pepper Noise. 0061 % Needs (1) noise density (see imnoise) 0062 % 0063 % OUTPUT: 0064 % Id : degraded image 0065 % PSF: the Point Spread Function of the blurring (this can be just 0066 % a delta function if there is no blurring). 0067 % 0068 % SYNTAX: 0069 % 0070 % [degraded,PSF] = apply_degradetion_2(Im,'Degradat_Model',Param1,Param2,...); 0071 % 0072 % J. Gutierrez, V. Laparra, G. Camps and J. Malo. "VistaRestoreTools: an image 0073 % restoration toolbox for Matlab", http://www.uv.es/vista/vistavalencia/software.html 0074 % 0075 function [degraded,PSF] = apply_degradetion(Im,type,varargin); 0076 0077 warning('off','MATLAB:dispatcher:InexactMatch') 0078 if (strcmpi(type,'wt_gn')) 0079 0080 fc = 3; 0081 Val_min = 0.001; 0082 0083 lim_frec = [0 3]; 0084 0085 variance = varargin{1}; 0086 0087 [degraded,PSF,H,noise,Blurred]=degrade(Im,fc,Val_min,lim_frec,variance); 0088 0089 elseif (strcmpi(type,'col_gn')) 0090 0091 fc = 3; 0092 Val_min = 0.001; 0093 0094 lim_frec = varargin{1}; 0095 0096 variance = varargin{2}; 0097 0098 [degraded,PSF,H,noise,Blurred]=degrade(Im,fc,Val_min,lim_frec,variance); 0099 0100 elseif (strcmpi(type,'blur_wt_gn')) 0101 0102 fc = varargin{1}; 0103 Val_min = varargin{2}; 0104 0105 lim_frec = [0 3]; 0106 0107 variance = varargin{3}; 0108 0109 [degraded,PSF,H,noise,Blurred]=degrade(Im,fc,Val_min,lim_frec,variance); 0110 0111 elseif (strcmpi(type,'blur_col_gn')) 0112 0113 fc = varargin{1}; 0114 Val_min = varargin{2}; 0115 0116 lim_frec = varargin{3}; 0117 0118 variance = varargin{4}; 0119 0120 [degraded,PSF,H,noise,Blurred]=degrade(Im,fc,Val_min,lim_frec,variance); 0121 0122 elseif (strcmpi(type,'jpeg')) 0123 0124 PSF = zeros(11); 0125 PSF(6,6)=1; 0126 0127 imwrite(Im/255,'tmp.jpg','Quality',varargin{1}); 0128 degraded = imread('tmp.jpg'); 0129 0130 elseif (strcmpi(type,'salt_pepper')) 0131 0132 PSF = zeros(11); 0133 PSF(6,6)=1; 0134 degraded = imnoise(Im/255,'salt & pepper', varargin{1}); 0135 degraded = degraded*255; 0136 else 0137 error('The requested degradation is not implemented'); 0138 end 0139 0140 degraded = double(degraded);