Gargob
Gargob

Reputation: 251

Numpy Concatenate Images into Array

I have a bunch of images that I want to store into an array.

The problem is that all my images are different sizes and I don't want to necessarily change their size, because some will be square and some aren't.

I tried using np.concatenate but someone online said it was better to construct a zero matrix and fill it.

However, using

image = misc.imread(filename)

from the scipy library. The image is returned as a 3 dimensional array. How should I construct my numpy ndarray if I want to store all the images in it?

Upvotes: 2

Views: 1563

Answers (2)

SFBA26
SFBA26

Reputation: 890

If I'm understanding the question correctly, you are trying to store a bunch of images of different sizes that are each stored as separate numpy arrays. If your images are gray scale (meaning 2D, as opposed to RGB which are 3D - a channel for R, G and B), you could store the images as the third dimension, filling in the absent pixels with 0s. But the best way would be to just use a python list (or tupple maybe) that stores a list of your numpy array images. That way they can be different sizes. i.e.: img_list = img1, img2, img3, etc.

Upvotes: 1

brettmichaelgreen
brettmichaelgreen

Reputation: 726

storing them in a list may be easier, the list will store them as array() objects and size wont matter, when you do operations on them, just reference the list elements.

Upvotes: 0

Related Questions