for i=1:1:34
for j=1:1:99
if(img(i,j)-img(i+1,j)>40)
axmag(i,j)=abs(img(i,j)-img(i+1,j));
ax(i,j)=1;
elseif(img(i,j)-img(i+1,j)<-40)
axmag(i,j)=abs(img(i,j)-img(i+1,j));
ax(i,j)=1;
end
if(img(i,j)-img(i,j+1)>40)
aymag(i,j)=abs(img(i,j)-img(i,j+1));
ay(i,j)=1;
elseif(img(i,j)-img(i,j+1)<-40)
aymag(i,j)=abs(img(i,j)-img(i,j+1));
ay(i,j)=1;
end