pygame和numpy演示灰度算法测试示例_gray example

"""
   pygame和numpy演示灰度算法测试示例,本程序会显示一幅彩色图,2秒后它会变成灰度图,演示了用numpy进行灰度图像处理的基本原理.pygame仅是用来显示的,.
"""
import pygame
import numpy as np
from time import sleep


'''仅测试的数据
x = np.array([[[32,76,8],[77,66,99],[12,133,32]],
        [[125,66,32],[81,12,56],[23,53,211]],
        [[5,6,12],[41,112,156],[68,63,35]]])
# 转为图像
image = pygame.surfarray.make_surface(x)
'''

# 加载图像
image = pygame.image.load("兰喂芝.png")
width,height = image.get_size()
x = pygame.surfarray.array3d(image)
print(x.shape)
screen = pygame.display.set_mode((width,height))
screen.blit(image,(0,0))
pygame.display.update()

sleep(2)

You must log in to read the rest of this article. Please log in or register as a user.