MPA
MPA

Reputation: 2038

scipy.misc.imread returns object with no size/shape

I have a question that is similar to this one, though not identical. My goal is to read a TIFF image using scipy.misc.imread and then use the array of grayscale values that is returned by the function. When I do this for one images of dimensions 1280x960 px, I get what I need. However, when I attempt the same for a larger image (6272x897 px), imread returns the following object:

<PIL.TiffImagePlugin.TiffImageFile image mode=LA size=6272x897 at 0x3906B48>

I would like to extract the data out of this object, for instance using .getdata(), but the object itself does not seem to have any shape or size, as was the case in the question I linked above. Ben then proposed the following solution:

pip uninstall PIL
brew install libjpeg
pip install PIL

However, I'm working with a TIFF file, rather than JPEG (libtiff appears to be installed). Also, reading a smaller image works fine, whereas reading a big one suddenly causes problems. Does anyone have any idea of what is going on?

Upvotes: 1

Views: 1122

Answers (1)

Davidmh
Davidmh

Reputation: 3865

Scipy is calling np.array, but when it fails to see __array__, creates an object array instead. You should use raw PIL and read the information from there, there are many questions in SO on how to convert a PIL object into a Numpy array.

The reason why it works with smaller ones may be that the size is so big that it makes PIL be careful about memory, but I am not sure.

An alternative that may work would be to use Pillow (a fork of PIL), or matplotlib

Upvotes: 1

Related Questions