0

Here is my existing code which is giving me an error by not returning a 4D input.Here is the code.Is there any way I can change it?

    img = cv2.cvtColor(cv2.imread(os.path.join(root, f_name)), cv2.COLOR_BGR2GRAY)   

    # convert each image of shape (32, 128, 1)
    w, h = img.shape
    if h > 128 or w > 32:
        continue
    if w < 32:
        add_zeros = np.ones((32-w, h))*255
        img = np.concatenate((img, add_zeros))

    if h < 128:
        add_zeros = np.ones((32, 128-h))*255
        img = np.concatenate((img, add_zeros), axis=1)
    img = np.expand_dims(img , axis = 2)

    # Normalize each image
    img = img/255.
  • I want to be able to Make each image of size (128,32) by using padding Expand image dimension as (128,32,1) to make it compatible with the input shape of architecture Normalize the image pixel values by dividing it with 255. – Tanushree Tanya Oct 08 '19 at 18:14
  • Possible duplicate of [Adding borders to an image using python](https://stackoverflow.com/questions/11142851/adding-borders-to-an-image-using-python) – Beginner Oct 08 '19 at 18:59
  • I am getting the error that 'expected input to be of 4 dimensions instead got array of shape (0,1) ' will adding borders to my image solve the problem? – Tanushree Tanya Oct 08 '19 at 20:13

0 Answers0