0

UPDATE

@peter wood comment is actually answer but it is comment so i just upvoted it.

The accepted answer reveals the presence of negative number in the matrix. What I have done is converted both image to grayscale and compared, no more warnings and error. Cheers and Thanks guys.


I am started to learn python and simplecv , using one of the example program in simple which is comparing two images, i am encountering this error. It first throws

runtime warning: overflow encountered in int_scalars

map(lambda a,b: (a-b)**2,h1,h2))/len(h1))

Then throws the error

Traceback (most recent call last):
  File "G:\fs\python27files\imagecompare2.py", line 29, in <module>
    compare('belt.jpg','belt4.jpg')
  File "G:\fs\python27files\imagecompare2.py", line 20, in compare
    map(lambda a,b: (a-b)**2,h1,h2))/len(h1))
ValueError: math domain error

The code is

import math, operator
from SimpleCV import *

def compare(f1,f2):


        img = Image(f1)
        img1 = Image(f2)

        h1 = img.hueHistogram()
        h2 = img1.hueHistogram()
        #print h1
        #print h2
        print len(h1)
        print len(h2)
        f = map(lambda a,b: (a-b)**2,h1,h2)
        print f

        rms = math.sqrt(reduce(operator.add,
                            map(lambda a,b: (a-b)**2,h1,h2))/len(h1))
        #print rms


        #print h1.huePeaks()
        #print h2.huePeaks()


if __name__=='__main__':
   compare('belt.jpg','belt4.jpg')

as you can see i tried to print map alone in variable f, and encounters the same warning.

Finally i saw one related question here in SO which tells that setting up

dType(datatype) will remove the issue , but that is pertaining to numpy, I read

that simplecv is also incorporating numpy. any help regarding this?

EDIT

i have pasted image showing the output of map function of resulting histograms, and i see one negative value in it.

enter image description here

the highlighted portion is showing the negative number. so how to overcome this?

sansknwoledge
  • 4,209
  • 9
  • 38
  • 61

2 Answers2

1

You are computing square root of negative number. You need to check your data and values in intermediate steps.

Minimal example:

Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.sqrt(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
>>>
Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93
  • 1
    It can be fixed using [**`cmath.sqrt`**](https://docs.python.org/2/library/cmath.html#cmath.sqrt). – Peter Wood Nov 27 '15 at 14:08
  • Actually, how can the sum of squares be negative? – Peter Wood Nov 27 '15 at 14:11
  • 1
    @Peter Wood maybe because in some step `runtime warning: overflow encountered in int_scalars` occurs. SimpleCV bindings between C(++) and Python may return some negatives after positive number overflow. Unfortunately, we do not have Complete and Verifiable Example. – Łukasz Rogalski Nov 27 '15 at 14:19
0

Try load the pictures elsewhere. If this does not fail. Attempt testing them with standard simpleCV functions for image class examples or examples. If this too works with your pictures the pictures are no the cause.

This exception means that there is an overflow in map(lambda a,b: (a-b)**2,h1,h2))/len(h1)). That can be you are nonnumbers. h1 or h2 are not linear sequences or of the same length. map in python or map in python.

Check wether a-b can not be squared. For example list in list etc..

Community
  • 1
  • 1
  • Try load the pictures elsewhere - if i am correct are you suggesting that should i try to open the picture with some other applications ? in that case well i am able to open both the pictures in all photo editors like gimp, photoshop , paint.net and ms paint as well. – sansknwoledge Nov 28 '15 at 04:23