function [out_plus, out_minu, out_diff, contrast] = average(input_line, Lmax)

L = input_line;

if max(L/Lmax)<0.5
   midpoint = median(L/Lmax);
else
   midpoint = 0.5;
end

plus_1 = clip(L/Lmax -midpoint); 
p_mean_1 = sum(plus_1)/sum(plus_1>0);

[row, col]=size(plus_1);

temp1 = [];
for i = 1:col
    if (plus_1(i)<p_mean_1+std(plus_1) & plus_1(i)>p_mean_1-std(plus_1))
       if i==1
            temp1 = plus_1(i); 
       else 
            temp1 = [temp1 plus_1(i)];
       end
    end
end 
out_plus = sum(temp1)/sum(temp1>0) + midpoint;

minu_1 = clip(L/Lmax -midpoint, -1, 0); 
m_mean_1 = sum(minu_1)/sum(minu_1<0);

temp2 = [];
for i = 1:col
    if (minu_1(i)<m_mean_1+std(minu_1) & minu_1(i)>m_mean_1-std(minu_1))
       if i==1
            temp2 = minu_1(i);
       else 
            temp2 = [temp2 minu_1(i)];
       end
    end
end 
out_minu = sum(temp2)/sum(temp2<0) + midpoint;

out_diff = out_plus - out_minu;

contrast = out_diff/(out_plus+out_minu);