%   makehues

%   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. 

stufen=input('wieviel stufen?');
staerke=input('range+/-? (0-1)');

                                                                     

mode=input('edit (0) oder sample (1)?');
if mode== 0
	gruen=input('grün? (0-1)');
	blau=input('blau? (0-1)');
   rot=input('rot? (0-1)');
   [filename,filepath]=uiputfile('*.bmp','startbitmap:');
	file=[filepath filename];
   imwrite(picmat,file,'jpg');
else
   [sourcefilename,sourcefilepath]=uigetfile('*.jpg','sourcebitmap:');
   sourcefile=[sourcefilepath sourcefilename];
   file=[sourcefilepath sourcefilename];
   cd(sourcefilepath);
   sourcepicmat=(double(imread(sourcefile,'jpg')))/255;
   gruen=sourcepicmat(100,100,1);
   blau=sourcepicmat(100,100,2);
   rot=sourcepicmat(100,100,3);
end

%[picmat]=imread(file,'bmp');

rel12=gruen/blau;
rel23=blau/rot;
rel13=gruen/rot;
picmat=zeros(480,640,3);
picmat(:,:,1)=(ones(480,640)*gruen);
picmat(:,:,2)=(ones(480,640)*blau);
picmat(:,:,3)=(ones(480,640)*rot);
bottomgruen=gruen-gruen*staerke;
topgruen=gruen+gruen*staerke;
gruenvec=linspace(bottomgruen,topgruen,stufen);
blauvec=gruenvec/rel12;
rotvec=gruenvec/rel13;

for k=1:stufen
   
   targetfilename=strrep(file,'.jpg',[num2str(k),'.jpg']);
   picmat(:,:,1)=(ones(480,640)*gruenvec(k));
	picmat(:,:,2)=(ones(480,640)*blauvec(k));
   picmat(:,:,3)=(ones(480,640)*rotvec(k));
   
   %clip über 1
   ceilpicmat=picmat>1;
   indexmat=find(ceilpicmat);
   picmat(indexmat)=1;
   
   imwrite(picmat,targetfilename,'jpg');
end