Numpy Resize/Rescale Image

后端 未结 7 2097
轻奢々
轻奢々 2020-12-02 06:38

I would like to take an image and change the scale of the image, while it is a numpy array.

For example I have this image of a coca-cola bottle: bottle-1

Whi

7条回答
  •  难免孤独
    2020-12-02 07:04

    import cv2
    import numpy as np
    
    image_read = cv2.imread('filename.jpg',0) 
    original_image = np.asarray(image_read)
    width , height = 452,452
    resize_image = np.zeros(shape=(width,height))
    
    for W in range(width):
        for H in range(height):
            new_width = int( W * original_image.shape[0] / width )
            new_height = int( H * original_image.shape[1] / height )
            resize_image[W][H] = original_image[new_width][new_height]
    
    print("Resized image size : " , resize_image.shape)
    
    cv2.imshow(resize_image)
    cv2.waitKey(0)
    

提交回复
热议问题