2

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.

  • Without tux.jpg and monalisa.jpg your code does not work here. A smaller code displaying the same problem would be better... Some hints: insert `keyboard` at the end of your "struct_comp" function. This is very handy for debugging purpose. And avoid `global`. – ederag Mar 18 '15 at 18:14
  • I edited the question and added the two images I used. I didn't know this `keyboard` function. I'll search for more information about it. – Hilder Vitor Lima Pereira Mar 18 '15 at 18:26

1 Answers1

1

i replaced the line

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

by

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

and it worked.