Séquence d'images

Résolu/Fermé
gari.fatima Messages postés 4 Date d'inscription vendredi 8 juin 2012 Statut Membre Dernière intervention 10 juin 2012 - 8 juin 2012 à 12:44
 gej62 - 10 juin 2012 à 14:42
Bonjour,
svp j'ai besoin d'une séquence d'image extraite à partir d'une vidéo.ces images doivent etre de dimension 256*256.j'ai travaillé avec le logiciel frameshot mais il me donne des frames de dimension 300*245.
j'ai besoins des 2 frames pour un code de la compression de vidéo et précisement la prédiction temporelle.
merci d'avance pour vos réponses.

5 réponses

bonjour
tu peux essayer virtual dub ou avidemux selon le "format" de ta vidéo si tu veux extraire toute la sequence.ou redimensionner tes images via un soft photos .
slts
0
salut merci bcq gej62 j'ai résolu le prob en ajoutant qlq lignes au programme ils m'ont permetté de lire des frames à partir d'une video avec extension .YUV
0
bravo
bonne continuation:-)
slts
0
gari.fatima Messages postés 4 Date d'inscription vendredi 8 juin 2012 Statut Membre Dernière intervention 10 juin 2012
10 juin 2012 à 14:13
merci
maintenant j'ai passé au 2éme code il est pour la compensation de mouvement, il me signale des erreurs au niveau des fonctions.
voila le code:




% Computes the motion vectors and motion compensated
% prediction error image corresponding to two
% temporally adjacent image frames using the
% Sum of Absolute Difference (SAD) metric and
% full search procedure.
% It can estimate the motion to integer pel, half pel, or
% quarter pel accuracy.
% Motion blocks are of size 8 x 8 pixels and the
% search window size is 16 x 16 pixels.
clear

fid = fopen('foreman.qcif.yuv', 'r');
foreman=fread(fid);
%lecture de l'image i en Y
X=6*72*88;
i=10;
Y10=foreman((i-1)*X+1:(i-1)*X+176*144);
Y10=reshape(Y10,176,144);
Y10=Y10';
%figure; imshow(Y,gray(256))
i=12;
Y12=foreman((i-1)*X+1:(i-1)*X+176*144);
Y12=reshape(Y12,176,144);
Y12=Y12';


A = Y10; % frame #1
B = Y12; % frame #2
N = 8;% block size is N x N pixels
W = 16; % search window size is W x W pixels
PredictionType = 'full'; % Options: "full", "half" and "quarter"
% Make image size divisible by 8
[X,Y,Z] = size(A);
if mod(X,8)~=0
Height = floor(X/8)*8;
else
Height = X;
end
if mod(Y,8)~=0
Width = floor(Y/8)*8;
else
Width = Y;
end
Depth = Z;
clear X Y Z
%
t1 = cputime; % start CPU time
% call appropriate motion estimation routine
switch PredictionType
case 'full'
[x,y,pf] = MCpredict_Full(A,B,N,W);
case 'half'
[x,y,pf] = MCpredict_Half(A,B,N,W);
case 'quarter'
[x,y,pf] = MCpredict_Quarter(A,B,N,W);
end
t2 = cputime; % end CPU time (t2-t1) is the time for motion estimation
figure,quiver(x,y,'k'),title('Motion Vector')
sprintf('MSE with MC = %3.3f',std2(pf)*std2(pf))
sprintf('MSE without MC = %3.3f', std2(single(A)-single(B))*std2(single(A)-single(B)))
figure,imshow(pf,[]),title('MC prediction')
figure,imshow(single(A)-single(B),[]),title('prediction without MC')
[hNoMC,BinNoMC] = hist(single(A)-single(B),256);
[hMC,BinMC] = hist(pf,256);
figure,plot(BinMC,hMC,'k'),title('histogram of p frame with MC')
figure,plot(BinNoMC,hNoMC,'k')
title('histogram of p frame with no MC')


function [x,y,pf] = MCpredict_full(A,B,N,W)
% [x,y,pf] = MCpredict_Full(A,B,N,W)
% Computes motion vectors of N x N moving blocks
% in an intensity image using full search and
% does a motion compensated prediction to a single pel accuracy
% Input:
% A = reference frame
% B = current frame
% N = block size (nominal value is 8, assumed square)
% W = search window (2N x 2N)
% Output:
% x = horizontal component of motion vector
% y = Vertical component of motion vector
% pf = motion compensated prediction image, same size as input image

