how to correct this error?
이전 댓글 표시
for x=1:rows
for y=1:cols
wt(x,y)=t1(x,y)/max(t1(x,y));
end
end
c=norm(double(wt.*(eimg1(x,y)-eimg(x,y))))/norm(double(wt.*eimg(x,y)));
For the last line,
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
I want this norm value to use as a condition in a loop eimg eimg1 are matrices of an image. wt is the weight function. t1 is the suppression term at the first iteration.
답변 (1개)
Walter Roberson
2017년 1월 10일
You have
wt(x,y)=t1(x,y)/max(t1(x,y));
Your x and y are scalars, so your t1(x,y) is going to be a scalar, and max() of a scalar is the scalar itself. Your wt() calculation is always going to result in 1 for every location. If t1 is floating point then your wt is going to be floating point; if your t1 is integer, your wt would be integer of the same class.
My guess is that you should replace your double loop with the single line
wt = double(t1) ./ double( max(t1) );
This would give you an array of floating point.
If your eimg1 and eimg are your images, they are probably integer class. In that case you would need to replace
c=norm(double(wt.*(eimg1(x,y)-eimg(x,y))))/norm(double(wt.*eimg(x,y)));
with
c = norm(wt .* (double(eimg1) - double(eimg))) / norm(wt .* double(eimg));
Notice here that I did not subscript with x and y: you are outside the loops at this point so x and y are nearly meaningless. Notice also that I used double() before subtracting: when you subtract two items of integer class, the result might not be what you expect.
댓글 수: 7
Divya Praisy
2017년 1월 10일
Image Analyst
2017년 1월 10일
You need ./ not just /
c = norm(wt .* (double(eimg1) - double(eimg))) ./ norm(wt .* double(eimg));
Walter Roberson
2017년 1월 10일
What is size(eimg) and size(wt) ? What size of output are you expecting for c ?
Divya Praisy
2017년 1월 10일
Walter Roberson
2017년 1월 10일
The norm() calls will return scalars so ./ should not be needed. And the error message was about .* not about /
Please show the exact values of
rows
cols
size(t1)
size(wt)
size(eimg1)
size(eimg)
And also please say what size you are expecting "c" to be when it is calculated.
Divya Praisy
2017년 1월 10일
Walter Roberson
2017년 1월 10일
You posted above that you received an error with .* in executing my code. For that particular combination of inputs, I need you to show the values I requested above. If you do not show the exact values associated with an occurrence of the error message, I will not be able to assist you further.
카테고리
도움말 센터 및 File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!