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.m
% for random points generatation with predefined distribution Rejection sampling method used:
% http://en.wikipedia.org/wiki/Rejection_sampling
[I map] = imread('neo2.gif', 'frames','all'); % read all frames
It0=I(:,:,1,1); % first frame to get parameters
It=ind2rgb(It0,map);
It = rgb2gray(It);
mg=30;
It=It(1+mg:end-mg,:);
Itd=1-It; % negative
% Itd cosidered as probability density function 2d

% limits:
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); % colormap to gray colors
fmax=max(1-mapg); % maximal value in negative image (maximal value of distribution, image considered as 2d distribution)


%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; % makes Itd<c*g always
% in wiki article c is M

N1=100000; % number of points

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

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);
    
    drawnow;
    %pause(0.1);
end

Contact us