필터 지우기
필터 지우기

Can anybody help me to solve the error from this code function it will be a nice help

조회 수: 3 (최근 30일)
clc;
close all;
clear variables;
clear all;
function inv_transformed_img= KT(I)
I=imread("cameraman.tif");
I=im2double(I);
m=1;
for i=1:8:256
for j=1:8:256
for x=0:7
for y=0:7
img(x+1,y+1)=i(i+x,j+y);
end
end
k=0;
for l=1:8
img_expect{k+1}=img(:,l)*img(:,l)';
k=k+1;
end
imgexp=zeros(8:8);
for l=1:8
imgexp=imgexp+(1/8)*img_expect{l};%expectation of E[xx']
end
img_mean=zeros(8,1);
for l=1:8
img_mean=img_mean+(1/8)*img(:,l);
end
img_mean_trans=img_mean*img_mean';
img_covariance=imgexp - img_mean_trans;
[v{m},d{m}]=eig(img_covariance);
temp=v{m};
m=m+1;
for l=1:8
v{m-1}(:,l)=temp(:,8-(l-1));
end
for l=1:8
trans_img1(:,l)=v{m-1}*img(:,l);
end
for x=0:7
for y=0:7
transformed_img(i+x,j+y)=trans_img1(x+1,y+1);
end
end
mask=[1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 ];
trans_img=trans_img1.*mask;
for l=1:8
inv_trans_img(:,l)=v{m-1}'*trans_img(:,l);
end
for x=0:7
for y=0:7
inv_transformed_img(i+x,j+y)=inv_trans_img(x+1,y+1);
end
end
end
end
figure(1)
imshow(transformed_img);
figure(2)
imshow(inv_transformed_img);
end
  댓글 수: 4
Guillaume
Guillaume 2018년 7월 24일
편집: Guillaume 2018년 7월 24일
It's not been uploaded. However, assuming that it's the standard 'cameraman.tif' that comes with matlab, it's not needed since as said, it comes with matlab.
What is needed however, is a description of "the error from this code function". If it does issue an error, then what is the whole text of the error (everything in red). If it does not produce the right result, then what does it produce and what was wanted instead.
Guillaume
Guillaume 2018년 7월 24일
In addition, why does the function takes input I to immediately overwrite that input by an image.

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

답변 (2개)

Guillaume
Guillaume 2018년 7월 24일
If "the error from this code function" is caused by imread, that would be because imread does not accept string inputs, only char array:
I = imread('cameraman.tif'); %use ' instead of "
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 7월 24일
I imagine that restriction will be lifted sooner or later.
Guillaume
Guillaume 2018년 7월 24일
Yes, I'm surprised it's already not supported. Strangely enough, if the second time in a few days that I see somebody on the forum passing a string to imread or imwrite.

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


Walter Roberson
Walter Roberson 2018년 7월 24일
편집: Walter Roberson 2018년 7월 24일
You have
for i=1:8:256
so i is a scalar.
Then you have
img(x+1,y+1)=i(i+x,j+y);
so you are trying to index i as if it were a 2D array.
Your error about duplicate function names is happening because your code
clc;
close all;
clear variables;
clear all;
is converting the .m file from being a function into being a script. Your script file name is KT.m . It is not permitted to have a function named the same thing as the script name when you have a function inside a script.
What you should be doing is removing the four lines I indicated.

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by