显示 更早的评论
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
2012-12-26
"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
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.)
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?
ok walter thanks
walter but why the size increases after encoding
Each element of the output represents one bit. The original data was 8 bits per element.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Denoising and Compression 的更多信息
标签
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
