function t = canonical_texton( u )
%CANONICAL_TEXTON Canonical texton
%   t = canonical_texton( u ) computes the canonical texton associated to
%   the texture u.
%
%   The canonical texton has been introduced in the paper
%   "A Compact Representation of Random Phase and Gaussian Textures" 
%   (Agnès Desolneux, Lionel Moisan, Samuel Ronsin), 
%   proceedings of the IEEE ICASSP, pp. 1381-1384, 2012. 
%
%   Notice that the luminance texton is here normalized to be a square
%   root of the covariance for the periodic convolution.
%
%   Author : Arthur Leclaire
%   v. 1.0 (03/2014) : first public version

[M,N,C] = size(u);
if C~=1
    error('u must have one color channel');
end

mu = mean(mean(u,2));
un = 1/sqrt(M*N)*(u-mu);
t = real(ifft2(abs(fft2(un))));

end

