Code covered by the BSD License  

Highlights from
video from random points

image thumbnail

video from random points

by

 

probability controled by frames of video

from_gif_to_gif.m
[I map] = imread('neo2.gif', 'frames','all');
It0=I(:,:,1,1);
It=ind2rgb(It0,map);
It = rgb2gray(It);
mg=30;
It=It(1+mg:end-mg,:);
Itd=1-It; % negative
x1=1;
x2=size(Itd,2);

y1=1;
y2=size(Itd,1);

mapg=0.2989 * map(:,1) + 0.5870 * map(:,2) + 0.1140 * map(:,3);
fmax=max(1-mapg); % maximal value in negative image


%fmax=max(I);

g=1/((x2-x1)*(y2-y1)); % use uniform distribution as instrumental distribution, constan for any x and y

c=2*fmax/g;

N1=100000;

%hi=imshow(Itd,[0 1]);
hp=plot(NaN,NaN,'k.','MarkerSize',1);
set(gca,'Ydir','reverse');
axis equal;
am=2; % axis margin
xlim([x1-am x2+am]);
ylim([y1-am y2+am]);
xl=zeros(1,N1);
yl=zeros(1,N1);
clear F;

clear im;
ff = getframe;
[im,mapg] = rgb2ind(ff.cdata,256,'nodither');
im(1,1,1,20) = 0;

for fc=1:size(I,4)
    It0=I(:,:,1,fc);
    It=ind2rgb(It0,map);
    It = rgb2gray(It);
    It=It(1+mg:end-mg,:);
    Itd=1-It;
    %set(hi,'CData',Itd);
    
    llc=1;
    while true;

        x=x1+(x2-x1)*rand;
        y=y1+(y2-y1)*rand;
        u=c*g*rand;
        %if(u<=f(x,y))
        if(u<=Itd(round(y),round(x)))
            %xl=[xl x];
            xl(llc)=x;
            %yl=[yl y];
            yl(llc)=y;
            llc=llc+1;
        end

        %if length(xl)>=N1
        if llc>=N1
            break;
        end

    end
    
    set(hp,'XData',xl,'YData',yl);
    xlim([x1-am x2+am]);
    ylim([y1-am y2+am]);
    %F(fc)=getframe;
    drawnow;
    
    ff = getframe;
    im(:,:,1,fc) = rgb2ind(ff.cdata,mapg,'nodither');
    
    %pause(0.1);
end

%movie2avi(F,'neo_avi','fps',10,'compression','Cinepak'); 
imwrite(im,mapg,'neo_gif.gif','DelayTime',0.1,'LoopCount',inf);

Contact us