Resize images and merge data sets in python


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)


(:,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.




1 Answer
1



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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Boo (programming language)

How to make file upload 'Required' in Contact Form 7?