function C5()

% Make a movie that dissolves CornellIthaca.jpg into a red version...
M = Dissolve('CornellIthaca.jpg',[1 0 0],5);
% Play the movie 3 times at 10 frames a second...
movie(M,3,10)


  function M = Dissolve(TheImage,TheColor,TheDuration)
% TheImage is the name of a jpeg in the current workspace.
% M is a movie of length TheDuration (seconds) that morphs
% TheImage into its monochrome version at 10 frames/second.
% TheColor is an rgb vector that defines the monochrome color
A = imread(TheImage);
B = rgb2mono(A,TheColor);
N = ceil(TheDuration*10);
for k=0:N
   f = k/N;
   D = InterpImage(A,B,f);
   imshow(D)
   M(k+1) = getframe;
end

  function D = InterpImage(A,B,f)
% A and B are equally sized 3D image arrays and 0<=f<=1
% D = (1-f)*A + f*B
[m,n,p] = size(A);
D = zeros(m,n,3,'uint8');
for i=1:m
    for j = 1:n
        D(i,j,1) = uint8((1-f)*double(A(i,j,1)) + f*double(B(i,j,1)));
        D(i,j,2) = uint8((1-f)*double(A(i,j,2)) + f*double(B(i,j,2)));
        D(i,j,3) = uint8((1-f)*double(A(i,j,3)) + f*double(B(i,j,3)));
    end
end