我创建了一个简单的程序来生成随机图像,为每个像素提供随机颜色。我知道生成可协调图像的机会非常低,但我想尝试一下。
我观察到工作中最长的部分是检查图像是否真的是东西。我还观察到,生成的大多数图像只是具有大量单个像素的彩色图像域。这就是为什么我想要求一种伪代码算法来检测图像中相似的颜色区域。我认为找到有意义的图像的最简单方法是过滤所有这些随机像素图像。这并不完美,但我认为它会有所帮助。如果有人可以提出另一种有助于完成这项任务的过滤算法,我也会很感激。
(已编辑)
为了澄清这一点,如果我的解释不够清楚,我将向您展示一些图像:
这就是我得到的图像,基本上我会将其描述为“彩色噪声”。正如你所看到的,所有像素都是单独分布的,没有在相似的颜色区域中分组,以跳跃地创建对象的形状或任何可协调的东西。
在这里你可以看到一个传统的图像,一个“reconocible”图片。我们可以清楚地看到一只狗躺在草地上,手里拿着一个网球。如果你仔细观察这张图片,它可以很明显地与另一张区别开来,因为它有相似的颜色,我们可以区分(如狗,白色区域,草,深绿色区域,网球球,光绿色区域)。
我真正想要的是在将它们保存在高清之前删除“像素”图像,并且只保存具有颜色 agrupations 的图像。正如我之前所说,这个想法是我必须过滤这些随机生成的图像的最佳方法,但如果有人提出另一种更有效的方法,我会非常感激它。
(已编辑)
好的,我认为这篇文章变得太长了......好吧,如果有人想看看这里是我编写的程序的代码。这真的很简单。我已经使用 Pygame 在 Python 中对其进行了编程。我知道这几乎不是最有效的方法,我知道这一点。问题是我在这个领域是个菜鸟,我真的不知道用其他语言或模块来做这件事的另一种方法。也许您也可以帮助我...我不知道,也许将代码翻译成C++?我觉得我在同一篇文章中提出了很多问题,但是正如我多次说过的那样,任何帮助都会非常感激。
import pygame, random
pygame.init()
#lots of printed text statements here
imageX = int(input("Enter the widht of the image you want to produce: "))
imageY = int(input("Enter the height of the image you want to produce: "))
maxImages = int(input("Enter the maximun image amoungt you want to produce: "))
maxMem = int(input("Enter the maximun data you want to produce (MB, only works with 800x600 images): "))
maxPPS = int(input("Enter the maximun image amoungt you want to produce each second: "))
firstSeed = int(input("Enter the first seed you want to use: "))
print("\n\n\n\n")
seed = firstSeed
clock = pygame.time.Clock()
images = 0
keepGoing = True
while keepGoing:
#seed
random.seed(seed)
#PPS
clock.tick(maxPPS)
#surface
image = pygame.Surface((imageX,imageY))
#generation
for x in range(imageX):
for y in range(imageY):
red = random.randint(0,255)
green = random.randint(0,255)
blue = random.randint(0,255)
image.set_at((x,y),(red,green,blue))
#save
pygame.image.save(image,str(seed)+".png")
#update parameters
seed += 1
images += 1
#print seed
print(seed - 1)
#check end
if images >= maxImages:
keepGoing = False
elif (images * 1.37) >= maxMem:
keepGoing = False
pygame.event.pump()
print("\n\nThis is the last seed that was used: " + str(seed - 1))
input("\nPress Enter to exit")