title: Issues with MATLAB: JPEG2000 compression scheme using wavelet toolbox
body: <p>Me and a teammate are working on a JPEG2000 similar compression scheme for a project.  It utilizes matlab and the wavelet toolbox.  </p>
  
  <p>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: <code>[dict,avglen] = huffmandict(cQ,p); % Create dictionary.</code><br>
  Error:
  ??? Error using ==> huffmandict at 174
  Source symbols repeat</p>
  
  <p>I am not sure if this has to do with repeating values in the matrix because no run-length coding has been done.</p>
  
  <p>Error in ==> project at 41
  [dict,avglen] = huffmandict(cQ,p); % Create dictionary.</p>
  
  <p>Any tips or information would be beneficial.<br>
  Also, I am unsure whether I need a pre-processing step </p>
  
  <p>The code is as follows:</p>
  
  <pre><code>%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.
  </code></pre>