首页 > 编程知识 正文

灰度值与rgb的转换,灰度图转rgb算法

时间:2023-05-03 19:39:10 阅读:9130 作者:3670

通过python将RGB图像转换成灰度图像灰度化公式:使用matplotlib

使用了mxnet来读取图片,也可以用其它的方式读取图片

灰度公式: gray=r * 0.299 g * 0.587 b * 0.114

frommxnetimportimageimportnumpyasnpimportmatplotlib.pyplotaspltfrommxnetimportndimg=image.im read ' autumn _ oak.jpg 0 1 ).astype ) float32 ) ) b=img ) :2 ).astype('float32 ' ) Y=R * 0.299 G * 0.587 B * 0.114 #灰度公式gray=0 ]=y gray [ :1 ]=y gray [ :2 ]=y gray=gray.as type (int ' ).asnumpy ) ) (1) gray ) plt.show (是matplotlibfrommatplotlibimportpyplotaspltimportnumpyasnpath=' autumn _ oak.jpg ' x=PLT.im read plplpath :0 ) 0.299x ) :1 ) 0.587x ) 387 Y.shape[1],3 ) ) gray [ :0 ]=gray [ :

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。