通过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 [ :