当前位置: 动力学知识库 > 问答 > 编程问答 >

Octave division returning zero

问题描述:

I'm writing a simple octave program that calculate similarity between two images.

The relevant part for this question can be found here:

http://pastebin.com/gBxN7VbP

The function struct_comp was supposed to return some number between zero and one. But the command

ec = (corr + C) / (dp1 * dp2 + C);

is setting ec as 0 even when it should not be zero.

The disp commands are showing the values of all variables involved in this division. The output is:

C:

6.5536

dp1

97.663

dp2

47.686

corr

-290

(corr + C)

-283

(dp1 * dp2 + C)

4663.7

(corr + C) / (dp1 * dp2 + C)

0

Struct comp:

0

As you can see, the partial values (numerator and denominator) are right, but the division is returning zero.

Somebody knows what is happening here?

Thank you.

EDIT:

The two images used to generate this output were these:

http://lasca.ic.unicamp.br/~hilder/tux.jpg

http://lasca.ic.unicamp.br/~hilder/monalisa.jpg

But you can use any grayscale image to test, just change the name in the code.

网友答案:

i replaced the line

ec = (corr + C) / (dp1 * dp2 + C);

by

ec = double(corr + C) / double(dp1 * dp2 + C);

and it worked.

分享给朋友:
您可能感兴趣的文章:
随机阅读: