% Generating movie for thresholding grayscale image
% Ziyue Xu
% UIowa ECE 2011 Feb.21
I = rgb2gray(imread('the_crane_building_pic.jpg'));
figure;
subplot(1,2,1);
imshow(I,[]);
minI = min(min(I));
maxI = max(max(I));
subplot(1,2,2);
M2D = moviein(maxI-minI+1);
for level = minI:maxI
    biI = im2bw(I, double(level)/255);
    imshow(biI,[]);
    drawnow
    M2D(:,level-minI+1) = capturescreen(gcf);
end
movie2avi(M2D,'building.avi');