Quantcast
Channel: DiskTuna // Photo Repair & Photo Recovery
Viewing all articles
Browse latest Browse all 286

Corrupt JPEG Files

$
0
0

Corrupt JPEG file Repair and JPEG File Recovery are often mixed up.

  • Image Recovery: Meaning getting lost or deleted files back from for example a memory card.
  • Or, Repair of JPEG files that can not be opened in image viewing or image editing software, or that appear to be corrupt when viewing them (colors off, shifted pixels etc.).

Recovering JPEG Files

You need to recover .JPG files from for example a memory card because they disappeared: Your digital photo camera, smart phone or the Windows explorer simple doesn’t show you the files. Maybe because they were deleted or the card was formatted. Or the file system on the card somehow got corrupted. So, it’s some kind of problem with the storage of the JPEG Files.

File System based recovery

Recovery is relatively ‘easy’. First of all you can try to recover a JPEG file just like you would recover any other lost or deleted file. I call that file system recovery. A data recovery tool scans the file system and locates pointers to the files. Using those pointers the content of the deleted file is copied to another disk. DiskTuna DFR can recover digital images that were deleted just as easy as any other file. If the preview, that is generated from the actual file content displays an intact image, then it can be recovered for sure.

DiskTuna DFR File Preview

This deleted image can be recovered intact

RAW recovery or File Carving

Most specialized Digital Photo Recovery tools are RAW scanners, or file carvers. Rather than looking for file system structures that point to the file, they look for the files themselves. JPEG files start with a specific byte sequence which makes it possible to recognize them when looking at a disk or memory card on a sector level.

JPEG header FF F8

JPEG starting with hex sequence FF F8.

Once the ‘signature’ is detected, it is assumed that the rest of the file will follow. The JPEG file also contains it’s own size. So, xxxx bytes are copied into a file starting with FF F8. Using this method it is very difficult to recover fragmented files. Another drawback is that the directory structure can not be recovered. Although this isn’t probably much of an issue when recovering digital images from memory cards.

Repairing corrupt JPEG Files

Corrupt JPEG files are image files that do not display correctly or not at all. So, you have access to them but when opening the corrupt JPEG using an image viewer or editor:

  • It does not display.
  • The viewer reports an error with the file (Not a valid image file).
  • Only part of the image is displayed.
  • The image shows extreme artifacts (off colors, grey bars, colored bars etc.).

So, the files are there, but there is a problem displaying them correctly.

A corrupt JPEG file

A corrupt JPEG file found on the internet

To correctly display the corrupt JPEG, the file itself must be repaired. As is the case with file recovery, automated tools are available to repair corrupt JPEG files. In my experience most of them are not worth their money. I tried several of the higher rated ones on review websites and blogs (example: https://www.raymond.cc/blog/repair-and-fix-corrupted-images/) tools on the above image, none of them even came close to repairing the above picture.

I was able however to repair the file using a specialized JPEG file editor that I am working on. In this case, the actual compressed (!) image data itself was corrupt. ‘Patching’ (directly modifying, inserting or deleting individual bytes or binary data) was used to repair the file. Due to the patches applied some grey tiny blocks occurred which were repaired using in-painting.

A Definition of inpainting: Given an image and a region Ω inside it, the inpainting problem consists
in modifying the image values of the pixels in Ω so that this region does not
stand out with respect to its surroundings. – source: http://math.univ-lyon1.fr/~masnou/fichiers/publications/survey.pdf

The JPEG repair workflow:

  • Test/Verify JPEG internal structures (markers) using a utility under development. You can see it as chkdsk for a JPEG file. It tests structures like chkdsk does, it does not check the actual data (the image data). This file was structurally okay, which is also why image viewers have no trouble displaying it. The tool also allows for the manipulation of structures and importing them from JPGs with the same properties.
  • Patching compressed image data. This is a labor intensive process with lots of trial and error. And although colors were restored and image shift (look at how the upper thumb is shifted from the lower thumb) was corrected by inserting (blank) data.
  • Due to the insertion of ‘zero’ bytes, grey blocks appeared which was then ‘fixed’ using an inpaint tool that is also under development.
Damaged block of several MCUs due to insertion of extra data

Damaged block of several MCUs due to insertion of extra data

 

The repaired JPEG

The repaired JPEG

 

 

The post Corrupt JPEG Files appeared first on DiskTuna Disk Utilities.


Viewing all articles
Browse latest Browse all 286

Trending Articles