问题描述
我有一些交通摄像头图像,我只想提取道路上的像素.在有人可以指定类似操作之前,我曾使用过遥感软件
I have some traffic camera images, and I want to extract only the pixels on the road. I have used remote sensing software before where one could specify an operation like
img1 * img2 = img3
img1 * img2 = img3
其中img1是原始图像,img2是纯正的黑白蒙版.本质上,图像的白色部分将评估为
where img1 is the original image and img2 is a straight black-and-white mask. Essentially, the white parts of the image would evaluate to
img1 * 1 = img3
img1 * 1 = img3
,黑色部分的计算结果为
and the black parts would evaluate to
img1 * 0 = img3
img1 * 0 = img3
因此,人们可以拍摄图像的一部分,然后将所有不重要的区域都变黑.
And so one could take a slice of the image and let all of the non-important areas go to black.
有没有一种方法可以使用PIL?我找不到像我以前所见的类似于图像代数的东西.我已经尝试过混合功能,但这只是将它们淡入淡出.我已经阅读了一些有关numpy的内容,似乎可以胜任,但是我想确定一点,在我深入之前,在PIL中没有简单的方法可以做到这一点.
Is there a way to do this using PIL? I can't find anything similar to image algebra like I'm used to seeing. I have experimented with the blend function but that just fades them together. I've read up a bit on numpy and it seems like it might be capable of it but I'd like to know for sure that there is no straightforward way of doing it in PIL before I go diving in.
谢谢.
推荐答案
Image.composite
方法可以执行您想要的操作.第一幅图像应为代表遮罩区域的恒定值,第二幅图像应为原始图像-第三幅图像为遮罩.
The Image.composite
method can do what you want. The first image should be a constant value representing the masked-off areas, and the second should be the original image - the third is the mask.
这篇关于是否可以在Python Imaging Library(PIL)中屏蔽图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!