使用keras.preprocessing.image load_img时,图像的背景变黑的背景
我的代码:
from keras.preprocessing.image import load_img, img_to_array
from keras.preprocessing.image import smart_resize
import numpy as np
#load pretrained model
os.chdir('path/to/dir')
# model = load_model(model_path)
input_imagesX = natsorted(os.listdir())
for idx, v in enumerate(input_imagesX):
img = load_img(v,color_mode='rgb')
img = img_to_array(img)
img = tensorflow.image.resize(img, (128,128))
# img = np.expand_dims(img, axis=0)
plt.imshow(img)
plt.grid(None)
plt.show()
在这里,PNG的透明背景变成黑色,填充会变形。尝试了几个骇客,似乎没有任何作用! 有人可以帮忙吗?
my code:
from keras.preprocessing.image import load_img, img_to_array
from keras.preprocessing.image import smart_resize
import numpy as np
#load pretrained model
os.chdir('path/to/dir')
# model = load_model(model_path)
input_imagesX = natsorted(os.listdir())
for idx, v in enumerate(input_imagesX):
img = load_img(v,color_mode='rgb')
img = img_to_array(img)
img = tensorflow.image.resize(img, (128,128))
# img = np.expand_dims(img, axis=0)
plt.imshow(img)
plt.grid(None)
plt.show()
Here, the transparent background of the png turns black and the fill gets distorted. Have tried a couple of hacks, none seems to work!
Can someone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有些图像也可能具有Alpha通道。请在下面找到如何加载alpha通道
输出:
让我们知道问题是否仍然存在。谢谢!
Some images might also have an alpha channel. Please find below how to load the alpha channel
Output:
Let us know if the issue still persists. Thanks!