image compression using dct,zigzag scan and runlength coding.

hello, I am trying to compress an image by applying dct, zigzag scan and run length coding. but I am stuck at zigzag coding.so can anybody tell me that how to apply zigzag scan now..here is my code till quantization.
clc;
I = imread('cameraman.tif');
I = im2double(I);
T= dctmtx(8);
B = blkproc(I,[8 8],'P1*x*P2',T,T');
%fun=@dct2;
%B = blkproc(A,[8 8],fun);
q= [16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99]/255;
B2= blkproc(B,[8 8],'round(x./P1).*P1',q);
imshow(I), figure, imshow(B), figure, imshow(B2);

6 commentaires

Thank you sir.. I have written the following code according to your suggestion. sir can you tell me that whether I am going in right direction? because i am not getting inverse of run length code..here is my code;
clc;
A = im2double(imread('cameraman.tif'));
T= dctmtx(8);
B = blkproc(A,[8 8],'P1*x*P2',T,T');
q= [16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99]/255;
B2= blkproc(B,[8 8],'round(x ./P1).*P1',q);
imshow(B2)
[M N]=size(B2)
fun=zigzag(B2)
fun=round(fun);
out=rle(fun);
in=irle(out);
in1=izigzag(in,M,N);
Looks plausible. We would need to see your rle and irle to check about why you are not getting a proper inverse.
hello sir,i have used rle & irle functions that are as followings:
function:
function Xrle=rle(XZv)
L=length(XZv);
j=1;
k=1;
i=1;
while i<2*L
comp=1;
for j=j:L
if j==L
break
end;
if XZv(j)==XZv(j+1)
comp=comp+1;
else
break
end;
end;
Xrle(k+1)=comp;
Xrle(k)=XZv(j);
if j==L & XZv(j-1)==XZv(j)
break
end;
i=i+1;
k=k+2;
j=j+1;
if j==L
if mod(L,2)==0
Xrle(k+1)=1;
Xrle(k)=XZv(j);
else
Xrle(k+1)=1;
Xrle(k)=XZv(j);
end;
break
end;
end;
and irle function:
function XZv=irle(x)
L=length(x);
s=1;
k=1;
i=1;
while i<=L
while s<=x(i+1)
XZv(k)=x(i);
s=s+1;
k=k+1;
end;
i=i+2;
s=1;
end;
sonam chhikara
sonam chhikara le 21 Sep 2015
Modifié(e) : sonam chhikara le 21 Sep 2015
what is P1,P2 and X in your code?
P1 will be T, P2 will be T' and x will be the data.
This code was designed using the blkproc() routine that was obsolete for several years before the code was posted.

Connectez-vous pour commenter.

Réponses (1)

Paula Souza
Paula Souza le 27 Jan 2016
Olá, como salvo os dados comprimidos pelo RLC no matlab?

1 commentaire

Walter Roberson
Walter Roberson le 27 Jan 2016
Modifié(e) : Walter Roberson le 27 Jan 2016
Approximate translation:
Hello, how to save compressed data by Run Length Coding in matlab?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by