Can anyone help me fix the error in matlab coding of fractal image compression.  - Page 1
Forum section: electronics / general

author: magnumX
author_rank: Newbie
timestamp: December 01, 2017, 01:57:53 pm
content: 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 Imagefname=uigetfile('lenna.jpg');%opens ui for select image filesI=imread(fname); %reads selected imageI=imresize(I,[128 128]);%resize image into 256*256figure,imshow(I);title('Original Image');drawnow;tic;%record time%% 2.Quadtree Decompositions=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 blocksizeblkcount=length(i); %no of total blocksavg=zeros(blkcount,1);%record mean valuesfor k=1:blkcountavg(k)=mean2(I(i(k):i(k)+blksz(k)-1,j(k):j(k)+blksz(k)-1));%find mean%valueendavg=uint8(avg);figure,imshow((full(s)));title('Quadtree Decomposition');drawnow;%% 3.Huffman Encoding%prepare datai(end+1)=0;j(end+1)=0;blksz(end+1)=0;%set boundary elementsdata=[i;j;blksz;avg];%record total informationdata=single(data); %convert to singlesymbols= unique(data);% Distinct symbols that data source can producecounts = hist(data(, symbols);%find counts of symblos in given datap = counts./ sum(counts);% Probability distributionsp=round(p*1000);% scaled probabilitiesdict = huffmandict(symbols,p'); % Create dictionary.comp = huffmanenco(data,dict);% Encode the data.%% 4.Compressed%Time taken for compressiont=toc;fprintf('Time taken for compression = %f seconds\n',t);%compression ratiobits_in_original=8*256*256;bits_in_final=length(comp)+8*length(symbols)+8*length(sp);%Compression Ratio = total number of bits in original file, divided by%number of bits in final fileCR= bits_in_original/bits_in_final;fprintf('compression ratio= %f\n',CR);%% 5.Huffman Decodingtic;%record timedatanew = huffmandeco(comp,dict);% decode the data.zeroindx=find(data==0);%find boundriesinew=datanew(1:zeroindx(1)-1); %seperate row indexjnew=datanew(zeroindx(1)+1:zeroindx(2)-1); %seperate column indexblksznew=datanew(zeroindx(2)+1:zeroindx(3)-1);%seperate blocksizeavgnew=datanew(zeroindx(3)+1:end); %seperate mean values%% 6.Decompressed imageavgnew=uint8(avgnew);for k=1:blkcountoutim(inew(k):inew(k)+blksznew(k)-1,jnew(k):jnew(k)+blksznew(k)-1)=avgnew(k);endfigure,imshow(outim);title('Decompressed Image');drawnow;%% PSNR calculation%Time taken for De-compressiont=toc;fprintf('Time taken for Decompression = %f seconds\n',t);%Create psnr objecthpsnr = vision.PSNR;psnr = step(hpsnr, I,outim);fprintf('PSNR= %f\n',psnr);%display psnr

author: hans
author_rank: Super Contributor
timestamp: December 01, 2017, 04:20:04 pm
content: https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/46102/versions/2/previews/fractal%20image%20compression%20using%20Quadtree%20decomposition%20and%20huffman%20coding/main.m/index.html?access_key=https://nl.mathworks.com/matlabcentral/fileexchange/46102-fractal-image-compression-using-quadtree-decomposition-and-huffman-coding?requestedDomain=www.mathworks.comThe author mail is in the code. Maybe try mailing him.I suspect you're missing some plugin or external file that defines a vision object of unspecified type.edit:Apparently author has accepted a solution:https://nl.mathworks.com/matlabcentral/answers/370431-can-anyone-please-help-me-to-fix-this-error-in-the-coding-of-fractal-image-compression-your-help-i

author: magnumX
author_rank: Newbie
timestamp: December 02, 2017, 01:04:13 am
content: Thank you so much for your opinions .It helps me a lot. Greatly appreciate it.

author: magnumX
author_rank: Newbie
timestamp: December 03, 2017, 02:38:31 am
content: Quote from: hans on December 01, 2017, 04:20:04 pmthank you