Problem with the following.
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
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 Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!