# What is the problem in my following Code?

조회 수: 2(최근 30일)
PRIYANGA 2012년 9월 20일
Dear Friends! This is my Thesis Coding. I have to calculate the Mean imamge in two ways. First One is Normal method. Another one is Decoded Mean image calculated Using Fractal values. But I got The Decoded Mean image is very
c = im2uint8(im1);
% figure(1);
% imshow(c);
% title('Image used for training');
gsize=16;
nr=512;
nc=512;
% resize the image
c=imresize(c,[nr,nr]);
nc=nr; R=c(:,:,1);
G=c(:,:,2);
B=c(:,:,3);
% split the image of the range size
k=1; for i1=1:gsize:nr
for j1=1:gsize:nc
l=1;
for x=i1:1:i1+(gsize-1)
for y=j1:1:j1+(gsize-1)
rang1r(k,l)=R(x,y);
rang1g(k,l)=G(x,y);
rang1b(k,l)=B(x,y);
l=l+1;
end
end
drr=double(rang1r(k,:));
meanranr(k)=mean(drr);
varranr(k,:)=var(drr);
drg=double(rang1g(k,:));
meanrang(k)=mean(drg);
varrang(k,:)=var(drg);
drb=double(rang1b(k,:));
meanranb(k)=mean(drb);
varranb(k,:)=var(drb);
k=k+1;
end
end
rang1=cat(3,rang1r,rang1g,rang1b);
meanran=cat(3,meanranr,meanrang,meanranb);
varran=cat(3,varranr,varrang,varranb);
[nrr1,ncr1]=size(rang1);
% to display the mean image
n=sqrt(nrr1);l=1; for i1=1:1:n
for j1=1:1:n
meanimg1r(i1,j1)=meanranr(l);
meanimg1g(i1,j1)=meanrang(l);
meanimg1b(i1,j1)=meanranb(l);
l=l+1;
end
end
meanimg1=cat(3,meanimg1r,meanimg1g,meanimg1b);
meanimg = uint8(round(meanimg1-1));
figure(3); %
imshow(meanimg);
title('Mean Image of the training'); I got a Good Mean Image
% divide the mean image into blocks km=1; for i1=1:gsize:n
for j1=1:gsize:n
l=1;
for x=i1:1:i1+(gsize-1)
for y=j1:1:j1+(gsize-1)
mimageranr(km,l)=meanimg1r(x,y);
mimagerang(km,l)=meanimg1g(x,y);
mimageranb(km,l)=meanimg1b(x,y);
l=l+1;
end
end
km=km+1;
end
end
mimageran=cat(3,mimageranr,mimagerang,mimageranb);
gsize1=gsize/2; km=1;
for i1=1:gsize1:n
for j1=1:gsize1:n
l=1;
for x=i1:1:i1+(gsize1-1)
for y=j1:1:j1+(gsize1-1)
mimageran1r(km,l)=meanimg1r(x,y);
mimageran1g(km,l)=meanimg1g(x,y);
mimageran1b(km,l)=meanimg1b(x,y);
l=l+1;
end
end
km=km+1;
end
end
mimageran1=cat(3,mimageran1r,mimageran1g,mimageran1b);
llim=10; if (gsize == 16)
nvar = 7; nvar1 = 9;
elseif (gsize == 8)
nvar = 11; nvar1 = 13;
elseif (gsize == 4)
nvar = 15; nvar1 = 17;
else nvar = 19; end
threshold=10;a=1;e=1;e1=1;b=1;w=1;w1=1;eno=0;
% compute the fractal code for i1=1:1:nrr1
disp(i1);
if (varran(i1) < threshold)
% Code using mean value
label(i1)=0;
mgacoder(e)=meanranr(i1);
mgacodeg(e)=meanrang(i1);
mgacodeb(e)=meanranb(i1);
e=e+1;
mgacode=cat(3,mgacoder,mgacodeg,mgacodeb);
else
% code using genetic Algorithm
label(i1)=1;
[isomer alphr meanrr dom1r errr]=ga(rang1r(i1,:),mimageranr,nvar,20);
[isomeg alphg meanrg dom1g errg]=ga(rang1g(i1,:),mimagerang,nvar,20);
[isomeb alphb meanrb dom1b errb]=ga(rang1b(i1,:),mimageranb,nvar,20);
err=(errr+errg+errb)/3;
if (err < llim)
label1(w)=0;
gacoder(a,:) = [isomer alphr meanrr dom1r];
gacodeg(a,:) = [isomeg alphg meanrg dom1g];
gacodeb(a,:) = [isomeb alphb meanrb dom1b];
a=a+1;
gacode=cat(3,gacoder,gacodeg,gacodeb);
else
label1(w)=1;
[rangr]=qtsplit(rang1r(i1,:),gsize1);
[rangg]=qtsplit(rang1g(i1,:),gsize1);
[rangb]=qtsplit(rang1b(i1,:),gsize1);
for x=1:1:4
drr1=double(rangr(x,:));
meansrangr(x)=mean(drr1);
varsranr(x,:)=var(drr1);
drg1=double(rangg(x,:));
meansrangg(x)=mean(drg1);
varsrang(x,:)=var(drg1);
drb1=double(rangb(x,:));
meansrangb(x)=mean(drb1);
varsranb(x,:)=var(drb1);
rang=cat(3,rangr,rangg,rangb);
meansrang=cat(3,meansrangr,meansrangg,meansrangb);
varsran=cat(3,varsranr,varsrang,varsranb);
if (varsran(x) < threshold/2)
lab(w1)=0;
mgacode1r(e1)=meansrangr(x);
mgacode1g(e1)=meansrangg(x);
mgacode1b(e1)=meansrangb(x);
e1=e1+1;
mgacode1=cat(3,mgacode1r,mgacode1g,mgacode1b);
else
lab(w1)=1;
[isomeqr alphqr meanrqr dom2qr errqr] = ga(rangr(x,:),mimageran1r,nvar1,40);
[isomeqg alphqg meanrqg dom2qg errqg] = ga(rangg(x,:),mimageran1g,nvar1,40);
[isomeqb alphqb meanrqb dom2qb errqb] = ga(rangb(x,:),mimageran1b,nvar1,40);
errq=(errqr+errqg+errqb)/3;
if (errq > llim)
eno=eno+1;
end
gacode1r(b,:)=[isomeqr,alphqr,meanrqr,dom2qr];
gacode1g(b,:)=[isomeqg,alphqg,meanrqg,dom2qg];
gacode1b(b,:)=[isomeqb,alphqb,meanrqb,dom2qb];
b=b+1;
gacode1=cat(3,gacode1r,gacode1g,gacode1b);
end
w1=w1+1;
end
end
w=w+1;
end
end
eno
%decoding
% compute the mean image and display tic w=1;a=1;b=1;w1=1;w2=1;e=1;e1=1;
for x=1:1:sqrt(nrr1)
for y=1:1:sqrt(nrr1)
if (label(w)==0)
dmimgr(x,y)=mgacoder(e);
dmimgg(x,y)=mgacodeg(e);
dmimgb(x,y)=mgacodeb(e);
e=e+1;
dmimg=cat(3,dmimgr,dmimgg,dmimgb);
else
if (label1(w1)==0)
dmimgr(x,y)=gacoder(a,3);
dmimgg(x,y)=gacodeg(a,3);
dmimgb(x,y)=gacodeb(a,3);
a=a+1;
dmimg=cat(3,dmimgr,dmimgg,dmimgb);
else
sumvq=0;sumvqr=0;sumvqg=0;sumvqb=0;
for i=1:4
if (lab(w2)==0)
sumvqr=sumvqr+mgacode1r(e1);
sumvqg=sumvqg+mgacode1g(e1);
sumvqb=sumvqb+mgacode1b(e1);
e1=e1+1;
sumvq=cat(3,sumvqr,sumvqg,sumvqb);
else
sumvqr=sumvqr+gacode1r(b,3);
sumvqg=sumvqg+gacode1g(b,3);
sumvqb=sumvqb+gacode1b(b,3);
b=b+1;
sumvq=cat(3,sumvqr,sumvqg,sumvqb);
end
w2=w2+1;
end
dmimg=sumvq/4;
end
w1=w1+1;
end
w=w+1;
end
end
cimage = uint8(round(dmimg - 1));
figure(4);
imshow(cimage);
title('Decoded Mena image'); % I am not get properDecoded Mean Image
##### 댓글 수: 2표시 이전 댓글 수: 1숨기기 이전 댓글 수: 1
Jan 2012년 9월 20일
편집: Jan 2012년 9월 20일
Please format the code properly. You find enough corresponding instructions in the forum. Then explain the actual problem. "But I got The Decoded Mean image is very" and "I am not get properDecoded Mean Image" does not allow to give instructions for a solution.

댓글을 달려면 로그인하십시오.

### 범주

Find more on Get Started with Image Processing Toolbox 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!

Translated by