function [obj_img] = fuzzy_segment2(image1, image2,tol,mult);
rgb_img1 = imread(image1);
rgb_img2 = imread(image2);
gray_img = double(rgb2gray(rgb_img1));
[M,N,P] = size(rgb_img1);
figure(1);
%draw 2 polygons- in case of disjoint background
t_inds1 = find(roipoly(rgb_img1));
t_inds2 = find(roipoly(rgb_img1));
t_inds = [t_inds1; t_inds2];
disp('performing classification...');
res_img1 = [];
res_img2 = [];
if (mult==0)
res_img1 = classify_img(rgb_img1,t_inds,tol);
res_img2 = classify_img(rgb_img2,t_inds,tol);
else
res_img1 = classify_img(rgb_img1,t_inds,tol);
res_img2 = classify_img(rgb_img2,t_inds,tol);
end
disp('formatting results...');
totres = round(256*(res_img1+2*res_img2)/3);
figure(2);
imagesc(totres);
imwrite(uint8(totres),'results/totres.png','png');
title('classification results, segment2');
colormap(gray);
objimg1 = (totres == 0);
%find pixels with background classification,
%which are connected to first training pixel
ind1n = floor(t_inds(1)/M) + 1;
ind1m = mod(t_inds(1),M) + 1;
objimg2 = 1 - double(bwselect([1-objimg1],ind1n,ind1m,8));
figure(3);
obj_img = double(bwselect(objimg2,8));
%display segmentation mask
imagesc(obj_img);
colormap(gray);
title('final mask, segment2');