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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.