function F_reg=txsim_reg(f)
% TXSIM_REG  Regularity texture measure
%	F_reg=txsim_reg(f) computes the regularity measure suggested by
%	H. Tamura, S. Mori, T. Yamawaki, ``Textural Features Corresponding
%	to Visual Perception'', IEEE Trans. Sys., Man, Cyb., June 1978

[M,N]=size(f);
if rem(M,2)~=0 | rem(N,2)~=0
  error('Image dimensions must be even');
end

for i=1:2
  for j=1:2
    f_sub=f((1:M/2)+(i-1)*M/2,(1:N/2)+(j-1)*N/2);
    F_crs(i,j)=txsim_crs(f_sub);
    F_con(i,j)=txsim_con(f_sub);
    [F_dir(i,j),dir]=txsim_dir(f_sub);
    F_lin(i,j)=txsim_lin(f_sub,dir);
  end
end

F_reg=1-(std(F_crs(:)) + std(F_con(:)) + std(F_dir(:)) + std(F_lin(:)));
