function adjustcontr(filename,filepath,faktor)
%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.                                                                      
file=[filepath filename];
[picmat]=imread(file);

picgroesse=size(picmat);
picvec=zeros(picgroesse(1)*picgroesse(2)*picgroesse(3),1);

bildnummerind=findstr(filename,'.');
bildnummer=filename(bildnummerind-4:bildnummerind+1);


%totbright

picgroesse=size(picmat);
nofpspercolor=picgroesse(1)*picgroesse(2);
nofpspercolumn=picgroesse(1);
%totcont
for i=1:picgroesse(3)
    for j=1:picgroesse(2)
    picvec((-1+i)*nofpspercolor+(-1+j)*nofpspercolumn+1:(-1+i)*nofpspercolor+(-1+j)*nofpspercolumn+nofpspercolumn)=picmat(:,j,i);
end 
end

totcont=std(picvec);


%normierung (quasi-z-Transformation)
[picmat]=double(picmat)/255;
totbright=mean(mean(mean(picmat)));
picmat=picmat-totbright;



% maxverstvec=[(-1)*totbright/min(min(min(picmat)));(255-totbright)/max(max(max(picmat)))];
% maxverst=min(maxverstvec);
% if sum(picmat>255)>0 | sum(picmat<0)>0
%     msgbox(['Bild verzerrt durch Clipping! maximal: ',num2str(maxverst)],'Achtung:');
% end
% imwrite(picmat,file,'jpg');

%verstärkung

verstaerkungsmat=-0.5*sin(mean(picmat,3)*pi-pi/2)+1+0.5;

for i=1:3
    picmat(:,:,i)=picmat(:,:,i).*verstaerkungsmat;
end

picmat=picmat+totbright;
picmat=uint8(round(picmat*255));
imwrite(picmat,strrep(file,'.jpg','.mod.jpg'),'jpg');
