Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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 Processing_Computer Vision_Python Imaging Library_Crop - Fatal编程技术网

裁剪图像时出现Python错误:平铺无法扩展图像外部

裁剪图像时出现Python错误:平铺无法扩展图像外部,python,image-processing,computer-vision,python-imaging-library,crop,Python,Image Processing,Computer Vision,Python Imaging Library,Crop,我有一个大小为2048x1536的JPG图像文件夹。在每个图像中,日期、时间、温度在顶部给出,相机型号名称在末尾给出。我只想裁剪这些图像的上部和下部 图像样本: 使用下面的代码,我得到一个错误-对于我提供的任何尺寸,瓷砖都不能延伸到外部图像**例如(500500)**。我的目标it(1500200015002000) 从PIL导入图像 导入操作系统 #Create an Image Object from an Image dir=r"C:\\Users\\Desktop\\crop1

我有一个大小为2048x1536的JPG图像文件夹。在每个图像中,日期、时间、温度在顶部给出,相机型号名称在末尾给出。我只想裁剪这些图像的上部下部

图像样本:

使用下面的代码,我得到一个错误-对于我提供的任何尺寸,瓷砖都不能延伸到外部图像**例如(500500)**。我的目标it(1500200015002000)

从PIL导入图像 导入操作系统

#Create an Image Object from an Image
dir=r"C:\\Users\\Desktop\\crop1"
output_dir = r"C:\\Users\\Desktop\\crop2"
file_names = os.listdir(dir)

for file_name in file_names:
    file_path = dir +"\{}".format(file_name)
    im = Image.open(r"{}".format(file_path))
    cropped = im.crop((2000,1500,2000,1500))
    output_file= output_dir+"\{}".format(file_name)
    cropped.save(r"{}".format(output_file))
“(2000150020001500)”是一个空框,这可以解释为什么即使“瓷砖无法延伸到外部图像”错误不完全合适,裁剪也会失败。crop的4元组参数的含义是“(左、上、右、下)”。示例来自:


似乎无法指定比图像大的裁剪区域。您还应该使用
os.path
来操作路径,而不是手动操作(更容易出错)。谢谢。在了解了这四个元组是如何工作的之后,我解决了这个问题。我通过做一些研究来理解。非常感谢您的链接。现在问题解决了。图像大小为-2048x1536。我只想裁剪上部和下部。我提供了参数(0,3020481450)以获得所需的输出。
from PIL import Image

im = Image.open("hopper.jpg")

# The crop method from the Image module takes four coordinates as input.
# The right can also be represented as (left+width)
# and lower can be represented as (upper+height).
(left, upper, right, lower) = (20, 20, 100, 100)

# Here the image "im" is cropped and assigned to new variable im_crop
im_crop = im.crop((left, upper, right, lower))