Home > eeg > egis > spline > scale_interps.m

scale_interps

PURPOSE ^

function status=scale_interps(imin,imax,irows,icols,filenums,inroot,outroot,invf);

SYNOPSIS ^

function status=scale_interps(imin,imax,irows,icols,filenums,inroot,outroot,invf);

DESCRIPTION ^

function status=scale_interps(imin,imax,irows,icols,filenums,inroot,outroot,invf);

This function takes a 32-bit floating point binary file output
from interp_by_samp or Interpolator 4.0, rescales it to an 8-bit
unsigned character, and writes it to a new file.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status=scale_interps(imin,imax,irows,icols,filenums,inroot,outroot,invf);
0002 %function status=scale_interps(imin,imax,irows,icols,filenums,inroot,outroot,invf);
0003 %
0004 %This function takes a 32-bit floating point binary file output
0005 %from interp_by_samp or Interpolator 4.0, rescales it to an 8-bit
0006 %unsigned character, and writes it to a new file.
0007 %
0008 
0009 %Created 3/21/96 by B. Rakitin
0010 %
0011 
0012 status= -1;
0013 
0014 if (nargin~=7) & (nargin~=8)
0015     error('get_interp_range requires 7 or 8 input params. See help.')
0016 end
0017 
0018 n=length(filenums);
0019 if n==0
0020     error('Null vector passed as filenums param, asshole.');
0021 end
0022 
0023 if imin>=imax
0024     error('Mins must be greater than maxs, dipshit.');
0025 end
0026 
0027 if strcmp(inroot,outroot)==1
0028     error('Input and output paths must be different, you must be Doran.');
0029 end
0030 
0031 if nargin==8
0032     if (invf~=0) & (invf~=1)
0033         error('Invert flag must be 0 or 1.');
0034     end
0035 else
0036     invf=0;
0037 end
0038 
0039 tempdata=zeros(irows,icols);
0040 
0041 for f=1:n
0042     infilename=[inroot int2str(filenums(f))];
0043     disp(['Current File: ' infilename]);
0044     if exist(infilename)~=2
0045         disp(['Skipping non-existing input file ' infilename ]);
0046     else
0047         infid=-1;msg='';
0048         [infid,msg]=fopen(infilename);
0049         if infid==-1
0050             disp([msg ': ' infilename]);
0051         else
0052             [tempdata, count]=fread(infid,size(tempdata),'float');
0053             if count~=(irows*icols)
0054                 fclose('all');
0055                 error(['Error reading file ' infilename]);
0056             end
0057             fclose(infid);
0058             tempdata=round(((tempdata - imin).*255)/(imax-imin));
0059             tempdata=tempdata.*(~(tempdata<0));
0060             tempdata=((tempdata>255)*255)+(tempdata.*(~(tempdata>255)));
0061 %            tempdata(tempdata>255)=ones(size(tempdata(tempdata>255)))*255;
0062 %            tempdata(tempdata<0)=zeros(size(tempdata(tempdata<0)));
0063             fnumstr=int2str(filenums(f));
0064             if filenums(f)<100, fnumstr=['0' fnumstr];end;
0065             if filenums(f)<10, fnumstr=['0' fnumstr];end;
0066             outfilename=[outroot fnumstr];
0067             outfid=-1;msg='';
0068             [outfid,msg]=fopen(outfilename,'w');
0069             if outfid==-1
0070                 error(['Error opening output file ' outfilename]);
0071             else
0072                 disp(['Output file is ' outfilename]);
0073                 if invf==0
0074                     count=fwrite(outfid,tempdata,'uchar');
0075                 else
0076                     count=fwrite(outfid,tempdata','uchar');
0077                 end
0078                 if count~=(irows*icols)
0079                     error(['Error writing scaled data to file ' outfilename]);
0080                 end
0081                 fclose(outfid);
0082             end
0083         end    %if infid==-1
0084     end    %if exist(infilename)~=2
0085 end    %for f=1:n
0086 
0087 status=1;

Generated on Sat 24-Aug-2019 04:00:39 by m2html © 2003