how to correct this error?
Show older comments
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.
Answers (1)
Walter Roberson
on 10 Jan 2017
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 Comments
Divya Praisy
on 10 Jan 2017
Image Analyst
on 10 Jan 2017
You need ./ not just /
c = norm(wt .* (double(eimg1) - double(eimg))) ./ norm(wt .* double(eimg));
Walter Roberson
on 10 Jan 2017
What is size(eimg) and size(wt) ? What size of output are you expecting for c ?
Divya Praisy
on 10 Jan 2017
Walter Roberson
on 10 Jan 2017
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
on 10 Jan 2017
Walter Roberson
on 10 Jan 2017
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.
Categories
Find more on Image Filtering and Enhancement in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!