如何解决从灰度图像中删除 alpha 通道
我有一些黑白图像,但是是 RGBa。我使用 skimage rgb2gray(inp_image)
将它们转换为灰度。然而,它们变成了带有 alpha 通道的灰度图像。
如果我想将那些 RGBa 转换为没有 alpha 通道的灰度该怎么办?
解决方法
你可以试试这个。
import cv2
image = cv2.imread('path to your image')
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow('Gray image',gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
多张图片
import cv2
from os import listdir,makedirs
from os.path import isfile,join
source = r'path to source folder'
destination = r'path where you want to save'
files = [f for f in listdir(source) if isfile(join(source,f))]
for image in files:
try:
img = cv2.imread(os.path.join(source,image))
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
dstPath = join(destination,image)
cv2.imwrite(destination,gray)
except:
print ("{} is not converted".format(image))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。