Could someone help me with the errors I'm facing in this code ? The code is for Image Compression using Huffman Coding

조회 수: 1 (최근 30일)
clc;
clear all;
close all;
base = 2; % For base (b) Huffman Coding
%% READING THE TEXT FILE
img = imread('chair.png');
img1 = double(img(:));
[M, N] = size(img1);
%% HUFFMAN CODING
[sym_prob,sym] = hist(img1,unique(img1));
sym_prob = sym_prob/sum(sym_prob);
entropy = - sum(sym_prob .*(log10(sym_prob)/log10(base)));
disp(['The entropy of the file is: ' num2str(entropy)]);
% Creating the dictionary corresponding to each used symbol
[dict,avglen]=huffmandict(sym,sym_prob, base);
disp(['The average length of the Huffman code is: ' num2str(avglen)]);
disp(['The efficiency of the Huffman code is: ' num2str(entropy/avglen*100) '%']);
disp(['The redundancy of the Huffman code is: ' num2str((1 - (entropy/avglen))*100) '%']);
fprintf('\n')
enco = huffmanenco(img1, dict); % Encoding the data
%% STORING & DISPLAYING THE COMPRESSED DATA
huff_im=bin2dec(enco');
huff_im=reshape(huff_im,M,N);
huff_im=uint8(huff_im);
imwrite(huff_im, 'compressed_img.png')
imshow(huff_im)

답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by