Playing with HEIC images in lossless mode

One of the most interesting features of the new HEIF/HEIC image format — and a true expected innovation — is lossless compression.

Before the HEIC era, to chose between lossy or lossless required the user to completely switch between image file formats:

  • You had to chose lossy (JPEG) if you needed small file size, loosing other features such as alpha channel (transparency). Not to mention to loose forever the original information about your subject. And loosing even more every time you edit your photos.
  • You had to chose lossless (PNG, TIFF) if you needed alpha channel and pixel perfectness for computer-generated samples. Having to deal with potentially bigger file sizes and formats not popular with EXIF, XMP and IPTC tags and metadata.

The new HEIF format with HEVC (H.265) compression (HEIC) unifies all of that. One single industry-standard image format can handle:

  • advanced lossy and lossless with high compression rates for the smallest possible file sizes
  • transparency and alpha channel
  • animations (remember GIF ?)
  • photo metadata with EXIF, XMP, IPTC and MPEG-4 style info

I used macOS 10.13.6 plain Preview app to convert some pictures and photos to lossless HEIF/HEVC. The conversion is of very high quality, preserving all original files metadata. These are the impressive results:

Original file size in bytesLossless HEIC file size in bytesCompression ratePicture dimensionsSource image type
19,572,28813,898,34571.01%6016×4016Nikon DSLR camera raw photo processed by Adobe tools and saved as DNG
22,250,0187,367,32233.11%4352×3264Unprocessed Canon G1X raw photo (CR2)
3,208,0627,251,778226.05%4032×3024iPhone X regular unprocessed JPEG photo
635,773424,80766.82%6452×3326Large computer-generated PNG file with gradients and alpha channel
5,031103,5142057.52%600×600Small computer-generated PNG file with gradients and alpha channel
21,141,6058,537,32140.38%5891×2271PNG created from a JPEG photo

As you can see, HEIF/HEIC lossless compression provides significantly smaller files when compared to other lossless formats. As pointed above, better compression is just one of the benefits of this new format. Standardisation and a single format to all needs are other benefits.

HEIF also supports advanced metadata tagging as JPEG does. Exiftool is the only tool that I know that can tag HEIF files. I use it to tag my iPhone photos with information such as:

  • Image regions and face names
  • Geolocation, including names of places, cities, zones, countries
  • Other file and camera metadata

HEIF is considerably more difficult to handle by programers. But this is a limitation that will be surpassed over time, as already did Exiftool.

About patents, HEIF and HEVC are completely free if used as software only. It means your camera manufacturer will have to pay royalties to the format creators, but computer software creators and users are free to use it.

Having said that, we are wasting our time still using old inefficient image formats as JPEG, TIFF, DNG and PNG for most use cases. Lets move to HEIF/HEIC.

Original and converted pictures used in this analysis are here.

14 thoughts on “Playing with HEIC images in lossless mode”

  1. > About patents, HEIF and HEVC are completely free if used as software only. It means your camera manufacturer will have to pay royalties to the format creators, but computer software creators and users are free to use it.

    This is a very misleading statement. There is an patent licence exception for free-as-in-beer software implementing HEVC patented features, from the HEVC Advance pool only, and not the two other patent licensing pools.

    Regardless, a “free as in beer” exception, even if it were offered by all patent pools, is not compatible with libre software generally, as it effectively imposes an additional restriction on charging for libre software. The fee waiver also *only* applies when the software is *not bundled* with hardware.

    > Lets move to HEIF/HEIC.

    So no, let’s not. It has serious patent problems.

    AVIF has some potential, as the equivalent still image format from AV1 https://en.wikipedia.org/wiki/AV1#AV1_Still_Image_File_Format_(AVIF). Maybe you might want to consider investigating that.

    1. Bob, I’m aware of AV1. I see it as a format still being developed and not in plans to be adopted by anybody. While HEIC is already there, in Apple, Windows and entering camera manufacturer domains.

      I might have indeed incomplete/incorrect information about HEIC IP issues. Even so, I think HEIC is the best think we currently have as an image format. It solves every single problem of older formats, but the IP one. And being widely adopted, open source software will be also widely available and IP constrains will be practically mitigated. As happened with MP3.

  2. Hi Avi
    I have been scanning (using a desktop scanner) or copying (with digital camera) old negatives and slides — and then storing them in TIFF format (for losslessness). As you indicate, the file sizes are substantial.
    Would I be losing anything if I convert the TIFFs I’ve created so far to HEIC? Would converting back from the HEIC to TIFF generate a file identical to the original TIFF?
    Thanks!

    1. As long as you convert to HEIC Lossless you won’t lose nothing in quality and you’ll get smaller file sizes.

      If you won’t pay attention to this losslessness feature of HEIC, the default is lossy compression which yields to much smaller file sizes at the cost of very small loss of quality.

      1. Hi AVI
        Have you made a software or package to implement the lossless HEIC compression?

      2. old topic, but I just tried to convert a png into heic lossless using preview, and the picture is different, hence it is not lossless. I have to zoom in at pixel level to see the difference, but it’s very obvious once you look at single pixels. Not saying heic cannot be lossless, but Apple’s implementation is not.

  3. Hi AVI,
    I am also trying to convert some tiff images to HEIC, the only tools I can find in Windows is it HEIF Image Extension, which can be called by other programs to convert such as XnviewMP.

    However, some extra black line appears on images with odd number resolution after converting. I notice that you convert a picture with 5891×2271 dimension. Would you mind tell what tool you use?

    Thanks

    1. Tshik, I think to forgot to set for lossless conversion.

      I used macOS Preview app for conversion. It’s the default app that macOS runs when you double-click any image.

  4. Hello AVI

    Can Raw camera files converted to HEIC be converted back to raw with no loss. The reason is to store files compressed by Heic and then restore them to raw for processing.

    Thank you for your work

    1. Yes, you can.

      But you shouldn’t.

      You can convert raw photos (CR2 file extension, for exemple) to lossless or lossy HEIC and you’ll get smaller files. My tests get 33% smaller files when converting a lossless CR2 files to lossless HEIC.

      But raw file formats as CR2 and Adobe DNG are better suited to handle these kind of assets. These formats will handle lossless image edits or all image editing history. So for archiving, you should use Adobe DNG.

  5. Use Rawtherapee and Gimp 2.10.22 and above these will solve format problem as it supports virtually every format

Leave a Reply

Your email address will not be published. Required fields are marked *