2

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

6 Comments

I was thinking about that. However, I am using Theano library, and I think they require numpy arrays..
which axis would you add it to if it were concatenated? as a new row, column, 3-d Dimension?
unless you need to do an operation on the entire array the elements themselves will still be numpy arrays in a list btw
Should I make the image into a 1d array?
I'm new to numpy so this is that I was thinking. I would have a numpy array where the 1st element is the 3d array representation of the first image. The 2nd element is the 3d array representation of the second image and so on. Thus, I guess concatenating them is wrong. I want to insert them into a numpy array where element is an arbitrary sized matrix.
|

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.