0 Replies - 372 Views - Last Post: 03 October 2013 - 01:49 PM Rate Topic: -----

#1 parkie02  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 5
  • Joined: 15-May 13

MATLAB Huffman Coding

Posted 03 October 2013 - 01:49 PM

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

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



Is This A Good Question/Topic? 0
  • +

Page 1 of 1