function [trn_img, tst_img, trn_lbl, tst_lbl] = load_mnist(parms)
%
% Load two digits from MNIST data 
%
% (C) Gal Chechik 2005

  [parms,do_force]   = take_from_struct(parms,'do_force', 0);
  [parms,frac]       = take_from_struct(parms,'frac', 0.1);
  [parms,n_trn]      = take_from_struct(parms,'n_trn',1000);
  [parms,n_tst]      = take_from_struct(parms,'n_tst',200);
  [parms,dig1]       = take_from_struct(parms,'dig1');
  [parms,dig2]       = take_from_struct(parms,'dig2');

  % Try to load from file 
  filename = set_filenames('nois',parms);
  vars = {'trn_img','tst_img','trn_lbl','tst_lbl'};
  [do_calc, trn_img, tst_img, trn_lbl, tst_lbl] = cond_load(filename, ...
						  do_force, vars{1:end});
  if do_calc<1, return; end

  fprintf('Read MNIST data from disk.\n');
  % --------------------------------------
  homedir = [getenv('HOME') '/'];
  addpath(fullfile(homedir,'Data','MNIST'));
  [trn_orig, trn_lbl, tst_orig, tst_lbl] = readMNIST;
  

  fprintf('Filter digits %d and %d.\n',dig1,dig2);
  % ----------------------------------------------
  trn_inds = randrows(find(trn_lbl==dig1 | trn_lbl==dig2));
  trn_orig = trn_orig(:,:,trn_inds(1:n_trn));
  tst_inds = randrows(find(tst_lbl==dig1 | tst_lbl==dig2));
  tst_orig = tst_orig(:,:,tst_inds(1:n_tst));
  trn_lbl = double(trn_lbl(trn_inds(1:n_trn)));
  tst_lbl = double(tst_lbl(tst_inds(1:n_tst))); 

  fprintf('Remove frame pixels\n');
  % -------------------------------
  trn_orig = double(reshape(trn_orig,28*28,n_trn)');
  tst_orig = double(reshape(tst_orig,28*28,n_tst)');
  o = ones(28);
  frame = 3; 
  o(1:frame,:)         = 0;
  o(end-frame+1:end,:) = 0;
  o(:,1:frame)         = 0;
  o(:,end-frame+1:end) = 0;
  inds = find(o);
  trn_orig = trn_orig(:,inds);
  tst_orig = tst_orig(:,inds);
  
  fprintf('Add Noise (%4.2f percent missing values).\n',frac);
  % ----------------------------------------------------------
  [trn_img, tst_img] = kill_values(trn_orig, tst_orig, parms);

  
  fprintf('Save file "%s".\n',filename);
  % ------------------------------------
  save(filename,'trn_img','tst_img','trn_lbl','tst_lbl');

  return
end