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.

Upvotes: 2

Views: 706

Answers (1)

user3794796
user3794796

Reputation: 26

i replaced the line

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

by

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

and it worked.

Upvotes: 1

Related Questions