Effacer les filtres
Effacer les filtres

MATLAB Huffman Coding. Can someone offer me help with the sorting and calculating of the probabilities?

2 vues (au cours des 30 derniers jours)
Hallo, can somebody help me with my code. I am busy implementing the huffman code, but calculating the probabilities dont work right out. It has to take the two lowest probabilities and then add them together. Then it has to be sorted and done again until only two probabilities remain. This is what my program do do
0.933522222222222 0.954933333333333 0.977122222222222
0.0228777777777778 0.0228777777777778 0.0228777777777778
0.0221888888888889 0.0221888888888889
0.0214111111111111
Here is my code:
format long;
%clearing all variableas and screen
clear all;
close all;
clc;
%Reading image
a=imread('D:\face.tif');
figure,imshow(a)
%converting an image to grayscale
I=a;
%size of the image
[f,g]=size(I);
Totalcount=f*g;
%variables using to find the probability
cnt=1;
sigma=0;
%computing the cumulative probability.
for i=0:f
k=I==i;
count(cnt)=sum(k(:))
%pro array is having the probabilities
pro(cnt)=count(cnt)/Totalcount;
sigma=sigma+pro(cnt);
cumpro(cnt)=sigma;
cnt=cnt+1;
end;
%Symbols for an image
symbols = [0:f];
%Order probabilities
for q=1:f
matrix(1,q) = pro(q);
end;
sorted = sort(transpose(matrix),'descend');
%Sort probabilities and add them together
for n=2:f-1
for m=1:f-n
sorted(m,n) = sorted(m,n-1);
if m==(f-n)
sorted(f+1-n,n) = sorted(f+2-n,n-1)+sorted(f+1-n,n-1);
final = sort(sorted,'descend');
end
end
end
  2 commentaires
Walter Roberson
Walter Roberson le 4 Oct 2013
How are you maintaining the list of which symbols have been merged into which branch, so that you can do the decoding?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Denoising and Compression dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by