使用 Python 的 Pillow 库提取图像中像素值为 (0, 0, 0) 的黑色像素坐标。\n\npython\nfrom PIL import Image\n\ndef extract_black_pixels(image_path):\n image = Image.open(image_path)\n pixels = image.load()\n width, height = image.size\n\n black_pixels = []\n\n for y in range(height):\n for x in range(width):\n r, g, b = pixels[x, y]\n if r == 0 and g == 0 and b == 0:\n black_pixels.append((x, y))\n\n return black_pixels\n\nimage_path = "example_image.jpg"\nblack_pixels = extract_black_pixels(image_path)\nprint(black_pixels)\n\n\n请确保在运行此程序之前已安装 Pillow 库(可以使用 pip install pillow 进行安装)并将 example_image.jpg 替换为您要处理的图像文件的路径。程序将输出一个列表,其中包含像素值为 (0, 0, 0) 的所有像素的坐标。

Python 图像处理:提取黑色像素坐标

原文地址: https://www.cveoy.top/t/topic/qiBs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录