function projs_fix = shiftfix(projs)
%
%  projs_fix = shiftfix(projs)
%
%  Shiftfix repair shifts in the projections due to
%  horizontal shifts in the phantom during the
%  projection capture by CALCPROJ.M.
%
%  SEE calcproj.m
%
%  Developed by Timothy D. Dorney
%               Rice University
%               April, 1999
%               tdorney@ieee.org
%
%  Coded using MATLAB 5.X.X.
%
%	REVISION HISTORY
%
%	VERSION 1.0.0		APR. 24, 1999	TIM DORNEY
%

[m,n] = size(projs);
T1 = (cumsum(projs(1,:)))./(sum(projs(1,:)));
[e,f] = find((T1 < 0.5) & (projs(1,:) == 0));
LOW = f(end);
[e,f] = find((T1 > 0.5) & (projs(1,:) == 0));
HIGH = f(1);
MID = (LOW + HIGH)/2;
OFFSET = n/2 - MID;
OTHER_END_OFFSET = n/2 + OFFSET;
RUN = OTHER_END_OFFSET - MID + 1;
FN = RUN - RUN*((cos(pi*[0:1/(m-1):1]) + 1)/2);

fres = 10;
projs_fix = zeros(m,n);
T4 = zeros(1,(n*fres));
for kk = 1:1:m
	mid = MID + FN(kk);
	SUM = sum(projs(kk,:));
	T2 = (cumsum(projs(kk,:)))./SUM;
	[e,f] = find((T2 < 0.5) & (projs(kk,:) == 0));
	LOW = f(end);
	[e,f] = find((T2 > 0.5) & (projs(kk,:) == 0));
	HIGH = f(1);
	midcur = (LOW + HIGH)/2;
	T3 = mid - midcur;
	if (abs(T3) >= 0.7)
		m - kk
		T4 = interp(projs(kk,:),fres);
		T3 = round(T3*fres);
		if (T3 > 0)
			T4 = [zeros(1,T3) T4(1:1:(n*fres - T3))];
		else
			T4 = [T4((abs(T3) + 1):1:(n*fres + T3)) zeros(1,abs(T3))];
		end
		T5 = decimate(T4,fres);
		T5SUM = sum(T5);
		projs_fix(kk,:) = T5.*SUM/T5SUM;
	else
		projs_fix(kk,:) = projs(kk,:);
	end
end
