
% Adam Wang, 17 Mar 2008
% Creates movies of blurring noise, comparing white vs. blue
% Makes one movie of tumor w/out window/leveling, one with, and one of a
% 'mystery' object

createNoise;

Obj = (dist<15); % tumor object
obj = ifft2c(Obj)*30;
obj = circshift(obj,[100 -100]);


objWhite = obj + white;
objBlue = obj + blue;
objRed = obj + red;

NPSwhite(imSize/2+1) = NPSwhite(end); NPSblue(imSize/2+1) = NPSblue(end);
Margin = imSize/8;

clear mex;
mov = avifile('C:\Documents and Settings\Adam Wang\My Documents\_Second Year\PSYCH221\Project\data\smallLesionStatic.avi');
colormap gray;


Fc = 128:-1:10; % cutoff freqs of LPF
Max = max(max([objWhite objBlue]));
Min = min(min([objWhite objBlue]));
R = max(abs([Max Min]));

for i = 1:length(Fc);
    fc = Fc(i); 
    F = 255*ones(imSize+3*Margin+160, 2*imSize+4*Margin);
    im1 = ifft2c(fft2c(objWhite).*(dist<fc));
    im2 = ifft2c(fft2c(objBlue).*(dist<fc));
    
    F(1+Margin:Margin+imSize, 1+Margin:Margin+imSize) = im1;
    F(1+Margin:Margin+imSize, 1+3*Margin+imSize:end-Margin) = im2;

    dd = imSize + 2*Margin; ll = Margin;
    F(dd+11:dd+160, ll+1:ll+2*floor(Fc(i))) = R/2;
    for j = 1:floor(Fc(i))
        F(dd+160-floor(100*NPSwhite(j)):dd+160,ll+2*j-1:ll+2*j) = -R/4;
        F(dd+160-floor(100*NPSwhite(j))-2:dd+160-floor(100*NPSwhite(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))-2:dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))+2,ll+2*j) = -R/2;
    end
    for j = floor(Fc(i))+1:128
        F(dd+160-floor(100*NPSwhite(j)):dd+160,ll+2*j-1:ll+2*j) = R;
        F(dd+160-floor(100*NPSwhite(j))-2:dd+160-floor(100*NPSwhite(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))-2:dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))+2,ll+2*j) = -R/2;
    end
    F(dd+1:dd+160,ll-1:ll+2) = -R;
    F(dd+160:dd+163,ll-1:ll+imSize+4) = -R;
    
    dd = imSize + 2*Margin; ll = imSize+3*Margin;
    F(dd+11:dd+160, ll+1:ll+2*floor(Fc(i))) = R/2;
    for j = 1:floor(Fc(i))
        F(dd+160-floor(100*NPSblue(j)):dd+160,ll+2*j-1:ll+2*j) = -R/4;
        F(dd+160-floor(100*NPSblue(j))-2:dd+160-floor(100*NPSblue(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))-2:dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))+2,ll+2*j) = -R/2;
    end
    for j = floor(Fc(i))+1:128
        F(dd+160-floor(100*NPSblue(j)):dd+160,ll+2*j-1:ll+2*j) = R;
        F(dd+160-floor(100*NPSblue(j))-2:dd+160-floor(100*NPSblue(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))-2:dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))+2,ll+2*j) = -R/2;
    end
    F(dd+1:dd+160,ll-1:ll+2) = -R;
    F(dd+160:dd+163,ll-1:ll+imSize+4) = -R;


    FF = repmat(uint8((F+R)/(2*R)*256),[1 1 3]);
    f.cdata = FF;
    f.colormap = [];
    


    mov = addframe(mov,f);
end
mov = close(mov);




clear mex;
mov = avifile('C:\Documents and Settings\Adam Wang\My Documents\_Second Year\PSYCH221\Project\data\smallLesionDynamic.avi');
colormap gray;

Fc = [128:-10:48 43:-4:31 30:-1:20 19.5:-.05:16 15.9:-.02:14.1 14:-.05:10 10:-.1:1];

