soft-matter / pims

Python Image Sequence: Load video and sequential images in many formats with a simple, consistent interface.
http://soft-matter.github.io/pims/
Other
258 stars 67 forks source link

Read color tiff stacks #87

Open nkeim opened 9 years ago

nkeim commented 9 years ago

I get an error when trying to open a color TiffStack.

To duplicate: open a few color PNGs in ImageJ as a stack, from the sample_data/bulk_water directory in the trackpy-examples repo. Save as a single TIFF file.

In Python:

>>> ts = pims.TiffStack('seq.tif')
>>> ts[0]
ValueError                                Traceback (most recent call last)
<ipython-input-5-5810989840f7> in <module>()
----> 1 ts[0]

/Users/nkeim/trackpy-tryout/src/pims/pims/base_frames.pyc in __getitem__(self, key)
    153 
    154             # else, fall back to `get_frame`
--> 155             return self.get_frame(key if key >= 0 else _len + key)
    156 
    157     def __iter__(self):

/Users/nkeim/trackpy-tryout/src/pims/pims/tiff_stack.pyc in get_frame(self, j)
    334         self.cur = self.im.tell()
    335         res = np.reshape(self.im.getdata(),
--> 336                          self._im_sz).astype(self._dtype).T[::-1]
    337         return Frame(self.process_func(res), frame_no=j)
    338 

/Users/nkeim/anaconda/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in reshape(a, newshape, order)
    215         reshape = a.reshape
    216     except AttributeError:
--> 217         return _wrapit(a, 'reshape', newshape, order=order)
    218     return reshape(newshape, order=order)
    219 

/Users/nkeim/anaconda/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in _wrapit(obj, method, *args, **kwds)
     41     except AttributeError:
     42         wrap = None
---> 43     result = getattr(asarray(obj), method)(*args, **kwds)
     44     if wrap:
     45         if not isinstance(result, mu.ndarray):

ValueError: total size of new array must be unchanged
danielballan commented 9 years ago

As a workaround, try all the different tiff classes in turn and see if one works. They each have their advantages and none of them can read every flavor of tiff. Defining the correct precedence is hard. I need to resolve this for my own purposes as well, so I can take a more detailed look soon.

On Thursday, September 4, 2014, Nathan Keim notifications@github.com wrote:

I get an error when trying to open a color TiffStack.

To duplicate: open a few color PNGs in ImageJ as a stack, from the sample_data/bulk_water directory in the trackpy-examples repo. Save as a single TIFF file.

In Python:

ts = pims.TiffStack('seq.tif') ts[0] ValueError Traceback (most recent call last)

in () ----> 1 ts[0]

/Users/nkeim/trackpy-tryout/src/pims/pims/base_frames.pyc in getitem(self, key) 153 154 # else, fall back to get_frame --> 155 return self.get_frame(key if key >= 0 else _len + key) 156 157 def iter(self):

/Users/nkeim/trackpy-tryout/src/pims/pims/tiff_stack.pyc in get_frame(self, j) 334 self.cur = self.im.tell() 335 res = np.reshape(self.im.getdata(), --> 336 self._im_sz).astype(self._dtype).T[::-1] 337 return Frame(self.process_func(res), frame_no=j) 338

/Users/nkeim/anaconda/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in reshape(a, newshape, order) 215 reshape = a.reshape 216 except AttributeError: --> 217 return _wrapit(a, 'reshape', newshape, order=order) 218 return reshape(newshape, order=order) 219

/Users/nkeim/anaconda/lib/python2.7/site-packages/numpy/core/fromnumeric.pyc in _wrapit(obj, method, _args, _kwds) 41 except AttributeError: 42 wrap = None ---> 43 result = getattr(asarray(obj), method)(_args, _kwds) 44 if wrap: 45 if not isinstance(result, mu.ndarray):

ValueError: total size of new array must be unchanged

— Reply to this email directly or view it on GitHub https://github.com/soft-matter/pims/issues/87.