napari / napari-tiff

A napari reader plugin for tiff images.
BSD 3-Clause "New" or "Revised" License
8 stars 4 forks source link

Photometric PALETTE tiff colormap bug #32

Closed GenevieveBuckley closed 2 months ago

GenevieveBuckley commented 2 months ago

Problem

Opening tiff files with the photometric PALETTE value results in a new custom colormap being added to the napari colormap dropdown list. And if you open multiple images like this, you get multiple custom colormaps (one for each tiff image opened).

How to reproduce

  1. Download the "bali.tif" image from https://github.com/tlnagy/exampletiffs and check it uses the PHOTOMETRIC.PALETTE
    
    from tifffile import TiffFile, PHOTOMETRIC

tif = TiffFile("bali.tif") assert tif.series[0].pages[0].photometric == PHOTOMETRIC.PALETTE



2. Drag and drop the "bali.tif" image onto an open napari viewer (with the napari-tiff plugin installed in your napari environment). Observe that the image opens, and a new colormap called `[unnamed colormap: 0]` has appeared in the list of colormaps.

3. Again, drag and drop the "bali.tif" image onto the napari viewer a second time. Observe that a second copy of the image opens, and the colormap associated with it is called `[unnamed colormap: 1]`

## Extra details

This is the relevant section of code: https://github.com/napari/napari-tiff/blob/7dd6c3b88ae1e168eb2a65c0f14e69d0f533d3d3/napari_tiff/napari_tiff_metadata.py#L146-L154