フィルターのクリア

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

3 ビュー (過去 30 日間)
shivu P
shivu P 2018 年 7 月 24 日
コメント済み: Guillaume 2018 年 7 月 24 日
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 Center および File ExchangeWorkspace 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