function w = calWeight(saliency_map, ele_size, csize, Z)


map1 = saliency_map;
level = graythresh(map1);

salim = imclose(im2bw(map1, level), strel('square', ele_size));
map1 = normlz(map1)/255;
salval = sum(map1(:)) / numel(map1);

salcnt = 0;
[map2,labcnt] = bwlabel(salim);
cint = 1;
num2 = numel(salim);
for k=1:labcnt
    temp1 = mean(mean(map1(map2==k)));
    if (sum(sum(map2==k)) > csize)
        salcnt = salcnt + temp1;
        cint = cint + 1;
    end
end
w = 1-(cint-1)/Z;

%  w =  sum(normlz(ka1)/255 .* sa1) * (2/cint);

if (w<0), w= 0.1; end
