Matlab Code for Rle Decoding
Hi ,
I am rashi new at a Matlab and doing for project for Image compression using Run Length Encoding I tried this code and was able to compress my Image but when it comes for decompression I an unable to get my original image back Plzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Plzzzzzzzzzzzzzzzzzzzzzzzz Help me out
My code for Image compression using RLE is
function[rle]=inter(f)
clear;
I=imread('c:/gis11.jpg','jpg');
%I=imread('c:/gis4.jpg','jpg');
imshow(I);title('original image');
level=graythresh(I);
imshow(I);title('grey')
bw=im2bw(I,level);
figure;imshow(bw);title('binary image');
a=bw'; a=a(:); a=a';
a=double(a);
rle(1)=a(1); m=2; rle(m)=1;
for i=1:length(a)-1
if a(i)==a(i+1)
rle(m)=rle(m)+1;
else
m=m+1; rle(m)=1; %dynamic allocation and initialization of next element of rle
end
end
display(rle);
image(rle);title('Compressed image');
This Code runs Correct as far as compression is concerned
BUT the problem is in Decompressing the Image it gives a blank image
my code for RLE Decoding is
% RUN LENGTH DECODING
clear;
%rle=imread('c:/compressed.jpg','jpg');
rle=imread('c:/catcom1.jpg','jpg');
% loop to calculate length of binary data matrix
l=0;
for t=2:length(rle)
l=l+rle(t);
end
a=false(1,l); % preallocate array
a(1)=rle(1);
m=2;n=1;
for i = 2:length(rle)-1
for j=1:rle(m)
a(n+1)=a(n); n=n+1;
end
m=m+1;a(n)=~a(n);
end
a=double(a); %ignore if u want output matrix as logical
image(a);title('original Image');
PLZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ Help Me
I am rashi new at a Matlab and doing for project for Image compression using Run Length Encoding I tried this code and was able to compress my Image but when it comes for decompression I an unable to get my original image back Plzzzzzzzzzzzzzzzzzzzzzzzzzzzzz Plzzzzzzzzzzzzzzzzzzzzzzzz Help me out
My code for Image compression using RLE is
function[rle]=inter(f)
clear;
I=imread('c:/gis11.jpg','jpg');
%I=imread('c:/gis4.jpg','jpg');
imshow(I);title('original image');
level=graythresh(I);
imshow(I);title('grey')
bw=im2bw(I,level);
figure;imshow(bw);title('binary image');
a=bw'; a=a(:); a=a';
a=double(a);
rle(1)=a(1); m=2; rle(m)=1;
for i=1:length(a)-1
if a(i)==a(i+1)
rle(m)=rle(m)+1;
else
m=m+1; rle(m)=1; %dynamic allocation and initialization of next element of rle
end
end
display(rle);
image(rle);title('Compressed image');
This Code runs Correct as far as compression is concerned
BUT the problem is in Decompressing the Image it gives a blank image
my code for RLE Decoding is
% RUN LENGTH DECODING
clear;
%rle=imread('c:/compressed.jpg','jpg');
rle=imread('c:/catcom1.jpg','jpg');
% loop to calculate length of binary data matrix
l=0;
for t=2:length(rle)
l=l+rle(t);
end
a=false(1,l); % preallocate array
a(1)=rle(1);
m=2;n=1;
for i = 2:length(rle)-1
for j=1:rle(m)
a(n+1)=a(n); n=n+1;
end
m=m+1;a(n)=~a(n);
end
a=double(a); %ignore if u want output matrix as logical
image(a);title('original Image');
PLZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ Help Me
0