python删除图片 某种颜色_检测颜色并从图像中删除该颜色

这是一种使用像素阵列的方法。像素阵列很慢,但是如果速度不是问题,它们可以满足您的需要,而不必下载任何外部库。此外,像素阵列也很容易理解。在import pygame

# You would load your image as a sprite here.

# But let's create a demonstration sprite instead.

#

usecolor = (46,12,187,255) # Declare an example color.

sprite = pygame.Surface((10,10)) # Greate a surface. Let us call it a 'sprite'.

sprite.fill(usecolor) # Fill the 'sprite' with our chosen color.

#

# Now process the image.

array = pygame.PixelArray(sprite) # Create a pixel array of the sprite, locking the sprite.

sample = array[5,5] # Sample the integer holding the color values of pixel [5,5]

# We will feed this integer to pygame.Color()

sample_1 = sprite.get_at((5,5)) # Alternately, we can use the .get_at() method.

# Do the same for every pixel, creating a list (an array) of color values.

del array # Then delete the pixel array, unlocking the sprite.

m,r,g,b = pygame.Color(sample) # Note: m is for the alpha value (not used by .Color())

print("\n sample =",sample,"decoded by python.Color() to:")

print(" r >>",r)

print(" g >>",g)

print(" b >>",b)

print("\n or we could use .get_at()")

print(" sample_1 =",sample_1)

print()

exit()

只需测试每个r,g,b值,看看它们是否落在每个颜色分量所需的范围内。然后将每个像素复制到一个新的曲面上,用所需的替换颜色替换范围内的所有颜色。在

或者,在将像素放入新图像之前,可以对每个R、G、B颜色分量(如果color>255:color=255)添加75。这会使所有的颜色逐渐变白,直到浅色消失。然后你可以重复这个过程,从每个剩余的像素减去75(分量值小于255),使颜色再次上移。我怀疑任何一个像样的验证码都是那么容易被击败的,但你去吧。在

好玩好玩!在

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值