for i=1:size(ag,3)
HEag(:,:,i) = histeq(ag(:,:,i));
end

Wag = HEag;