Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.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_Python 3.x_Image_Image Processing - Fatal编程技术网

在不使用Python中的库的情况下,是否可以使用百分比裁剪任何图像的侧面

在不使用Python中的库的情况下,是否可以使用百分比裁剪任何图像的侧面,python,python-3.x,image,image-processing,Python,Python 3.x,Image,Image Processing,我想做一个函数,在这个函数中,图像的所有侧面都要修剪一个百分比 我想写一个函数,其中的参数如下:我想裁剪侧面的图像;我希望在所有侧面裁剪多少图像(4个不同的百分比)。我试着写了这篇文章,但没有成功: def cropImage2 (image, perL, perR, perB, perO): widthL = image.shape[0] / 2 widthR = image.shape[0] / 2 heightAbove = image.shape[1] / 2 heightBelow =

我想做一个函数,在这个函数中,图像的所有侧面都要修剪一个百分比

我想写一个函数,其中的参数如下:我想裁剪侧面的图像;我希望在所有侧面裁剪多少图像(4个不同的百分比)。我试着写了这篇文章,但没有成功:

def cropImage2 (image, perL, perR, perB, perO):
widthL = image.shape[0] / 2
widthR = image.shape[0] / 2
heightAbove = image.shape[1] / 2
heightBelow = image.shape[1] / 2

linksBr = int(widthL * perL)
rechtsBr = int(widthR * perR)
bovenHg = int(heightAbove * perB)
onderHg = int(heightBelow * perO)

cropX = linksBr + rechtsBr
cropY = bovenHg + onderHg

arrayNieuweImage = np.zeros([cropX, cropY,3])

for i in range(1, cropX):
    for j in range(1, cropY):
        arrayNieuweImage[i, j] = image[i, j]

return arrayNieuweImage
我想要它做什么:例如,如果我写cropImage2(图,0.7,0.8,0.6,0.5),它应该删除30%的左侧,20%的右侧,40%的位于中线上方,50%的位于中线下方

为了让这一切顺利进行,你会做些什么改变?提前谢谢


(我知道使用像openCV或PIL这样的库会更容易,但我不想使用库)

你可以使用Numpy切片,所以
arrayNieuweImage=image[bovenHg:onderHg,linksBr:rechtsBr]
或类似的方法。@MarkSetchell我试过这么做,但我收到一条错误消息:从零大小数组到最小缩减操作,没有标识Yok,请显示原始图像的维度以及boven、onder、links和rechts的值。维度原始图像:(512、512、3)///bovenHg、onderHg的值,linksBr和rechtsBr都因变量perL、perR、perB和peroth的改变而改变。新图像将从上到下10%的距离开始,因此距离顶部51像素,并将结束从上到下80%的距离,因此从顶部向下410像素。新图像将从左开始30%,从左开始153像素,从左到右结束60%,从左边缘开始307像素。