huffman encoding for image compression

44 ビュー (過去 30 日間)
Nidhi Kumari
Nidhi Kumari 2018 年 10 月 9 日
コメント済み: Ahmed 2022 年 12 月 30 日
i am using the following code for huffman encoding-
img = imread('xyz.jpg');
Image = rgb2gray(img);
Image = Image(:);
[N M] = size(Image)
Count = zeros(256,1)
for i = 1:N
for j = 1:M
Count(Image(i,j)+1)=Count(Image(i,j)+1)+1;
end
end
prob = Count/(M*N)
symbols = 1:256;
[dict,avglen] = huffmandict(symbols,prob);
comp = huffmanenco(Image,dict);
but i am getting the following error-
Error using huffmanenco (line 86)
The Huffman dictionary provided does not have the codes for all the input signals.
Error in Untitled2 (line 14)
comp = huffmanenco(Image,dict);
please suggest the required changes
  3 件のコメント
Swarnali Sadhukhan
Swarnali Sadhukhan 2019 年 5 月 3 日
clc;
clear all;
close all;
warning off;
x = imread('brain.jpg');
img=imresize(x,[256 256]);
Image = rgb2gray(img);
%Image = Image(:);
[M N] = size(Image)
Count = 0:255;
for i = 1:M
for j = 1:N
Count(Image(i,j)+1)=Count(Image(i,j)+1)+1;
end
end
prob = Count/(M*N);
symbols = 0:255;
[dict,avglen] = huffmandict(symbols,prob);
comp = huffmanenco(Image,dict);
figure,imshow(comp); title('encoded.JPG');
Swarnali Sadhukhan
Swarnali Sadhukhan 2019 年 5 月 3 日
Error using huffmandict (line 107)
The sum of elements of the probability
vector must be 1
Error in huffman (line 19)
[dict,avglen] =
huffmandict(symbols,prob);
I am getting this error .How can I solve this?

サインインしてコメントする。

回答 (3 件)

reb rebz
reb rebz 2019 年 3 月 22 日
img = imread('xyz.jpg');
Image = rgb2gray(img);
Image = Image(:);
[N M] = size(Image)
Count = zeros(256,1)
for i = 1:N
for j = 1:M
Count(Image(i,j)+1)=Count(Image(i,j)+1)+1;
end
end
prob = Count/(M*N)
symbols = 0:255;
[dict,avglen] = huffmandict(symbols,prob);
comp = huffmanenco(Image,dict)
  1 件のコメント
Islam Abu Tabikh
Islam Abu Tabikh 2019 年 5 月 12 日
Did you know how ???

サインインしてコメントする。


satyendra kumar
satyendra kumar 2019 年 3 月 23 日
i am using the following code for huffman encoding-
clear all
clc
A=imread('cameraman.tif');
A1=double(A(:));
[p,symbols]=hist(A1,unique(A1));
p=p/sum(p);
[dict,avglen] = huffmandict(symbols,p);
comp = huffmanenco(A1,dict);

SS
SS 2019 年 10 月 11 日
can i use huffman coding for both lossy and lossless image compression??
  1 件のコメント
Ahmed
Ahmed 2022 年 12 月 30 日
yes you can

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDenoising and Compression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by