Hai, I am working on lossless compression of hyperspectral image. I have used 2 prediction stages first a median predictor, a inter band predictor after that quantization is done. After that Huffman coding of the quantized matrix is to be done.

1 view (last 30 days)
During Huffman coding of the quantized matrix the count value (which is set to find out same pixel values in a matrix) is getting as zero. Can anyone help me to correct the code? The code that I had written is given below.
load('C:\Documents and Settings\user\My Documents\MATLAB\indian pines\Indian_pines.mat') %MEDIAN PREDICTOR A = (indian_pines(:,:,10)); imagesc(A); [m,n]=size(A); pre=A; prerror=zeros(m,n); for i=2:m for j=2:n if A(i-1,j-1)>=max(A(i,j-1),A(i-1,j)) pre(i,j)=min(A(i,j-1),A(i-1,j)); elseif A(i-1,j-1)<=min(A(i,j-1),A(i-1,j)) pre(i,j)=max(A(i,j-1),A(i-1,j)); else pre(i,j)=A(i-1,j)+A(i,j-1)-A(i-1,j-1); end prerror(i,j)=A(i,j)-pre(i,j); end end s=max(max(max(prerror(:)))); figure,imagesc(pre) figure,imagesc(prerror) cr1 = A(i,j)./pre(i,j)
%INTER BAND PREDICTOR B = (indian_pines(:,:,11)); figure,imagesc(B) AM=mean(pre); BM=mean(B); MMA= mean(mean(pre)); MMB= mean(mean(B)); for i= 1:8 ASQ= sum(sum((pre.*pre))); end for i=1:8 SQASQ = (sum(sum(pre)))^2; end SIGA= 8*(ASQ-SQASQ); ABM = mean(mean((pre .* B))); for i=1:8 MULTIPLYAB=sum(sum( pre.*B)); end for i=1:8 AI= sum(sum(pre)); end for i=1:8 BI= sum(sum(B)); end
for i= 1:8 ASQ= sum(sum((pre.*pre))); end for i=1:8 SQASQ = (sum(sum(pre)))^2; end ALPHA = (8*(MULTIPLYAB)-(AI*BI))/((8*(ASQ))-SQASQ); COEFF2 = MMB - (ALPHA*MMA); Y = ALPHA*pre + COEFF2; figure,imagesc(Y) cr2 = pre(i,j)./Y(i,j) cr3 = B(i,j)./Y(i,j)
%QUANTIZATION
img_size = size(Y); x_max = img_size(1); y_max = img_size(2);
Y_scalar = Y;
for i = 1 : x_max for j = 1 : y_max for color = 1:3 if Y(i,j) < 64 Y_scalar(i, j) = 512; elseif Y(i,j) < 128 Y_scalar(i, j) = 768; elseif Y(i,j) < 192 Y_scalar(i, j) = 2048; elseif Y(i,j) < 192 Y_scalar(i, j) = 3072; else Y_scalar(i, j) = 4096; end end end end
figure(1); imagesc(Y);
figure(2); image(Y_scalar); cr4=Y(i,j)./Y_scalar(i,j)
%HUFFMAN CODING [m,n]=size(Y_scalar); Totalcount=m*n;
%variables using to find the probability cnt=1; sigma=0; %count=zeros(); %computing the cumulative probability. for i=0:65536 k=Y==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:65536];
%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) = I(p,q); vec_size = vec_size+1; end end
%Huffman Encodig hcode = huffmanenco(newvec,dict);

Answers (0)

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!