필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Denoising and Compression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by