function animcompress(imgname,cmode,endframe)
    img = imread(imgname);
    name = strsplit(imgname,'.');
    mov(endframe) = struct('cdata',[],'colormap',[]);
    for i = 0:endframe-1
        p = 2^i;
        compress(img,p,cmode);
        fig = figure(2); axis square;
        mov(i+1) = getframe(fig);
    end
    
    fps = 1/3;
    v = VideoWriter(char(name(1)),'MPEG-4');
    v.FrameRate = fps;
    open(v); writeVideo(v,mov); close(v);
end