Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 镜像坐标_Python_Image_Python Imaging Library - Fatal编程技术网

Python 镜像坐标

Python 镜像坐标,python,image,python-imaging-library,Python,Image,Python Imaging Library,我有一个使用PIL创建的图像 import Image import ImageDraw img = Image.new("RGB", (400,400), "white") draw = ImageDraw.Draw(img) coords = [(100,70), (220, 310), (200,200)] dotSize = 2 for (x,y) in coords: draw.rectangle([x,y,x+dotSize-1,y+dotSize-1], fill="

我有一个使用PIL创建的图像

import Image
import ImageDraw

img = Image.new("RGB", (400,400), "white")
draw = ImageDraw.Draw(img)

coords = [(100,70), (220, 310), (200,200)]
dotSize = 2

for (x,y) in coords:
    draw.rectangle([x,y,x+dotSize-1,y+dotSize-1], fill="black")
我知道你想编辑这张图片,在同一张图片上取每个坐标,然后做一个对角线镜像

有什么方法我可以用吗?
我想有这个效果

您可以使用PIL的
转置
旋转
组合
功能来实现所需的结果。这些都在模块中

我稍微改变了初始图像,使结果更清晰。首先,我增加了每个点的大小,使它们更引人注目

下面的代码首先显示覆盖有遮罩的初始图像,该遮罩选择左上至右下对角线下方图像的一半

然后显示原始图像和镜像图像的合成

import Image
import ImageDraw

imsize = 400
img = Image.new("L", (imsize,imsize), "white")
draw = ImageDraw.Draw(img)

coords = [(100,70), (220, 310), (200,200), (80,20)]
dotSize = 50

for (x,y) in coords:
    draw.rectangle([x,y,x+dotSize-1,y+dotSize-1], fill="black")

## mirror image along the diagonal
img2 = img.rotate(90).transpose(Image.FLIP_TOP_BOTTOM)

## mask
mask = Image.new("L", (imsize,imsize), "black")
maskdraw = ImageDraw.Draw(mask)
# draw a triangle on the mask dividing the image along the diagonal
maskdraw.polygon([(0,0),(0,imsize),(imsize,imsize)], fill="white")

# show the mask overlaid on the original image
Image.blend(mask, img, 0.5).show()

# compute and show the blended result
img3 = Image.composite(img, img2, mask)
img3.show()