letmaik / rawpy

📷 RAW image processing for Python, a wrapper for libraw
https://pypi.python.org/pypi/rawpy
MIT License
587 stars 67 forks source link

Cannot read thumbnail of NEF file #215

Closed giacomomarchioro closed 7 months ago

giacomomarchioro commented 7 months ago

Hi all thanks for this wonderful package!

When I try to read the thumbnail of a .nef file I get a byte object containing the whole image:

    import rawpy
    with rawpy.imread(r"testtnef") as raw:
        try:
            thumb = raw.extract_thumb()
        except rawpy.LibRawNoThumbnailError:
            print('no thumbnail found')
        except rawpy.LibRawUnsupportedThumbnailError:
            print('unsupported thumbnail')
        else:
            g = thumb.data

        print("thumb:",type(g))
        print(raw.sizes)

This can be opened using:

from PIL import Image
import io
image = Image.open(io.BytesIO(thumb.data))
image.show()

Using imageio I can get the thumbnail but not the image:

import imageio
img = imageio.read(r"test.nef")
i1 = img.get_data(0)
letmaik commented 7 months ago

rawpy is using libraw's unpack_thumb function which extracts the largest thumbnail available in the file (and that could be a full-size JPEG). See https://www.libraw.org/docs/API-CXX.html#unpack_thumb. It's likely your file has multiple thumbnails, but rawpy currently doesn't support reading the other ones. Do you have a use case for extracting the smaller thumbnails or does the large one work as well for you?