JPEG Medic // Accurate Manual JPEG Recovery
Table of Contents
  1. Overview
  2. Theory of JPEG Repair
    1. JPEG structure
    2. How to fix broken JPEG file
  3. Working with the Program
    1. Main menu
    2. Virtual folder tree
    3. Files panel
    4. Preview panel
    5. Cluster view
    6. Hex view
  4. Repairing JPEG image
    1. Opening JPEG file
    2. Repair window
      1. Menu commands
    3. Repair procedure
      1. Visual analysis and localization of damaged MCUs
      2. Finding the next correct MCU
      3. Deleting damaged MCUs
      4. Inserting empty MCUs
      5. Color correction
        1. Automatic color correction
        2. Manual color correction
      6. Filling empty MCUs with data
        1. Use the thumbnail image to fill the empty MCUs
        2. Auto-generate missing content
    4. Saving repaired JPEG image
    5. Repairing fragmented JPEG file
    6. Repairing damaged JPEG image based on SOS marker
    7. Repairing JPEG file encoded by ransomware

Use the thumbnail image to fill the empty MCUs

This technique basically means filling the missing parts of the original JPEG image with the data taken from the thumbnail image of a lower resolution. Simply put, the removed parts of the original image will display thumbnail image instead. However, due to lower resolution of the thumbnail, such parts will look blurry. The lower thumbnail resolution is, the more blurry the recovered parts will look.

Below are two examples of restored images. The first one uses the 320x240 thumbnail to recover the image, and the second one uses the 160x120 thumbnail.

Broken JPEG

Broken JPEG fixed with thumbnail

Broken JPEG fixed with thumbnail

This method produces non-ideal results, but it's still much better than nothing. And if the thumbnail resolution is high, the resulting recovered image may even look acceptable.

To preview how the image combined of the original MCUs and the thumbnail image look like, use the Image > Show thumbnail.

To use a specific thumbnail, select it in the Thumbnail list in the right part of the Repair window. The selected thumbnail will be applied automatically when you save the image.

IMPORTANT! The repaired image is always saved using the thumbnail, regardless of whether the Show thumbnail option is turned on or off. If you want to explicitly disable using thumbnails to fill the empty MCUs, select the Don't use thumbnail in the Thumbnail list.

Using a thumbnail to fill empty spaces implies that pixels of the thumbnail is converted from the RGB color space to the color space of the original file (typically YCbCr) and then quantized according to quantization tables of the original JPEG image. As a result, this may lead to slight but visible discrepancy between colors of the inserted thumbnail part and the rest of the image. This can be seen on the edge where the original image and the converted thumbnail link together:

Broken JPEG fixed with thumbnail

You can avoid this by filling the empty space before saving the file. Use the Edit MCU > Apply thumbnail command. When you apply the command, select any empty MCU from the sequence of empty MCU blocks. The command will fills all empty MCUs in the selected sequence, the same way it would be done if you saved the file. Then, the program applies automatic color correction to the filled MCU blocks, which results in a better final result:

Broken JPEG fixed with thumbnail

After this command finishes, the cursor is set to the first MCU just after the filled sequence. This may come in handy if there are visual differences in color tone between the filled area and the following graphical data. You can eliminate this difference using the Edit MCU > Auto color command.

After the program executes the Apply thumbnail command, it treats the filled MCU blocks as normal MCUs. That is, you can apply any operations to them as usual – move, delete, clear and so on.

Some cameras may save thumbnails with certain specifics, for instance with black borders or with dimensions that does not multiply to the size of the original image. JpegMedic allows you to fix such peculiarities to be able to use thumbnails for filling empty areas of the recovered image.

Fixing black borders

Some cameras save thumbnail with black borders:

Thumbnail with black borders

In this case, the repaired image will also have such ugly black bands below the image. To remove these bands, use the Thumbnail > Edit menu command.

Remove black borders

In the Edit thumbnail window, you can crop the image so to remove the black bands. You can also rotate the thumbnail image or flip it here if JpegMedic was not able to determine the orientation of the thumbnail automatically.

To save the edited thumbnail to an external file, click the Save to file button.

Fixing non-matching thumbnail size

Some cameras save thumbnail images so that their size does not multiply to the size of the large image. When you use such a thumbnail to fill the "gaps" in the damaged JPEG, the resulting combined image looks not very good, because the enlarged thumbnail does not match the original image. This can be clearly seen at the edges:

Non-matching thumbnail

To fix this, use the Thumbnail > Position menu command. This command brings up the window where you can adjust positioning of the thumbnail:

Reposition non-matching thumbnail

The Grid with thumbnail option displays the resulting image as a chessboard where cells containing the original image alternate with cells from the thumbnail. This simplifies visual positioning of the thumbnail.

If the program failed to match a thumbnail with the original image and hence the thumbnail is not available, you can select it manually using the Thumbnails > Add menu command. You can also add a thumbnail image from any external file using the Thumbnails > Add from file command.