简体   繁体   中英

Issues with MATLAB: JPEG2000 compression scheme using wavelet toolbox

Me and a teammate are working on a JPEG2000 similar compression scheme for a project. It utilizes matlab and the wavelet toolbox.

There are 2 problems. My lack of knowledge with JPEG2000 leads me to believe I am missing steps for this compression process. The 2nd problem is an actual error which involves: [dict,avglen] = huffmandict(cQ,p); % Create dictionary. [dict,avglen] = huffmandict(cQ,p); % Create dictionary.
Error: ??? Error using ==> huffmandict at 174 Source symbols repeat

I am not sure if this has to do with repeating values in the matrix because no run-length coding has been done.

Error in ==> project at 41 [dict,avglen] = huffmandict(cQ,p); % Create dictionary.

Any tips or information would be beneficial.
Also, I am unsure whether I need a pre-processing step

The code is as follows:

%wavelet based compression sub-band coding
clear all;
close all;
x=imread('1.png');%input image
n=input('enter the desired decompositon level '); %decompositon level
Q=input('enter the desired quantization step size '); %quantization level

%begin wavelet decomposition
c = [];
sx =  size(x);
s = zeros(n+2,length(sx));
if isempty(x) , return; end

s(end,:) = size(x);
for i=1:n
    [x,h,v,d] = dwt2(x,'haar'); % decomposition
    c = [h(:)' v(:)' d(:)' c];     % store details
    s(n+2-i,:) = size(x);          % store size
end

% Last approximation.
c = [x(:)' c];
s(1,:) = size(x);

%Begin Quantization

cQ=round(c/Q);

%Begin Entropy Encoding



scQ=length(cQ);
l=1;
for i=1:(scQ-1);
    l=l/2;
    p(i)=l;
end
p(scQ)=p(scQ-1);

[dict,avglen] = huffmandict(cQ,p); % Create dictionary.
actualsig = randsrc(100,1,[cQ; p]); % Create data using p.
comp = huffmanenco(actualsig,dict); % Encode the data.

I know that it is only a partial answer, but it appears that the error is caused because your input contains duplicates.

This can be prevented by using the unique command.

On this website they recommend something like:

[symbols,p]=hist(A,double(unique(A)))

But as I am not sure how your input works, you may need to use

unique([cQ; p],'rows')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM