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