for i = 1:length(Fc);
    fc = Fc(i); 
    F = 255*ones(imSize+3*Margin+160, 2*imSize+4*Margin);
    im1 = ifft2c(fft2c(objWhite).*(dist<fc));
    im2 = ifft2c(fft2c(objBlue).*(dist<fc));
    
    R1 = max(abs([max(im1(:)) min(im1(:))]));
    R2 = max(abs([max(im2(:)) min(im2(:))]));
    R = max(R1,R2);
    
    F(1+Margin:Margin+imSize, 1+Margin:Margin+imSize) = im1*R/R1;
    F(1+Margin:Margin+imSize, 1+3*Margin+imSize:end-Margin) = im2*R/R2;

    
    dd = imSize + 2*Margin; ll = Margin;
    F(dd+11:dd+160, ll+1:ll+2*floor(Fc(i))) = R/2;
    for j = 1:floor(Fc(i))
        F(dd+160-floor(100*NPSwhite(j)):dd+160,ll+2*j-1:ll+2*j) = -R/4;
        F(dd+160-floor(100*NPSwhite(j))-2:dd+160-floor(100*NPSwhite(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))-2:dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))+2,ll+2*j) = -R/2;
    end
    for j = floor(Fc(i))+1:128
        F(dd+160-floor(100*NPSwhite(j)):dd+160,ll+2*j-1:ll+2*j) = R;
        F(dd+160-floor(100*NPSwhite(j))-2:dd+160-floor(100*NPSwhite(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))-2:dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))+2,ll+2*j) = -R/2;
    end
    F(dd+1:dd+160,ll-1:ll+2) = -R;
    F(dd+160:dd+163,ll-1:ll+imSize+4) = -R;
    
    dd = imSize + 2*Margin; ll = imSize+3*Margin;
    F(dd+11:dd+160, ll+1:ll+2*floor(Fc(i))) = R/2;
    for j = 1:floor(Fc(i))
        F(dd+160-floor(100*NPSblue(j)):dd+160,ll+2*j-1:ll+2*j) = -R/4;
        F(dd+160-floor(100*NPSblue(j))-2:dd+160-floor(100*NPSblue(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))-2:dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))+2,ll+2*j) = -R/2;
    end
    for j = floor(Fc(i))+1:128
        F(dd+160-floor(100*NPSblue(j)):dd+160,ll+2*j-1:ll+2*j) = R;
        F(dd+160-floor(100*NPSblue(j))-2:dd+160-floor(100*NPSblue(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))-2:dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))+2,ll+2*j) = -R/2;
    end
    F(dd+1:dd+160,ll-1:ll+2) = -R;
    F(dd+160:dd+163,ll-1:ll+imSize+4) = -R;


    FF = repmat(uint8((F+R)/(2*R)*256),[1 1 3]);
    f.cdata = FF;
    f.colormap = [];

    mov = addframe(mov,f);
end
mov = close(mov);





skull = imread('C:\Documents and Settings\Adam Wang\My Documents\_Second Year\PSYCH221\Project\data\skull_bones.jpg');
skull = double(skull);
Skull = fft2c(skull);
skullObj = ifft2c(Skull.*(dist<10));
skullObj = skullObj/max(skullObj(:))*.18;

objWhite = white + skullObj;
objBlue = blue + skullObj;

clear mex;
mov = avifile('C:\Documents and Settings\Adam Wang\My Documents\_Second Year\PSYCH221\Project\data\mysteryDynamic.avi');
colormap gray;

Fc = [128:-10:38 34:-4:22 21:-.5:15 14.5:-.05:11 10.9:-.02:9.3 9:-.05:1];

for i = 1:length(Fc);
    fc = Fc(i); 
    F = 255*ones(imSize+3*Margin+160, 2*imSize+4*Margin);
    im1 = ifft2c(fft2c(objWhite).*(dist<fc));
    im2 = ifft2c(fft2c(objBlue).*(dist<fc));
    
    R1 = max(abs([max(im1(:)) min(im1(:))]));
    R2 = max(abs([max(im2(:)) min(im2(:))]));
    R = max(R1,R2);
    
    F(1+Margin:Margin+imSize, 1+Margin:Margin+imSize) = im1*R/R1;
    F(1+Margin:Margin+imSize, 1+3*Margin+imSize:end-Margin) = im2*R/R2;

    
    dd = imSize + 2*Margin; ll = Margin;
    F(dd+11:dd+160, ll+1:ll+2*floor(Fc(i))) = R/2;
    for j = 1:floor(Fc(i))
        F(dd+160-floor(100*NPSwhite(j)):dd+160,ll+2*j-1:ll+2*j) = -R/4;
        F(dd+160-floor(100*NPSwhite(j))-2:dd+160-floor(100*NPSwhite(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))-2:dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))+2,ll+2*j) = -R/2;
    end
    for j = floor(Fc(i))+1:128
        F(dd+160-floor(100*NPSwhite(j)):dd+160,ll+2*j-1:ll+2*j) = R;
        F(dd+160-floor(100*NPSwhite(j))-2:dd+160-floor(100*NPSwhite(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))-2:dd+160-floor(50*NPSwhite(j)+50*NPSwhite(j+1))+2,ll+2*j) = -R/2;
    end
    F(dd+1:dd+160,ll-1:ll+2) = -R;
    F(dd+160:dd+163,ll-1:ll+imSize+4) = -R;
    
    dd = imSize + 2*Margin; ll = imSize+3*Margin;
    F(dd+11:dd+160, ll+1:ll+2*floor(Fc(i))) = R/2;
    for j = 1:floor(Fc(i))
        F(dd+160-floor(100*NPSblue(j)):dd+160,ll+2*j-1:ll+2*j) = -R/4;
        F(dd+160-floor(100*NPSblue(j))-2:dd+160-floor(100*NPSblue(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))-2:dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))+2,ll+2*j) = -R/2;
    end
    for j = floor(Fc(i))+1:128
        F(dd+160-floor(100*NPSblue(j)):dd+160,ll+2*j-1:ll+2*j) = R;
        F(dd+160-floor(100*NPSblue(j))-2:dd+160-floor(100*NPSblue(j))+2,ll+2*j-1) = -R/2;
        F(dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))-2:dd+160-floor(50*NPSblue(j)+50*NPSblue(j+1))+2,ll+2*j) = -R/2;
    end
    F(dd+1:dd+160,ll-1:ll+2) = -R;
    F(dd+160:dd+163,ll-1:ll+imSize+4) = -R;


    FF = repmat(uint8((F+R)/(2*R)*256),[1 1 3]);
    f.cdata = FF;
    f.colormap = [];

    mov = addframe(mov,f);
end
mov = close(mov);
