%This reads in a color image, transforms from RGB to YIQ representation,
%and performs Sobel edge detection with threshold T on the Y component only.
clear;X=imread('toucan.jpg');X=double(X);H=[1 2 1;0 0 0;-1 -2 -1];
X=(X-min(min(min(X))))/(max(max(max(X)))-min(min(min(X))));%Scale image to range 0X<1.
T=0.5;%T=threshold-need to set this by trial and error.
%Transform from RGB to YIQ representation:
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);ZV=conv2(Z(:,:,1),H');ZE=sqrt(ZH.*ZH+ZV.*ZV);
ZE(abs(ZE)<T)=0;ZE(abs(ZE)>T)=1;%Note order of these matters!
figure,imagesc(ZE),colormap(gray),axis off,title('YIQ EDGES')
