%This shows how to deblur color images: Deconvolve each RGB component separately.
%No point in transforming from RGB to YIQ: by linearity, get the same answer.
clear;X(1:2:8,1:2:8,1)=1;X(1:2:8,2:2:8,2)=1;X(2:2:8,1:2:8,3)=1;%8X8 checkerboard.
figure,imagesc(X),axis off,title('8X8 original checkerboard image')
%(9X9) point-spread function of radius 5 centered at (5,5):
H(9,9)=0;for I=1:9;for J=1:9;if((I-5)*(I-5)+(J-5)*(J-5)<17);H(I,J)=1/12;end;end;end;
figure,imagesc(H),colormap(gray),axis off,title('9X9 PSF centered at (5,5)')
Y(:,:,1)=conv2(X(:,:,1),H);Y(:,:,2)=conv2(X(:,:,2),H);Y(:,:,3)=conv2(X(:,:,3),H);
%Blurred image is (16X16), where 8+9-1=16.
figure,imagesc(Y),axis off,title('16X16 blurred checkerboard image')
FH=fft2(H,16,16);%Deconvolve each RGB component separately using Eq. (10.15):
XHAT(:,:,1)=real(ifft2(fft2(Y(:,:,1))./FH));
XHAT(:,:,2)=real(ifft2(fft2(Y(:,:,2))./FH));
XHAT(:,:,3)=real(ifft2(fft2(Y(:,:,3))./FH));
%Now linearly scale so 0<XHAT<1 (required by imagesc for color images):
XHAT1=(XHAT-min(min(min(XHAT))))/(max(max(max(XHAT)))-min(min(min(XHAT))));
figure,imagesc(XHAT1),axis off,title('16X16 reconstructed and 0-padded checkerboard image')
