function segment_test

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function EST_BA laskee tilavuuden kpit ja PPA:n avulla kuvitteellisen
% look-up-tablen avulla.             
%
% kunnollisessa proseduurissa sekä keskipituus että pohjapinta-ala
% pitää kalibroida, nyt ne vain tempastiin datasta.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%      

%eval(['load d:\lecture_material\',name,'.txt'])
%file=eval(name);
eval(['load d:\lecture_material\wattest'])


se = strel('disk', 5);
Itop = imtophat(wattest, se);
Ibot = imbothat(wattest, se);
Ienhance = imsubtract(imadd(Itop, wattest), Ibot);
Iec = imcomplement(Ienhance);
Iemin = imextendedmin(Iec, 22);
Iimpose = imimposemin(Iec, Iemin);
wat = watershed(Iimpose);
rgb = label2rgb(wat);
figure, imshow(rgb);
title('watershed segmented image');
stats = regionprops(wat, 'Area', 'Orientation');
area = [stats(:).Area];
orient = [stats(:).Orientation];
pause
figure, plot(area, orient, 'b*');
title('Relationship of Particle Orientation to Area');
xlabel('particle area (pixels)');
ylabel('particle orientation (degrees)');



