我正在编写一段代码,其中一部分是读取图像源并将其显示在屏幕上以供用户交互。我还需要锐化的图像数据。我使用以下方法读取数据并将其显示在pyGame
def image_and_sharpen_array(file_name):
#read the image data and return it, with the sharpened image
image = misc.imread(file_name)
blurred = ndimage.gaussian_filter(image,3)
edge = ndimage.gaussian_filter(blurred,1)
alpha = 20
out = blurred + alpha*(blurred - edge)
return image,out
#get image data
scan,sharpen = image_and_sharpen_array('foo.jpg')
w,h,c = scan.shape
#setting up pygame
pygame.init()
screen = pygame.display.set_mode((w,h))
pygame.surfarray.blit_array(screen,scan)
pygame.display.update()
并且图像在屏幕上显示只是旋转和反转。这是由于之间的差异misc.imread
and pyGame
?或者这是由于我的代码有问题吗?
还有其他方法可以做到这一点吗?我读到的大多数解决方案都涉及保存图形,然后使用“pyGame”读取它。
我经常使用numpyswapaxes()
方法:
在这种情况下,我们只需要在显示数组之前反转 x 和 y 轴(轴号 0 和 1):
return image.swapaxes(0,1),out
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)