function [dfstack]=dffoSFNFix(stack,frames,invertdffo,forcesingle)

% [dfstack]=dffo(stack,frames)
% takes a stack, does df/fo, returns uint16 stack
% fo is based on average of 1st 3 frames


if strcmp(class(stack),'single')==0 && forcesingle==1
	disp('stack not of type single in dffo; casting to single');
	stack = single(stack);
else
    stack=double(stack);
end


fo = (stack(:,:,1)/3 + stack(:,:,2)/3 + stack(:,:,3)/3);
%fo = (stack(:,:,1) + stack(:,:,2) + stack(:,:,3))/3;

for p=frames:-1:1
%for p = 1:frames
    df_fo(:,:,p) = (stack(:,:,p) - fo)./fo;
end

dfstack=df_fo;

