retrieving image after encoding

my code is
A=imread('imagcp.bmp');
A=A(:);
YourVector=double(A);
symbols = unique(YourVector(:));
counts = hist(YourVector(:), symbols);
p = double(counts) ./ sum(counts)
[dict,avglen]=huffmandict(symbols,p);
comp=huffmanenco(A,dict);
I want to dispaly image after encoding,plz help

 채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 26일

0 개 추천

"comp" is not something that can be displayed. You need to do a huffman decoding of "comp" with "dict" in order to restore the image.

댓글 수: 7

FIR
FIR 2012년 12월 27일
편집: Walter Roberson 2012년 12월 27일
walter i have displayed decoded image but the thing is i need encoded image to be displayed and find compression ratio
my code
clc
clear all
a=imread('cameraman.tif')
I=a;
[m,n]=size(I);
Totalcount=m*n;
cnt=1;
sigma=0;
%computing the cumulative probability.
for i=0:255
k=I==i;
count(cnt)=sum(k(:))
pro(cnt)=count(cnt)/Totalcount;
sigma=sigma+pro(cnt);
cumpro(cnt)=sigma;
cnt=cnt+1;
end;
symbols = [0:255];
%Huffman code Dictionary
dict = huffmandict(symbols,pro);
%function which converts array to vector
vec_size = 1;
for p = 1:m
for q = 1:n
newvec(vec_size) = I(p,q);
vec_size = vec_size+1;
end
end
%Huffman Encodig
hcode = huffmanenco(newvec,dict);
%Huffman Decoding
dhsig1 = huffmandeco(hcode,dict);
% convertign dhsig1 double to dhsig uint8
dhsig = uint8(dhsig1);
%vector to array conversion
dec_row=sqrt(length(dhsig));
dec_col=dec_row;
%variables using to convert vector 2 array
arr_row = 1;
arr_col = 1;
vec_si = 1;
for x = 1:m
for y = 1:n
back(x,y)=dhsig(vec_si);
arr_col = arr_col+1;
vec_si = vec_si + 1;
end
arr_row = arr_row+1;
end
imshow(back),title('decoded_Image')
Notice that your code never resets arr_col to 1 when the row changes. Not that it matters in your code as you never use arr_col or arr_row for anything.
I don't know why you don't use reshape() to construct "back", but anyhow...
Assuming that your image is square is a bad idea. You should take my earlier advice of including the sizes along with the data being logically transmitted (that is, include the sizes at the beginning of hcode, and strip them out of hcode before decoding.
Does the assignment say anything about having to display the encoded image in the form of an image ? If it does, then
imagesc(hcode)
and prepare to be underwhelmed (and to get a warning about how the image has been scaled down to fit in the window.)
FIR
FIR 2012년 12월 27일
shows the encoded image,why i get like this,
please as per ur advice can u send the code for dislaying encoded and decoded image as u said the code above is not sufficient as u said to use reshape,plz assist in sending some codes
Instead of your "for x" "for y" loop,
back = reshape(dhsig, n, m) .';
As to why the encoded image shows up like it does, what were you expecting when you display a vector of binary values?
FIR
FIR 2012년 12월 27일
ok walter thanks
FIR
FIR 2012년 12월 27일
walter but why the size increases after encoding
Walter Roberson
Walter Roberson 2012년 12월 27일
Each element of the output represents one bit. The original data was 8 bits per element.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Denoising and Compression에 대해 자세히 알아보기

태그

질문:

FIR
2012년 12월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by