1
import os
import cv2
import numpy as np
from google.colab.patches import cv2_imshow
from PIL import Image

train_path_positive = "/content/Dataset_P5/Train/Positive"

positive_patches = []
for filename in os.listdir(train_path_positive):
  image = cv2.imread(train_path_positive + "/" +filename,0)
  image = cv2.resize(image, (500,500))
  print(image.shape)
  positive_patches.append(image)

positive_patches_array = np.array(positive_patches) 

I have 15 pictures in jpg format

When i try to print the shape, I got (15,) and I was trying to input those picture and store it on array with the format (15, 500,500)

1 Answer 1

1

You need to preallocate a numpy array

# Use your required dtype in below line
positive_patches_array = np.empty((15,500,500), dtype='uint16')


for num, filename in enumerate(os.listdir(train_path_positive)): 
    image = cv2.imread(train_path_positive + "/" +filename,0)
    image = cv2.resize(image, (500,500))   
    positive_patches_array[num, :, :] = image
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.