clear;load toucan.mat;T=0.5;
figure,imagesc(X),axis off,title('ORIGINAL'),H=[1 2 1;0 0 0;-1 -2 -1];
YH1=conv2(X(:,:,1),H);YV1=conv2(X(:,:,1),H');Y1=sqrt(YH1.*YH1+YV1.*YV1);
YH2=conv2(X(:,:,2),H);YV2=conv2(X(:,:,2),H');Y2=sqrt(YH2.*YH2+YV2.*YV2);
YH3=conv2(X(:,:,3),H);YV3=conv2(X(:,:,3),H');Y3=sqrt(YH3.*YH3+YV3.*YV3);
Y1(abs(Y1)>T)=1;Y1(abs(Y1)<T)=0;Y(:,:,1)=Y1;
Y2(abs(Y2)>T)=1;Y2(abs(Y2)<T)=0;Y(:,:,2)=Y2;
Y3(abs(Y3)>T)=1;Y3(abs(Y3)<T)=0;Y(:,:,3)=Y3;
figure,imagesc(Y1),colormap(gray),axis off,title('RED EDGES')
figure,imagesc(Y2),colormap(gray),axis off,title('GREEN EDGES')
figure,imagesc(Y3),colormap(gray),axis off,title('BLUE EDGES')

A=[.299,.587,.114;.596,-.275,-.321;.212,-.523,.311];B=inv(A);
Z(:,:,1)=A(1,1)*X(:,:,1)+A(1,2)*X(:,:,2)+A(1,3)*X(:,:,3);
Z(:,:,2)=A(2,1)*X(:,:,1)+A(2,2)*X(:,:,2)+A(2,3)*X(:,:,3);
Z(:,:,3)=A(3,1)*X(:,:,1)+A(3,2)*X(:,:,2)+A(3,3)*X(:,:,3);
ZH=conv2(Z(:,:,1),H,'same');ZV=conv2(Z(:,:,1),H','same');ZE=sqrt(ZH.*ZH+ZV.*ZV);
ZE(abs(ZE)>T)=1;ZE(abs(ZE)<T)=0;
figure,imagesc(ZE),colormap(gray),axis off,title('YIQ EDGES')




