Solved – runtimeWarning: overflow encountered in ubyte_scalars warning

In this article, you will learn how to solve runtimeWarning: overflow encountered in ubyte_scalars warning. Consider the code example below which throws the same warning: the correct…

The post Solved – runtimeWarning: overflow encountered in ubyte_scalars warning appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven

In this article, you will learn how to solve runtimeWarning: overflow encountered in ubyte_scalars warning.

Consider the code example below which throws the same warning:

from PIL import Image
 import numpy as np
image1 = np.array(Image.open( "hello1.jpg" ))                   
image2 = np.array(Image.open( "hello2.jpg" ))                  
 temp = image1[ 1 , 1 ]-image2[ 1 , 1 ]    

the correct way of writing the above code is below:

from PIL import Image
import numpy as np
image1 = np.array(Image.open( "hello1.jpg" ))                   
image2 = np.array(Image.open( "hello2.jpg" ))                  
temp = int (image1[ 1 , 1 ])- int (image2[ 1 , 1 ])

Note: When processing an image with python, it can involve addition and subtraction between the pixel values ​​of two images. It’s also worth noting that the pixel value of the image is of the ubyte type, and the data range of the ubyte type is 0~255

You can also completely remove this warning, which isn’t the best idea to do.

to completely remove the runtimeWarning you can just add the following after importing numpy:

import numpy as np
np.seterr(over='ignore')


The post Solved – runtimeWarning: overflow encountered in ubyte_scalars warning appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2021-03-07T14:43:19+00:00) Solved – runtimeWarning: overflow encountered in ubyte_scalars warning. Retrieved from https://www.scien.cx/2021/03/07/solved-runtimewarning-overflow-encountered-in-ubyte_scalars-warning/

MLA
" » Solved – runtimeWarning: overflow encountered in ubyte_scalars warning." Deven | Sciencx - Sunday March 7, 2021, https://www.scien.cx/2021/03/07/solved-runtimewarning-overflow-encountered-in-ubyte_scalars-warning/
HARVARD
Deven | Sciencx Sunday March 7, 2021 » Solved – runtimeWarning: overflow encountered in ubyte_scalars warning., viewed ,<https://www.scien.cx/2021/03/07/solved-runtimewarning-overflow-encountered-in-ubyte_scalars-warning/>
VANCOUVER
Deven | Sciencx - » Solved – runtimeWarning: overflow encountered in ubyte_scalars warning. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/07/solved-runtimewarning-overflow-encountered-in-ubyte_scalars-warning/
CHICAGO
" » Solved – runtimeWarning: overflow encountered in ubyte_scalars warning." Deven | Sciencx - Accessed . https://www.scien.cx/2021/03/07/solved-runtimewarning-overflow-encountered-in-ubyte_scalars-warning/
IEEE
" » Solved – runtimeWarning: overflow encountered in ubyte_scalars warning." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/03/07/solved-runtimewarning-overflow-encountered-in-ubyte_scalars-warning/. [Accessed: ]
rf:citation
» Solved – runtimeWarning: overflow encountered in ubyte_scalars warning | Deven | Sciencx | https://www.scien.cx/2021/03/07/solved-runtimewarning-overflow-encountered-in-ubyte_scalars-warning/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.