1

I am reading all images of a folder from following code

from skimage.io import imread_collection
img_dir = 'cats/*.jpg'
col = imread_collection(img_dir)

for getting shape or size of col i used following:

col.shape

but get AttributeError: 'ImageCollection' object has no attribute 'shape'

how to solve this problem

Hitesh
  • 1,285
  • 6
  • 20
  • 36

3 Answers3

2

ImageCollection is a list of images, so you have to access individual images with their index.

From the docs:

>>> coll = io.ImageCollection(data_dir + '/chess*.png')
>>> len(coll)
2
>>> coll[0].shape
(200, 200)
Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
1

try len instead of shape. try col[0].shape , directory list can't have shape, image do. so iterate in list and get all shapes of many images.

Jainil Patel
  • 1,284
  • 7
  • 16
1

As the accepted answer above, you could use len(col) to determine the length of the collection, i.e. how many images are there in the collection.

But I think the question title is a bit misleading, one might think what you are trying to achieve is to get the size (i.e. in Bytes) of an object, in this case, you could use sys.getsizeof(col) and this will return the size of this object, in Bytes, see this answer

P.S. this answer should be posted as a comment, but I couldn't do so not having enough rep, apologies to the SO community.


Edit: If you are interested in getting the size in Bytes of an object, please go through the other answers posted under this question, as the sys.getsizeof() isn't always accurate.

UdonN00dle
  • 723
  • 6
  • 28