How to transform distorted video to a normal video?

I am having a problem with displaying the video as it is shown as a distorted and corrupted video.
also the binary representation of the Rdouble, Gdouble, Bdouble isn't correct for example for 16 it gives a row equals to 1000 not 10000 and so on.
This is my code
clc
close all
clear all
obj=VideoReader('Stephan.avi');
a=read(obj);
frames=get(obj,'NumberOfFrames');
for i=1:frames
I(i).cdata=a(:,:,:,i);
end
s=size(I(1).cdata);
mov(1:frames) =struct('cdata', zeros(s(1),s(2), 3, 'uint8'),'colormap', []);
for Frame=1:296
%Red Components of the Frame
R=I(Frame).cdata(:,:,1);
%Green Components of the Frame
G=I(Frame).cdata(:,:,2);
%Blue Components of the Frame
B=I(Frame).cdata(:,:,3);
Rr=reshape(R, 1, []); %we reshape to put the red as a stream of 1 row
Gr=reshape(G, 1, []); %we reshape to put the green as a stream of 1 row
Br=reshape(B, 1, []); %we reshape to put the blue as a stream of 1 row
Rdouble = double(Rr);
Gdouble = double(Gr);
Bdouble = double(Br);
Rbin = de2bi(Rdouble);
Gbin = de2bi(Rdouble);
Bbin = de2bi(Rdouble);
pcksize=1024;
noofpckts= 101376*8/pcksize;
Rpck= reshape(Rbin,[noofpckts,pcksize]);
Gpck= reshape(Gbin,[noofpckts,pcksize]);
Bpck= reshape(Bbin,[noofpckts,pcksize]);
%trellis = poly2trellis(ConstraintLength,CodeGenerator)
trellis = poly2trellis(5,[25 27 33 37]);
A=[];
B=[];
C=[];
for i=1:noofpckts
Rcoded= convenc(Rpck(i,:),trellis);
Gcoded= convenc(Gpck(i,:),trellis);
Bcoded= convenc(Bpck(i,:),trellis);
%a = 0.0001;
%b = 0.2;
%p = rand(1, 1) .* (b-a) + a;
%p = 0.00000000001;
%Rerror= bsc(Rcoded,p);
%Gerror= bsc(Gcoded,p);
%Berror= bsc(Bcoded,p);
tbdepth = 35;
Rdecoded = vitdec(Rcoded,trellis,tbdepth,'trunc','hard');
Gdecoded = vitdec(Gcoded ,trellis,tbdepth,'trunc','hard');
Bdecoded = vitdec(Bcoded,trellis,tbdepth,'trunc','hard');
A=[A Rdecoded];
B=[B Gdecoded];
C=[C Bdecoded];
end
Rnpck= reshape(A,[],pcksize);
Gnpck= reshape(B,[],pcksize);
Bnpck= reshape(C,[],pcksize);
Rrr=reshape(Rnpck, [] ,8);
Grr=reshape(Gnpck, [] ,8);
Brr=reshape(Bnpck, [] ,8);
Rn=bi2de(Rrr);
Gn=bi2de(Grr);
Bn= bi2de(Brr);
Rnn=uint8(Rn);
Gnn=uint8(Gn);
Bnn=uint8(Bn);
Rnnn = reshape(Rnn,[288,352]);
Gnnn = reshape(Gnn,[288,352]);
Bnnn = reshape(Bnn,[288,352]);
mov(1,Frame).cdata(:,:,1) =Rnnn;
mov(1,Frame).cdata(:,:,2) =Gnnn;
mov(1,Frame).cdata(:,:,3) =Bnnn;
disp(Frame)
end
vid=VideoWriter('tagdeed','Motion JPEG AVI');
%vid = VideoWriter("D:\GUC\Spring 2023\Channel coding\Channel coding Project\Channel coding\trial3afreet.avi",'Uncompressed AVI');
open(vid);
writeVideo(vid,mov);
close(vid);

Answers (0)

Tags

Asked:

on 24 May 2023

Commented:

on 24 May 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!