How to solve this error in MATLAB coding of fractal image compression?

0 (0%)
3 (100%)

Total Members Voted: 3

Author Topic: Can anyone help me fix the error in matlab coding of fractal image compression.  (Read 282 times)

0 Members and 1 Guest are viewing this topic.

Offline magnumX

  • Contributor
  • Posts: 8
  • Country: sg
hpsnr = vision.PSNR;
psnr = step(hpsnr, I,outim);

error messages:
Undefined variable "vision"
Error in main (line 74) hpsnr = vision.PSNR;

*The original source code attached below

%% 1.input Image
fname=uigetfile('lenna.jpg');%opens ui for select image files
I=imread(fname); %reads selected image
I=imresize(I,[128 128]);%resize image into 256*256
figure,imshow(I);title('Original Image');drawnow;
tic;%record time

%% 2.Quadtree Decomposition
s=qtdecomp(I,0.2,[2 64]);%divides image using quadtree decomposition of
                         %threshold .2 and min dim =2 ,max dim =64
[i,j,blksz] = find(s); %record x and y coordinates and blocksize
blkcount=length(i);  %no of total blocks
avg=zeros(blkcount,1);%record mean values
for k=1:blkcount
    avg(k)=mean2(I(i(k):i(k)+blksz(k)-1,j(k):j(k)+blksz(k)-1));%find mean
figure,imshow((full(s)));title('Quadtree Decomposition');drawnow;
%% 3.Huffman Encoding
%prepare data
i(end+1)=0;j(end+1)=0;blksz(end+1)=0;%set boundary elements
data=[i;j;blksz;avg];%record total information
data=single(data); %convert to single
symbols= unique(data);% Distinct symbols that data source can produce
counts = hist(data(:), symbols);%find counts of symblos in given data
p = counts./ sum(counts);% Probability distribution
sp=round(p*1000);% scaled probabilities
dict = huffmandict(symbols,p'); % Create dictionary.
comp = huffmanenco(data,dict);% Encode the data.

%% 4.Compressed
%Time taken for compression
fprintf('Time taken for compression = %f seconds\n',t);
%compression ratio
%Compression Ratio = total number of bits in original file, divided by
%number of bits in final file
CR= bits_in_original/bits_in_final;
fprintf('compression ratio= %f\n',CR);

%% 5.Huffman Decoding
tic;%record time
datanew = huffmandeco(comp,dict);% decode the data.
zeroindx=find(data==0);%find boundries
inew=datanew(1:zeroindx(1)-1); %seperate row index
jnew=datanew(zeroindx(1)+1:zeroindx(2)-1); %seperate column index
blksznew=datanew(zeroindx(2)+1:zeroindx(3)-1);%seperate blocksize
avgnew=datanew(zeroindx(3)+1:end); %seperate mean values

%% 6.Decompressed image
for k=1:blkcount
figure,imshow(outim);title('Decompressed Image');drawnow;

%% PSNR calculation
%Time taken for De-compression
fprintf('Time taken for Decompression = %f seconds\n',t);
%Create psnr object
hpsnr = vision.PSNR;
psnr = step(hpsnr, I,outim);
fprintf('PSNR= %f\n',psnr);%display psnr

Offline magnumX

  • Contributor
  • Posts: 8
  • Country: sg
Thank you so much for your opinions .It helps me a lot. Greatly appreciate it.

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo