相关文章推荐

First of all, thanks for developing these amazing tools.

For sure is a newbie question, but I cannot find a way to resolve it.

I am running a segmentation using the Napari plugin for cellpose, but when I want to save the resulting masks, I got the following error:

PluginCallError: Error in plugin 'builtins', hook 'napari_write_labels': data too large for standard TIFF file

Any idea how I can save my results? It will be great to get the Outlines as a text file for the ROI Manager in Fiji as in the Cellpose GUI.

Thanks in advance for your help.

When I tried the save all layers option, I got the following error:

TypeError                                 Traceback (most recent call last)
~/anaconda3/envs/cellpose/lib/python3.7/site-packages/napari/_qt/qt_main_window.py in <lambda>()
    498         save_all_layers.setStatusTip(trans._('Save all layers'))
    499         save_all_layers.triggered.connect(
--> 500             lambda: self.qt_viewer._save_layers_dialog(selected=False)
        global self.qt_viewer._save_layers_dialog = undefined
        global selected = undefined
    501         )
~/anaconda3/envs/cellpose/lib/python3.7/site-packages/napari/_qt/qt_viewer.py in _save_layers_dialog(self=<napari._qt.qt_viewer.QtViewer object>, selected=False)
    551                 )
    552             else:
--> 553                 update_save_history(saved[0])
        global update_save_history = <function update_save_history at 0x7f0aed233e60>
        saved = [None, None, None, None, None, None, None, None, None]
    555     def _update_welcome_screen(self, event=None):
~/anaconda3/envs/cellpose/lib/python3.7/site-packages/napari/utils/history.py in update_save_history(filename=None)
     35     settings = get_settings()
     36     folders = settings.application.save_history
---> 37     new_loc = os.path.dirname(filename)
        new_loc = undefined
        global os.path.dirname = <function dirname at 0x7f0b0df77290>
        filename = None
     38     if new_loc in folders:
     39         folders.insert(0, folders.pop(folders.index(new_loc)))
~/anaconda3/envs/cellpose/lib/python3.7/posixpath.py in dirname(p=None)
    154 def dirname(p):
    155     """Returns the directory component of a pathname"""
--> 156     p = os.fspath(p)
        p = None
        global os.fspath = <built-in function fspath>
    157     sep = _get_sep(p)
    158     i = p.rfind(sep) + 1
TypeError: expected str, bytes or os.PathLike object, not NoneType

Again, thanks for your help.

Hi @EdwinHernandezG, sorry for the delay!

I need a little more information to try to reproduce this.
Can you give me a little more information about the shape of the data? what are the dimensions of the mask you’re trying to save?

Thanks @talley for your help.

I am attaching the entire error I got when I try to save the single layer because it is too long.

saving_error.txt (35.7 KB)

It is a label layer, and its dimensions should be the same as the base layer. I suppose correctly? In that case, they are 2176 x 4875 x 390

Again, thanks for your help.

hmmm, this looks like a bug in our default imsave implementation, and the compression kwarg added in Tifffile compress' kwargs deprecated. Update to compression. by Carreau · Pull Request #2872 · napari/napari · GitHub

import tifffile as tf
import numpy as np
# fails (ValueError: data too large for standard TIFF file)
tf.imsave('test.tif', np.zeros((390, 4875, 2176), 'uint32'), compression=1)
# works:
tf.imsave('test.tif', np.zeros((390, 4875, 2176), 'uint32'), compress=1)
tf.imsave('test.tif', np.zeros((390, 4875, 2176), 'uint32'))

cc @jni

@talley what version of tifffile did you test with? compress=1 is now deprecated according to that PR, so it might not be super useful that it works…? Could this be an imagecodecs thing?

I’d love it if @cgohlke could chime in with the “preferred” way to handle 2GB+ arrays going forward… (This array is slightly under 4GB. Searching for the error message turned up this issue in Steve Sylvester’s now-defunct tifffile fork.)

compress=1 and compression=1 are not the same:

compress=1 specifies to use zlib (ADOBE_DEFLATE) compression scheme with level 1. It is a deprecated leftover from the days that only zlib compression was supported.

compression=1 specifies to use the compression scheme TIFF.COMPRESSION.NONE=1.

The equivalent of compress=1 is compression=(8, 1) or compression=('zlib', 1)

“preferred” way to handle 2GB+ arrays

Use compression if you are sure that your data are highly compressible. Otherwise use BigTIFF (bigtiff=True), which however is not supported by all libraries and software (e.g. Pillow).

Hi @EdwinHernandezG, given a labels layer you can save it directly as follows (this is essentially all that the “save layer” command is doing for you)

layer = viewer.layers['your layer name']
tifffile.imsave('filename.tif', layer.data)
# or, with compression
tifffile.imsave('filename.tif', layer.data, compression=('zlib', 1))
 
推荐文章