Python numpy questions Rossy conversion from float64 to uint8

Asked 2 years ago, Updated 2 years ago, 40 views

I'm studying the Python Numpai tutorial (https://cs231n.github.io/python-numpy-tutorial/) and I'm asking because I got an error.

<Before correction>

from scipy.miscimportimread,imsave,imresize

img = imread('cat.jpg')
print(img.dtype, img.shape)  

img_tinted = img * [1, 0.95, 0.9]
img_tinted = imresize(img_tinted, (300, 300))
imsave('cat_tinted.jpg', img_tinted)

The original code is the same as above, but I modified the code as below because I heard that the spike module cannot be used. The picture has been saved, but the following statement appears. How do I solve this problem?

<After modifying>

from imageio import read, write
from skimage.transform import resize 

img = imread ('cat.jpg') #Reads the image in an array
print (img.dtype, img.shape) #data type, size output

img_tinted = img * [1,0.95, 0.9] #ColorChannel is multiplied by a constant value to change color (RGB)

image_tinted = resize(img_tinted, (300, 300)) #colorchangeimage pixel size change

imwrite('cat_tinted.jpg',img_tinted) #Write to complete

python numpy

2022-09-21 10:00

1 Answers

Unlike the error, warning is not stopped because of a problem, but just think of it as "There are some problems, so know it."

The warning you showed is what happens when you try to image the float type value, and it tells you that some information is lost because the values below the decimal point are lost.

In other words, you don't have to worry about it, and if you really want to erase that warning, change the values of img_tinted to int and then write it.


2022-09-21 10:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.