RuntimeWarning: overflow encountered in ubyte_scalars RuntimeWarning: overflow encountered in ubyte_scalars python python

RuntimeWarning: overflow encountered in ubyte_scalars


You are adding two uint8 values together resulting in an uint8 value. You need to transform your data types in the calculation. I suggest you try this:

pixeldiff = (int(ipxeldiff)+int(currentdiff))/2

This should work.

Edit: balanced bracketts


I had a similar problem that I resolved by initializing my numpy arrays as an int64 datatype:

imAnchor = array(Image.open(imList[10]), dtype='int64')


I think your problem stems from this line:

pixeldiff=pixeldiff+currentdiff

Remember that pixels are normally saved in uint8 datatype, which is 0 to 255. So if you try to add two of them and it goes over 255, it will fail.

Do something like this:

pixeldiff = (pixeldiff+currentdiff)/2

You will still get the relational data, but it will be compressed into the right size of 0-255.