Size of compressed image is larger than image .... How to solve this problem?
Mostra commenti meno recenti
The following code works well, but the size of compressed image is larger than the image. Need some assistance....
%clearing all variableas and screen
clear all;
close all;
clc;
%Reading image
a=imread('encrypted.jpg');
figure,imshow(uint8(a))
%size of the image
[m,n]=size(a);
Totalcount=m*n;
%variables using to find the probability
cnt=1;
sigma=0;
%computing the cumulative probability.
for i=0:255;
k=a==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:255];
%Huffman code Dictionary
dict = huffmandict(symbols,pro);
%function which converts array to vector
vec_size = 1;
for p = 1:m
for q = 1:n
newvec(vec_size) = a(p,q);
vec_size = vec_size+1;
end
end
%Huffman Encodig
hcode = huffmanenco(newvec,dict);
%vector to array conversion
enco_row=sqrt(length(hcode));
enco_col=enco_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)=hcode(vec_si);
arr_col = arr_col+1;
vec_si = vec_si + 1;
end
arr_row = arr_row+1;
end
imwrite(back,'encoded5.jpg')
%end of the huffman coding
1 Commento
KSSV
il 12 Nov 2021
Read about imresize.
Risposta accettata
Più risposte (1)
Jan
il 12 Nov 2021
0 voti
If the original image was written with a low quality, the default Quality=75 of imwrite might increase the file size.
Categorie
Scopri di più su Denoising and Compression in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!