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
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
2018-7-24
In addition, why does the function takes input I to immediately overwrite that input by an image.
回答(2 个)
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 个评论
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
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.
0 个评论
另请参阅
类别
在 Help Center 和 File 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!