DEGRADE an image using a PSF spatially invariant h (Gaussian low-pass filter with normalized cutoff frequency fc, 0<fc<1 -1 is the Nyquist frequency-). Also, it includes isotropic colored noise in the 0<[f1,f2]<1 band of a given variance. NOTE THAT: In order to allow frequencies higher than fc, there is a parameter 'val' in the frequency response. Since we are normlaizing the PSF in order to keep the DC component, the value of the frequency response for high frequencies is not 'val' but slightly higher. In any case, the function gives back H (frequency response of the blurring filter) With val=0 no the normalization is not modified. The degraded image is: Id = conv2(Im,h) + noise; INPUTS: Im: Dergraded image. fcorte: Cutoff PSF frequency val: value to control the response value above fc. [f1 f2]: Vector of frecuencies defining the band of the colored noise. vari: variance of the aditive noise. OUTPUTS: Id: Degraded image PSF: Peak Spread Function H: Frequency response H=abs(freqz2(PSF)); noise: added noise blurred: Blurred image (before adding the noise) USE: [Id,PSF,H,noise,Blurred] = degrade2(Im,fcorte,val,[f1 f2],vari);
0001 % 0002 % DEGRADE an image using a PSF spatially invariant h (Gaussian low-pass filter 0003 % with normalized cutoff frequency fc, 0<fc<1 -1 is the Nyquist frequency-). 0004 % Also, it includes isotropic colored noise in the 0<[f1,f2]<1 band of a 0005 % given variance. 0006 % 0007 % NOTE THAT: In order to allow frequencies higher than fc, there is a parameter 0008 % 'val' in the frequency response. 0009 % Since we are normlaizing the PSF in order to keep the DC component, the value 0010 % of the frequency response for high frequencies is not 'val' but slightly higher. 0011 % In any case, the function gives back H (frequency response of the blurring filter) 0012 % With val=0 no the normalization is not modified. 0013 % 0014 % The degraded image is: 0015 % Id = conv2(Im,h) + noise; 0016 % 0017 % 0018 % INPUTS: 0019 % 0020 % Im: Dergraded image. 0021 % fcorte: Cutoff PSF frequency 0022 % val: value to control the response value above fc. 0023 % [f1 f2]: Vector of frecuencies defining the band of the colored noise. 0024 % vari: variance of the aditive noise. 0025 % 0026 % OUTPUTS: 0027 % 0028 % Id: Degraded image 0029 % PSF: Peak Spread Function 0030 % H: Frequency response H=abs(freqz2(PSF)); 0031 % noise: added noise 0032 % blurred: Blurred image (before adding the noise) 0033 % 0034 % USE: 0035 % [Id,PSF,H,noise,Blurred] = degrade2(Im,fcorte,val,[f1 f2],vari); 0036 0037 function [Id,PSF,H,noise,Blurred]=degrade2(Im,fc,Val_min,lim_frec,vari); 0038 0039 N=size(Im); 0040 0041 Numpf = 11; 0042 0043 [f1,f2] = freqspace(Numpf,'meshgrid'); 0044 Hd = ones(Numpf); 0045 r = sqrt(f1.^2 + f2.^2); 0046 Hd(r>fc) = Val_min; 0047 win = fspecial('gaussian',Numpf,2); 0048 win = win ./ max(win(:)); 0049 PSF = fwind2(Hd,win); 0050 PSF=PSF/sum(sum(PSF)); 0051 H=abs(freqz2(PSF)); 0052 0053 Im2 = ampliaconborde(Im,10); 0054 0055 Im2 = conv2(Im2,PSF,'same'); 0056 0057 Blurred = Im2(11:11+N(1)-1,11:11+N(2)-1); 0058 0059 [f1,f2] = freqspace(N,'meshgrid'); 0060 r = sqrt(f1.^2 + f2.^2); 0061 Hruido=(r>=lim_frec(1))&(r<=lim_frec(2)); 0062 tfruido=Hruido.*exp(sqrt(-1)*2*pi*rand(N)); 0063 ruido=real(ifft2(fftshift(tfruido))); 0064 varruido=var(ruido(:)); 0065 0066 noise = sqrt(vari)*ruido/sqrt(varruido); 0067 0068 Id = Blurred + noise;