gpt4 book ai didi

python-3.x - python : how to display an image pixel by pixel using random coordinates

转载 作者:行者123 更新时间:2023-12-04 15:36:54 26 4
gpt4 key购买 nike

1.将image.jpg加载到数组中2.从数组中随机选择坐标并显示该像素及其所有属性3. 从数组中使用弹出坐标。4. 重复#2 直到数组为空

这将显示一个填充了随机像素的图像。

最终结果始终是原始图像,但每次都会以不同的方式填充。

这在 Python3 中如何完成?

最佳答案

这是一种方法...

#!/usr/bin/env python3

import numpy as np
import cv2

# Open the image and make black version, same size, to fill randomly
im = cv2.imread('paddington.png')
fade = np.zeros_like(im)

# Generate a randomly shuffled array of the coordinates
X,Y = np.where(im[...,0]>=0)
coords = np.column_stack((X,Y))
np.random.shuffle(coords)

for n, c in enumerate(list(coords)):
# Copy one original pixel across to image we are fading in
x, y = c
fade[x,y] = im[x,y]
# It takes 1ms to update the image, so we don't update after every pixel
if n % 500 == 0:
cv2.imshow('Fading in...', fade)
cv2.waitKey(1)

# Image should now be completely faded in
cv2.imshow('Fading in...', fade)
cv2.waitKey()

enter image description here

关键词:Python、OpenCV、fade、fade in、fade from black、fade from white、图像处理、视频。

关于python-3.x - python : how to display an image pixel by pixel using random coordinates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59432924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com