[英]Image Processing in python using PIL
I am trying to do some image processing in Python using PIL. 我正在尝试使用PIL在Python中进行一些图像处理。 I need to raise a flag is the picture is has red colour in it.
我需要举一个标志,即图片中有红色。 Can someone please give me some pointers?
有人可以给我一些指示吗?
I figured one can use split function on an image and split it into the individual channels. 我认为可以在图像上使用分割功能,并将其分割为各个通道。 After this, I am not sure what to do.
此后,我不确定该怎么办。
Try something like this. 尝试这样的事情。 It iterates over each pixel and checks if it's the one you want.
它遍历每个像素,并检查它是否是您想要的像素。
from PIL import Image
desired_colour = (255, 0, 0)
im = Image.open("myfile.jpg")
w, h = im.size
pix = im.load()
found = False
for i in range(w):
for j in range(h):
if pix[i, j] == desired_colour:
# Bingo! Found it!
found = True
break
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.