% Generates a simple image: 2 gray levels separated by an oblique line
% Jose A. Rodriguez-Serrano 2002

outputfilename='/home/josear/images/2tissues.w'; 
imageside = 200;
% Both gray levels
gl1=0;
gl2=100;
% Some important params for the separation line
ya=150;
yb=50;
xa=1;
xb=imageside;
image=zeros(imageside);
for i=1:imageside,
  % Compute separation line equation
  m = (ya-yb)/(xa-xb);
  b = ya-m*xa;
  %Compute line value for current i
  lvalue = round(m*i+b);
  % And draw according to the correct pattern
  for j=1:lvalue,
    image(i,j) = gl1;
  end  
  for j=lvalue+1:imageside,
    image(i,j)=gl2;
  end  
end  
% Write image!
fid=fopen(outputfilename, 'w+');
fwrite (fid, image, 'short');
fclose (fid);
% Show image
imshow (mat2gray (image));
clear image outputfilename gl1 gl2 xa ya xb yb m b i j lvalue fid

    Source: geocities.com/pretabbed/code_matlab

               ( geocities.com/pretabbed)