简体   繁体   中英

Resize images and merge data sets in python

I have two datasets, images1 and images2(generated in the function below, by reading images in a loop via given path)

def measure(images1,path):
      images2=[]
      for filename in glob.glob(path): #looking for pngs
          temp = cv2.imread(filename).astype(float)
          images2.append (augm_img)

          print(np.array(images2).dtype)
          print(np.array(images).dtype)

          print(np.array(images2).shape)
          print(np.array(images).shape)

Prints outputs:

  float64
  float64

    (1, 24, 24, 3)
(60000, 32, 32, 3)
(2, 24, 24, 3)
(60000, 32, 32, 3)
(3, 24, 24, 3)
(60000, 32, 32, 3)
(4, 24, 24, 3)
(60000, 32, 32, 3)
       ....
       ....

etc

After reading images from path i want to resize images2 read from file to same size as images (:,32,32,3)

And merge these two datasets in one (via concatenate or append?) in order to train my model.

Until now i cant find a way to do this so any advice would be helpful.

I found the solution:

def resize_images(image_arrays, size=[32, 32]):
# convert float type to integer
image_arrays = (image_arrays * 255).astype('uint8')

resized_image_arrays = np.zeros([image_arrays.shape[0]] + size + [3])
for i, image_array in enumerate(image_arrays):
    image = Image.fromarray(image_array)
    resized_image = image.resize(size=size, resample=Image.ANTIALIAS)


    resized_image_arrays[i] = resized_image


return resized_image_arrays

By calling this function images are resized in specific size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM