필터 지우기
필터 지우기

how can i do huffman encoding in image compression

조회 수: 2 (최근 30일)
omar
omar 2012년 12월 8일
댓글: Walter Roberson 2021년 5월 18일
hi,i am doing lossy image compression using discrete cosine transform i had done all the steps of the compression(dct then quantization then zigzag scan) now i have a vector and i want to do huffman encoding i know that the code as follows
[dict,avglen] = huffmandict(symbols,p)
comp = huffmanenco(sig,dict)
i am asking now how to get the symbol and p(probability) from the large vector that i have to do the encoding
  댓글 수: 1
shabu sathyadhas
shabu sathyadhas 2016년 3월 22일
편집: Walter Roberson 2018년 8월 28일
%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

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 8일
If your vector is uint8() then one way of doing it is
symbols = unique(YourVector(:));
counts = hist(YourVector(:), symbols);
p = double(counts) ./ sum(counts);
This is not the only way.
  댓글 수: 19
NAGA PAVAN KALYAN KUMAR TENTU
NAGA PAVAN KALYAN KUMAR TENTU 2021년 5월 18일
편집: Walter Roberson 2021년 5월 18일
I = imread('cameraman.tif');
I = im2double(I);
T = dctmtx(8);
dct = @(block_struct) T * block_struct.data * T';
B = blockproc(I,[8 8],dct);
mask = [1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2 = blockproc(B,[8 8],@(block_struct) mask .* block_struct.data);
symbols = unique(B2(:));
counts = hist(B2(:), symbols);
p = double(counts) ./ sum(counts);
[dict,avglen] = huffmandict(symbols,p);
comp = huffmanenco(I,dict);
Sir there is error in above code in last command sir. sir could you help in fixing that error? Or Is that above code is for write for Huffman encoding in image compression sir.?
Walter Roberson
Walter Roberson 2021년 5월 18일
You are applying huffman dictionary to floating point numbers, and those are only going to be bit-for-bit identical mostly by coincidence.
You then try to do a huffman encoding of the image, instead of based upon a vector of B2 values.
... Are you sure you want to use floating point numbers as your symbols ?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Source Coding에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by