function [Orig,Seg] = demo_seg_seabed(mask,K,STD,stat_law_seg)

%init frame rate parameters
frame_rate = 1/4.5; %1/9 if work done on each image, 1/4.5 if two
NB_STORE_FRAME = 25;
% Symbolic sequence of images
symb_seq = [];


%Create the movie to save the results
figure(1);
f1 = gcf;
set(f1,'renderer','zbuffer');
Orig = moviein(NB_STORE_FRAME);
figure(2);
f2 = gcf;
set(f2,'renderer','zbuffer');
Seg = moviein(NB_STORE_FRAME);
count = 1;
nb_files = 0;

% init the input images location
directory = '/u1/pg/aramis/Data/Seabed/Video_1/15/15.';
% process the input flow of images
j = 1;
mu = [];
std1 = [];
while (j < 96)
  name = sprintf('%s%0.6d%s',directory,j,'.rgb');
  ima1 = images(name)
  figure(1);
  plot(ima1);
  xlabel(name);
  drawnow;
  hold on;
  
  figure(2)
  [ima2,mu,std1] = stat_seg(ima1,K,5,mask,45,STD,mu,std1,0)
  ima3 = median(ima2);
  %carefull !!! assuming that higher mu value correspond
  %with higher std value etc... otherwise, mu and std must be 
  %sorted so that ranks values correspond
  %ima3=threshold(images(ima2),mu(3)-1);
  plot(ima3);
  xlabel(num2str(j));
  drawnow;
  figure(1);
  if mod(j,2) == 0
    Orig(:,count) = getframe;
  end
  drawnow;
  hold off;
  figure(2);
  %Display only (reset the movie to save memory space)
  if mod(j,2) == 0
   Seg(:,count) = getframe;
   count
   if (count == NB_STORE_FRAME)
     save(strcat('movie',num2str(nb_files),'.mat'),'Orig','Seg');
     count = 1;
     nb_files = nb_files + 1;
     [x,map] = capture(1);
     imwrite(x,map,strcat('ex_track_sonar',num2str(nb_files),'.tif'),...
	 'tif');
     [x,map] = capture(2);
     imwrite(x,map,strcat('ex_track_sonar_seg',num2str(nb_files),'.tif'),...
	 'tif');
   else
     count = count +1;
   end
 end
 drawnow;
 hold off;
 j = j + 1;
end
Orig = Orig(:,1:count-1);
Seg = Seg(:,1:count-1);


