Add padding to images to get them into the same shape

前端 未结 6 1772
野趣味
野趣味 2020-12-31 04:21

l have a set of images of different sizes (45,50,3), (69,34,3), (34,98,3). l want to add padding to these images as follows:

Take the max width and leng

6条回答
  •  一个人的身影
    2020-12-31 04:50

    You can use:

    image = cv2.copyMakeBorder( src, top, bottom, left, right, borderType)
    

    where src is your source image and top, botto, left, right are paddings around the image.

    You can use max(sizes) - size value of the image in a while loop to add the padding to each image. the bordertype can be one of these:

    • cv2.BORDER_CONSTANT
    • cv2.BORDER_REFLECT
    • cv2.BORDER_REFLECT_101
    • cv2.BORDER_DEFAULT
    • cv2.BORDER_REPLICATE
    • cv2.BORDER_WRAP

    copyMakeBorder tutorial

提交回复
热议问题