can I repair corrupted JPEG files or other photos?

By | March 21, 2021

JPEG-Repair Toolkit

Dude, can my JPEGs be repaired?

“can I repair corrupted JPEG files or other photos?” is a question I get asked many times a week. Or, the variant “I ran your tool JPEG-Repair, but it does not repair my photos.”. Or, “I recovered deleted JPEG files but they are all corrupt and can not be opened”.

Key question is indeed IF corrupt JPEG files and other photo formats such as CR2 (Canon RAW) and NEF (Nikon RAW) can be repaired. And the answer to that is, yes IF the corrupt files contain actual photo data. No one or nothing can possibly repair corrupt JPEG or other photo formats if the files lack any actual photo data. So then my first answer is:

Does the JPEG or RAW photo contain any data to begin with?

low entropy file = no jpeg data

In the above example, the answer is no. Another common value for files containing no data at all is all zeros. It needs no explanation such a file can not be repaired. I mostly see files like this after they have been recovered from an SSD. File recovery software detects deleted files, however the data was trimmed.

File contains data, but is it JPEG (or CR2 or NEF etc.)?

As a rule of thumb, if we see high entropy data it becomes more likely the JPEG can be repaired

This file obviously contains data, but is it JPEG data? Or CR2, or NEF? The data looks reasonably ‘chaotic’. We call this high entropy. If we compare this to the previous image we see highly predictable and repeating data, we call that low entropy.

We can see this is a RAR file, a compressed archive. Compressed data has high entropy, is chaotic. JPEG and RAW photos contain compressed image data. So how do we then differentiate between compressed image data and other compressed data. This is indeed quite tricky and it takes some experience to be able to tell compressed image data and other compressed data.

As a rule of thumb though, when we try to determine if a JPEG can be repaired, seeing high entropy data is a good thing. If we again compare with previous image, we can see how that is not compressed data, as after all a series of FF bytes could be easily compressed.

Examining a corrupt JPEG using JPEG-Repair

Low entropy data = no JPEG. No values < 128 = no JPEG.

In this example we see JPEG-Repair was asked to extract JPEG data from a Nikon RAW file (NEF). JPEG-Repair calculates the entropy for the entire file and this is expressed in a bits/byte value that ranges from 0 to 8. We see it calculated a value of 6.00 bits/byte. The value is displayed in red characters as this is too low; the file does not contain compressed photo data or a large potion of the file contains low entropy data.

We also see a a byte histogram right below the red entropy value which simply displays the number of times a specific byte value was found. Byte values range from 0 – 255 (0xoo – 0xFF) and we see no values below 128 were detected. Normally compressed image data uses byte values across the full 0 – 255 range.

A healthy byte histogram and entropy

A healthy byte histogram and entropy.

The error log window again shows the (too low) entropy and also tells us no JPEG start of image marker was detected. If we add everything up it is unlikely the file can be repaired or that a full resolution JPEG can be extracted. If this were a JPEG file we’d reach the same conclusion.

Estimating for a bunch of JPEGs if they can be repaired

Batch processing multiple corrupt JPEGs, all 0.00 entropy = No JPEG

If you have a large number of JPEG you want to repair or RAW files you want to extract full resolution JPEGs from, use the JPEG-Repair Extract tool and select all files. In above example, 61 JPEGs were selected and we see all of them having an entropy value of 0.00 bits/byte, this is enough to reach the conclusion they can’t be repaired.

This way JPEG-repair can be used to determine the condition of a large number of corrupt JPEGs.

Leave a Reply

Your email address will not be published.