Something I have been doing lately is looking into repair of damaged and corrupt JPEG photos. I have been offering a JPEG repair service for a while now. Learning from that experience I have created a utility called JPEG Repair Toolkit that addresses most common issues with corrupt and damaged JPEG files.
Basically there are two types of issues:
- JPEG file is too corrupt to open with any photo viewer or editor. Usually Windows Explorer is unable to show previews or thumbnails.
- File opens but the contents do not display correctly. Colors are ‘off’ and image data is misaligned.
Of course it also possible damage extends overlaps both areas (partially).
Corrupt and damaged JPEG files
A JPEG image consists basically of two parts:
- The JPEG Header
- Actual image data, which is encoded, compressed binary data.
If the header is corrupt, and only the header, by far the easiest plus the most effective way to repair the file is with the use of a ‘sample’ file and a hex editor such as HxD. I have written about this in more detail here. In short you cut the header of a known good file and stick to the image data of the corrupt file. This process can be easily automated.
A corrupted header typically looks like this in Windows Explorer (large thumbnail view):
The image data
The image data depends on the information in the header to be decoded correctly. Without this info it’s just a binary blob. Manipulating the binary blob is hard to automate and beyond the scope of this blog post. Still, the JPEG Repair Utility I introduce in this post does repair invalid JPEG markers within this blob which is often required before the data can be manipulated at all.
You can repair invalid markers manually using HxD and JpegSnoop.
Corruption in the JPEG image data can take many shapes and forms. Key is that part of the image shows, distorted, but non the less. Simple corruption may look something like this:
My utility to repair corrupt and damaged JPEG files
My utility JPEG-Repair Toolkit allows you to repair corrupt and damaged JPEG files yourself using a reference or sample file. There are two conditions for the method used to be successful:
- File contains image data.
- A known good sample file is available.
In other words, the need for image data means that it is the JPEG header that is damaged or corrupt. The sample needs to be intact and shot with the same camera using the same settings (resolution, quality settings ) as the corrupt file(s).
JPEG-Repair is a utility to repair corrupt and damaged JPEG files that suffer from a corrupt header. It takes a known good sample, determines the header, processes the header and merges this header with the image data of the corrupt files.
Steps to repair corrupt and damaged JPEG files
Prepare a folder to copy the corrupt JPEGs and Sample file to. Always work on copies of the corrupt files! The reference/sample file needs to be shot with the same camera, using the same settings!
Download and extract JPGRepair. There is no setup, just copy the .exe file where ever you like. Run JPGRepair (double click).
- Select a repair mode > Pick Repair (header)
- Browse to the folder containing the corrupt file(s. Select the corrupted files.
- Select the reference file.
- Click Repair.
Files that JPEG-Repair was able to fix will be saved automatically.
|These videos explain how to repair corrupt and damaged JPEG headers using JPG-Repair
|Procedure for repairing JPEGs
|Procedure for repairing distorted JPEGs
Corruption in JPEG image data, like half grey image
If the header is okay, but the JPEG bit stream is corrupt you are facing a more challenging problem. The JPEG bit stream contains encoded and Huffman compressed data. Due to compression there is no one on one relation between any point in the image data with specific RAW data. So, a pixel exactly in the middle of the image does not correspond with the RAW byte value in the middle of the JPEG bitstream.
The JPEG-Repair Toolkit offers the option to manipulate RAW bytes with visual feedback. Using this method it is often possible to repair (read: remove) corrupt data.