[Height,Width] = size(A);
% pad input images on left, right, top, and bottom
% padding by replicating works better than padding w/ zeros, which is
% better than symmetric which is better than circular
A1 = double(padarray(A,[W/2 W/2],'replicate'));
B1 = double(padarray(B,[W/2 W/2],'replicate'));
x = int16(zeros(Height/N,Width/N));% x-component of motion vector
y = int16(zeros(Height/N,Width/N));% y-component of motion vector
% Find motion vector by exhaustive search to a single pel accuracy
figure,imshow(B), title('Superimposed motion vectors')
hold on % display image & superimpose motion vectors
for r = N:N:Height
rblk = floor(r/N);
for c = N:N:Width
cblk = floor(c/N);
D = 1.0e+10;% initial city block distance
for u = -N:N
for v = -N:N
d = B1(r+1:r+N,c+1:c+N)-A1(r+u+1:r+u+N,c+v+1:c+v+N);
d = sum(abs(d(:)));% city block distance between pixels
if d < D
D = d;
x(rblk,cblk) = v; y(rblk,cblk) = u;
end
end
end
quiver(c+y(rblk,cblk),r+x(rblk,cblk),x(rblk,cblk),y(rblk,cblk),'k','LineWidth',1)
end
end
hold off
% Reconstruct current frame using prediction error & reference frame
N2 = 2*N;
pf = double(zeros(Height,Width)); % prediction frame
Br = double(zeros(Height,Width)); % reconstructed frame
for r = 1:N:Height
rblk = floor(r/N) + 1;
for c = 1:N:Width
cblk = floor(c/N) + 1;
x1 = x(rblk,cblk); y1 = y(rblk,cblk);
pf(r:r+N-1,c:c+N-1) = B1(r+N:r+N2-1,c+N:c+N2-1-A1(r+N+y1:r+y1+N2-1,c+N+x1:c+x1+N2-1);
Br(r:r+N-1,c:c+N-1) = A1(r+N+y1:r+y1+N2-1,c+N+x1:c+x1+N2-1)+ pf(r:r+N-1,c:c+N-1);
end
end
%
figure,imshow(uint8(round(Br))),title('Reconstructed image')

function [x,y,pf] = MCpredict_Half(A,B,N,W)
% [x,y,pf] = MCpredict_Full(A,B,N,W)
% Computes motion vectors of N x N moving blocks
% in an intensity image using full search and
% does a motion compensated prediction to a half pel accuracy
% Input:
% A = reference frame
% B = current frame
% N = block size (nominal value is 8, assumed square)
% W = search window (2N x 2N)
% Output:
% x = horizontal component of motion vector
% y = Vertical component of motion vector
% pf = motion compensated prediction image, same size as input image
[Height,Width] = size(A);
% pad input images on left, right, top, and bottom
A1 = double(padarray(A,[W/2 W/2],'symmetric')); % reference block
B1 = double(padarray(B,[W/2 W/2],'symmetric')); % current block
NumRblk = Height/N;
NumCblk = Width/N;
x = zeros(NumRblk,NumCblk);% x-component of motion vector
y = zeros(NumRblk,NumCblk);% %y-component of motion vector
pf = double(zeros(Height,Width)); % prediction frame
% Find motion vectors by exhaustive search to 1/2 pel accuracy
figure,imshow(B), title('Superimposed motion vectors')
hold on % display image & superimpose motion vectors
for r = N:N:Height
rblk = floor(r/N);
for c = N:N:Width
cblk = floor(c/N);
D = 1.0e+10;% initial city block distance
for u = -N:N
for v = -N:N
%
RefBlk = A1(r+u+1:r+u+N,c+v+1:c+v+N);
CurrentBlk = B1(r+1:r+N,c+1:c+N);
[x2,y2] = meshgrid(r+u+1:r+u+N,c+v+1:c+v+N);
[x3,y3] = meshgrid(r+u-0.5:r+u+N-1,c+v-0.5:c+v+N-1);
% interpolate at 1/2 pel accuracy
z1 = interp2(x2,y2,RefBlk,x3,y3,'*linear');
Indx = isnan(z1);
z1(Indx == 1) = CurrentBlk(Indx==1);
%
dd = CurrentBlk - round(z1);
d = sum(abs(dd(:)));
if d < D
D = d;
U = u+0.5; L = v+0.5;
pf(r-N+1:r,c-N+1:c) = dd;
end
end
end
x(rblk,cblk) = L; % Motion in the vertical direction
y(rblk,cblk) = U; % Motion in the horizontal direction
quiver(c+y(rblk,cblk),r+x(rblk,cblk),x(rblk,cblk),y(rblk,cblk),'k','LineWidth',1)
end
end
hold off
% Reconstruct current frame using prediction error & reference frame
N2 = 2*N;
Br = double(zeros(Height,Width));
for r = N:N:Height
rblk = floor(r/N);
for c = N:N:Width
cblk = floor(c/N);
x1 = x(rblk,cblk); y1 = y(rblk,cblk);
Indr1 = floor(r+y1+1); Indr2 = floor(r+y1+N);
if Indr1 <= 0
Indr1 = 1;
end
if Indr2 > Height +N2
Indr2 = Height + N2;
end
Indc1 = floor(c+x1+1); Indc2 = floor(c+x1+N);
if Indc1 <= 0
Indc1 = 1;
end
if Indc2 > Width +N2
Indc2 = Width + N2;
end
RefBlk = A1(Indr1:Indr2,Indc1:Indc2);
%
[x2,y2] = meshgrid(Indr1:Indr2,Indc1:Indc2);
[x3,y3] = meshgrid(r-N+1:r,c-N+1:c);
z1 = interp2(x2,y2,RefBlk,x3,y3,'*linear');
Indx = isnan(z1);
z1(Indx==1) = RefBlk(Indx == 1);
Br(r-N+1:r,c-N+1:c)= round(pf(r-N+1:r,c-N+1:c) + z1);
end
end
figure,imshow(uint8(round(Br))),title('Reconstructed image')


function [x,y,pf] = MCpredict_Quarter(A,B,N,W)
% [x,y,pf] = MCpredict_Quarter(A,B,N,W)
% Computes motion vectors of N x N moving blocks
% in an intensity image using full search and
% does a motion compensated prediction to a quarter pel accuracy
% Input:
% A = reference frame
% B = current frame
% N = block size (nominal value is 8, assumed square)
% W = search window (2N x 2N)
% Output:
% x = horizontal component of motion vector
% y = Vertical component of motion vector
% pf = motion compensated prediction image, same size as input image

[Height,Width] = size(A);
% pad input images on left, right, top, and bottom
A1 = single(padarray(A,[W/2 W/2],'symmetric')); % reference block
B1 = single(padarray(B,[W/2 W/2],'symmetric')); % current block
NumRblk = Height/N;
NumCblk = Width/N;
x = zeros(NumRblk,NumCblk);% x-component of motion vector
y = zeros(NumRblk,NumCblk);% %y-component of motion vector
pf = single(zeros(Height,Width)); % predicted frame
% Find motion vectors to 1/4 pel accuracy
figure,imshow(B), title('Superimposed motion vectors')
hold on % display image & superimpose motion vectros
for r = N:N:Height
rblk = floor(r/N);
for c = N:N:Width
cblk = floor(c/N);
D = 1.0e+10;% initial city block distance
for u = -N:N
for l = -N:N
RefBlk = A1(r+u+1:r+u+N,c+l+1:c+l+N);
CurrentBlk = B1(r+1:r+N,c+1:c+N);
[x2,y2] = meshgrid(r+u+1:r+u+N,c+l+1:c+l+N);
[x3,y3] = meshgrid(r+u-0.25:r+u+N-1,c+l-0.25:c+l+N-1);
% interpolate at 1/4 pel
z1 = interp2(x2,y2,RefBlk,x3,y3,'*linear');
Indx = isnan(z1);
z1(Indx == 1) = CurrentBlk(Indx==1);
dd = CurrentBlk - round(z1);
d = sum(abs(dd(:)));
if d < D
D = d;
U = u+0.25; L = l+0.25;
pf(r:r+N-1,c:c+N-1) = dd;
end
end
end
x(rblk,cblk) = L; % Motion in the vertical direction
y(rblk,cblk) = U; % Motion in the horizontal direction
quiver(c+y(rblk,cblk),r+x(rblk,cblk),x(rblk,cblk),y(rblk,cblk),'k','LineWidth',1)
end
end
hold off
% Reconstruct current frame using prediction error &
reference frame
%
N2 = 2*N;
Br = single(zeros(Height,Width));
for r = N:N:Height
rblk = floor(r/N);
for c = N:N:Width
cblk = floor(c/N);
x1 = x(rblk,cblk); y1 = y(rblk,cblk);
Indr1 = floor(r+y1+1); Indr2 = floor(r+y1+N);
if Indr1 <= 0
Indr1 = 1;
end
if Indr2 > Height +N2
Indr2 = Height + N2;
end
Indc1 = floor(c+x1+1); Indc2 = floor(c+x1+N);
if Indc1 <= 0
Indc1 = 1;
end
if Indc2 > Width +N2
Indc2 = Width + N2;
end
RefBlk = A1(Indr1:Indr2,Indc1:Indc2);
[x2,y2] = meshgrid(Indr1:Indr2,Indc1:Indc2);
[x3,y3] = meshgrid(r-N+1:r,c-N+1:c);
z1 = interp2(x2,y2,RefBlk,x3,y3,'*linear');
Indx = isnan(z1);
z1(Indx==1) = RefBlk(Indx == 1);
Br(r-N+1:r,c-N+1:c)= round(pf(r-N+1:r,c-N+1:c) + z1);
end
end
figure,imshow(uint8(round(Br))),title('Reconstructed image')
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
j en comprend le principe ,mais je ne peux t aider.desolé
slts
0