【问题标题】:Manipulate images with Python for image quiz (big pixels areas) [duplicate]使用 Python 处理图像以进行图像测验(大像素区域)[重复]
【发布时间】:2020-12-24 13:46:57
【问题描述】:

我想用 Python 处理一些图像来做一个小问答游戏。猜谜者应该猜出图片。

我认为只有大像素区域的图像就可以了。我想要一个类似的结果:https://www.ixxiyourworld.com/media/2387631/ixsp110-van-gogh-petrol-pixel-03.jpg

【问题讨论】:

    标签: python image


    【解决方案1】:

    让我们尝试 PIL 首先将图像大规模缩小到给定的内核大小,然后用 NEAREST 放大到相同的大小 -

    from PIL import Image
    from numpy import asarray
    
    img = Image.open("van_gogh.jpg", mode='r')
    
    factor = 100
    
    kernel = (img.height//factor, img.width//factor)
    pixelated = img.resize(kernel,resample=Image.BICUBIC) #downsample
    pixelated = pixelated.resize(img.size,Image.NEAREST) #upsample
    
    #Grids
    grid_color = [255,255,255]
    
    dx, dy = factor, factor
    g = np.asarray(pixelated).copy()
    
    g[:,::dy,:] = grid_color
    g[::dx,:,:] = grid_color
    
    pixelated2 = Image.fromarray(g)
    pixelated2
    

    在此处增加因子,将进一步像素化图像。

    factor = 100
    

    【讨论】:

      猜你喜欢
      • 2016-04-30
      • 2021-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多