Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motion corrected tiff-files only have one frame #647

Closed
swkeemink opened this issue Mar 31, 2021 · 3 comments
Closed

Motion corrected tiff-files only have one frame #647

swkeemink opened this issue Mar 31, 2021 · 3 comments

Comments

@swkeemink
Copy link

Issue: When setting 'reg_tif': True, the extracted tiff-files seem to only have one frame, at least when imported with the tifffile package.

To reproduce: Run the example analysis on some existing tifffiles, and set 'reg_tif': True in the options.
Then, load a registered tiff file as follows:

tiffname = 'suite2pfolder/plane0/reg_tif/file000_chan0.tif'
tiff_data = tifffile.imread(tiffname)
tiff_data.shape

Which returns
(176, 156)
indicating only a single frame instead of a stack of frames.

This was reproduced with both our own example tiffs, and yours.

Package version:
tifffile==2021.3.17
suite2p==0.10.0

Expected behavior

tiffname = 'suite2pfolder/plane0/reg_tif/file000_chan0.tif'
tiff_data = tifffile.imread(tiffname)
tiff_data.shape

Which should return
(num_frames, 176, 156)

It is very possible I am reading the tifffile in the wrong way of course. However, when I read the original tiffiles using the above methods, it correctly creates a 3-D array.
In our own neuripil separation package this leads to problems in our current Suite2P implementation: rochefort-lab/fissa#148
One of our users also posted a solution there to work directly with the binary data file. We are reworking our example to work directly with the binary data file instead also, but still thought I'd point this out. For future use, using the tifffile would probably also be more resistant to API changes.

@carsen-stringer
Copy link
Member

is this a function of tiff size / formatting? how to read tiffs with tifffile (from documentation https://pypi.org/project/tifffile/):

with TiffFile('temp.tif') as tif:
     for page in tif.pages:
         image = page.asarray()

how we write tiffs:

def save_tiff(mov: np.ndarray, fname: str) -> None:

happy to accept pull requests on tiff writing if you think there's a better format

@swkeemink
Copy link
Author

Thank you for the simple solution, that seems to work!

It's strange because the tifffile.imread method worked fine when I originally wrote the code to use the suite2p extracted tifffiles.

@wiessall
Copy link

wiessall commented Aug 24, 2022

I'm observing the same thing when saving tiffs after motion correction using 'reg_tif': True. This shows both when inspecting the saved files using exiftool as well as when loading the tiffs using tifffile.imread: In both cases only x,y dimensions are recognized and the stack appears as a single image. For me it is a bit cumbersome since I am using this output for other applications as well. I currently have a small conversion function that I run like so:

def format_suite2p_stack(filename):
    tif = tifffile.TiffFile(filename)
    tif_stack = tifffile.imread(filename, key=range(len(tif.pages)))
    tifffile.imwrite(filename, tif_stack)

Is there a reason however not to save the tiffs using tifffile.imwrite directly?

Update:
After checking https://github.com/rochefort-lab/fissa/issues/150 better I might understand better why not to change the save process, maybe the functions helps others who end up here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants