Problem with the following.

10 ビュー (過去 30 日間)
Sabarinathan Vadivelu
Sabarinathan Vadivelu 2012 年 9 月 3 日
This is my MATLAB code for the following:
F(m, n) = w0I0 + w1I1 + w2I2
where
I0 = I2^α0 (m, n)
I1 = I2^α1 (m 1, n) + I2^α1 (m + 1, n) + I2^α1 (m, n 1) + I2^α1 (m, n + 1)
I2 = I2^α2 (m 1, n 1) + I2^α2 (m + 1, n 1) + I2^α2 (m + 1, n 1) + I2^α2 (m + 1, n + 1)
The value of alpha0,alpha1,alpha2,w0,w1,w2 are declared in code. But it shows some error. I dono why?
code:
[file path] = uigetfile ('*.bmp','Select any Image');
if file ~=0
I = imread (strcat(path,file));
[m n] = size (I);
h=1;
alpha0 = 8*h;
alpha1 = h;
alpha2 = h;
w0 = 2;
w1 = -0.125;
w2 = -0.125;
% Compute I0
for j = 1 : n
for i = 1 : m
I0(i,j) = I(i,j)^(2*alpha0);
end
end
% Compute I1
for j = 1 : n
for i = 1 : m
I1(i,j) = I(i-1,j)^(2*alpha1) + I(i+1,j)^(2*alpha1) + I(i,j-1)^(2*alpha1) + I(i,j+1)^(2*alpha1);
end
end
% Compute I2
for j = 1 : n
for i = 1 : m
I2(i,j) = I(i-1,j-1)^(2*alpha2) + I(i+1,j-1)^(2*alpha2) + I(i+1,j-1)^(2*alpha2) + I(i+1,j+1)^(2*alpha2);
end
end
F(m,n) = (w0*I0(m,n)) + (w1*I1(m,n)) + (w2*I2(m,n));
figure, imshow(F);
end
  2 件のコメント
Oleg Komarov
Oleg Komarov 2012 年 9 月 3 日
What error do you get?
Sabarinathan Vadivelu
Sabarinathan Vadivelu 2012 年 9 月 5 日
Index out of bounds

サインインしてコメントする。

採用された回答

Jan
Jan 2012 年 9 月 3 日
編集済み: Jan 2012 年 9 月 3 日
Always provide the complete error message to the forum, when you get one.
I guess at least this fails:
for i = 1 : m
I1(i,j) = I(i-1,j)^(2*alpha1) + I(i+1,j)^(2*alpha1) ...
This fails for i==1 and i==m, because i-1 and i+1 are no valid indices, respectively. You have to run the loop from 2:m-1, such that I1 has a different size.
Btw.:
  • Overwriting the important function path with a local variable is a bad idea. E.g. the debugging might fail.
  • This code:
% Compute I0
for j = 1 : n
for i = 1 : m
I0(i,j) = I(i,j)^(2*alpha0);
end
end
can be abbreviated to:
I0 = I .^ (2 * alpha0);
  • The comparison of strings should not be done by == or ~=, although this works accidently in your example: "if file ~=0". Better use if ischar(file) or if ~isequal(file, 0).
  2 件のコメント
Sabarinathan Vadivelu
Sabarinathan Vadivelu 2012 年 9 月 5 日
But there is a problem that the size of I1, I2 is decreased to 1023*1023. How to rectify this problem?
Jan
Jan 2012 年 9 月 5 日
Yes, the procedure you have shown should decrease the size by two rows and columns. There is no standard solution to "rectify" this, because this is no error. If you want to get the same size as the inputs, a definition of the margins is required. E.g. use the same values as the inputs, or repeat the values of the outputs (and a special trick at the corners).

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by