【问题标题】:how to generate different color images according to one image in java or python?如何根据java或python中的一张图像生成不同颜色的图像?
【发布时间】:2016-11-27 09:18:08
【问题描述】:

我想根据一个图像生成一些不同颜色的图像。但是我找不到有关此的资源。您能否推荐一些有关如何使用java或python实现的有用参考资料。

例如,下面的图像是从一张图像生成的。

【问题讨论】:

  • 您可以将 opencv 与 python 一起使用(它们也应该存在于 java 中,但我不确定)。使用它们可以操纵色彩空间和值,但我不确定这是否会解决这些图像的不同“花瓣”颜色的情况..

标签: java python image image-processing


【解决方案1】:

在 Python 中,您可以借助 Image 模块来完成这些工作。

例如——

import Image
picture = Image.open("/path/to/my/picture.jpg")
r,g,b = picture.getpixel( (0,0) )
print("Red: {0}, Green: {1}, Blue: {2}".format(r,g,b))

以上代码将为您提供 (0,0) 处像素的信息

import Image
picture = Image.open("/path/to/my/picture.jpg")

# Get the size of the image
width, height = picture.size()

# Process every pixel
for x in width:
    for y in height:
        # get pixel color
        current_color = picture.getpixel( (x,y) )

        # your main logic here to choose new color

        # put the new color on the pixel
        picture.putpixel( (x,y), new_color)

【讨论】:

  • 但是如何使旧图像中相同颜色的空间在新图像中保持相同?
  • @mengying.ye 你需要检查图片中的不同颜色。我只能看到 4 种颜色 - 白色、黑色、第一个花瓣颜色、第二个花瓣颜色。如果它是白色或黑色,不要做任何事情。如果是第一种颜色,请将 newcolor 设置为您想要的颜色,并为图像中的最后一种颜色设置相同的颜色。
猜你喜欢
  • 2019-02-18
  • 2020-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-18
  • 2019-10-19
  • 2020-03-22
  • 2019-05-27
相关资源
最近更新 更多