在python中,我尝试将一个图像分割成多个圆,并计算每个圆中黑色像素的数量。在
例如,我有一个用鱼眼镜头拍摄的图像(半球形的图像)(下面画的例子),我想把图像分成小圆,捕捉图像的一部分,从中间的一个小圆到整个图像。
一旦我有了圆形图像,我就可以计算出每个图像中的像素数。在
我试过了:
Image=Image.new("RGB", (2000,2000))
draw = ImageDraw.Draw(image)
draw.ellipse((20,20,1800,1800),fill(255,255,255)
然后从中创建了一个掩码,不管我如何更改绘图.椭圆圆圈只会捕捉到整个图像,但会使图像本身变小。在
任何关于如何解决这个问题的想法或建议都将不胜感激!在
如果您对库足够熟悉,那么在纯numpy中这是最简单的方法:
要查看各种阵列的外观:
^{pr2}$对于这些任务,您应该查看OpenCV。您可以将圆转换为整个轮廓并计算圆的半径。然后你可以画圆,在蒙版上画出它们,然后执行
cv2.bitwise_and
在图像上画出圆形感兴趣区域。你可以用你选择的一个整数(在我的例子中是10)来迭代和多个ROI圆的半径。希望有帮助。干杯!在示例代码:
结果:
编辑:
尝试用不同的方法计算中间值
^{pr2}$编辑2:
好吧,我从你的第一个例子中假设你的形象从一开始就几乎是一个圆。因为它不是你必须计算不同的中心(从我的第一个编辑-从边界框)和做一个更大的内核(40,40)-因为事实上,图像非常大。再加上你必须使我在范围内的阈值(如10000)。这将起作用:
相关问题 更多 >
编程相关推荐