how can I split a large image into small pieces in python

后端 未结 2 1286
别那么骄傲
别那么骄傲 2021-01-29 16:09

I need to create 30 * 30 px small images from splitting a large image. I need these parts separately saved in separate files after being split up like so:

相关标签:
2条回答
  • 2021-01-29 16:41

    Here you go:

    import cv2
    img = cv2.imread('image.png')
    for r in range(0,img.shape[0],30):
        for c in range(0,img.shape[1],30):
            cv2.imwrite(f"img{r}_{c}.png",img[r:r+30, c:c+30,:])
    
    0 讨论(0)
  • 2021-01-29 16:45

    Try use image_slicer. (8 x 8 from your description)

    import image_slicer
    
    image_slicer.slice('C:\\files\\cars.png', 64)
    

    This' how the outputs looked like.

    0 讨论(0)
提交回复
热议问题