13

Hi I'm sure there were a lot of similar questions asked, but after searching a lot I didn't find any post describing my situation.

I have some jpg files which have some colours wrong after a certain point and also every pixel is shifted to the left. I think this is because of some missing bytes at the point where it changes. I tried to edit the file with vi but it seems impossible to find out where the missing bytes are, also vi is very complicated to use. I also tried nano but it's not binary-safe.

This is one of the images in question:

enter image description here

So I want to ask you two questions:

  1. How can I repair such images in Linux?
  2. How could I safely open and edit the file in a binary text editor under Linux?

Edit: using hexedit I discovered that from position 0x27F000 to 0x27F403 there are only ones 0xff, and from 0x27F404 to 0x27FFFF there are only zeroes 0x00. This makes something like this:

    0027EFF0   F8 83 C3 E2  09 35 AF 13  44 6E C5 FD  C7 EF 23 E8  .....5..Dn....#.
    0027F000   FF FF FF FF  FF FF FF FF  FF FF FF FF  FF FF FF FF  ................
    [...]
    0027F400   FF FF FF FF  00 00 00 00  00 00 00 00  00 00 00 00  ................
    [...]
    0027FFF0   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ................
    00280000   8F 39 6E 47  4F 43 5F 36  7C 73 66 F1  0D AE AD AF  .9nGOC_6|sf.....

Changing these bytes with random numbers I was able to unshift the image, but there is still the colour problem.

Could someone point me to some documentation about jpeg encoding so I can figure out how to know where an 8x8 block ends.

I'm wondering why the positions are so precise (0x27F000 to 0x27FFFF), could this be a bug of my cam or the memory card I used?

2
  • I had this happen once to a large set of images. I just ended up deleting them, a shame really. I'd be interested to know if you succeed in repairing these, you've got a tough job ahead of you.
    – dtmland
    Jun 24 '13 at 20:16
  • Yes it is it's a shame, I'm trying to figure out how this jpeg files are encoded, it's just one 8x4000px line which I will have to delete. In this file there are exactly 4KB damaged in a file of 4.4MB It's less then 0.1%!!!
    – Falk
    Jun 25 '13 at 14:23
2

The wikipedia article on http://en.wikipedia.org/wiki/JPEG#Entropy_coding has a lot of information - the most relevant to your current problem is this one:

The previous quantized DC coefficient is used to predict the current quantized DC coefficient. The difference between the two is encoded rather than the actual value. The encoding of the 63 quantized AC coefficients does not use such prediction differencing.

The color shifting in the remainder of the image is caused by a single bad DC coefficient that cascades to all the rest. You might be able to find a small area (maybe one byte, maybe two - it's probably actually some sequence of bits) that reliably affects the colors, and try a large number of different values for that.

It may be easier to simply fix the image in a graphic editor - it looks like the one you posted, other than the shift (and wraparound), may simply have a lower brightness, you could select the area and use the Levels tool. Others that have more involved color shifts, you might be able to get a good enough result by looking at the decomposition in color channels (JPGs may be in RGB or Y'CbCr) and fixing each channel separately, possibly swapping channels.

EDIT: Oops, I didn't see how old your question was. Well, maybe this will be useful to you or someone else.

2
  • Lots of thanks,don’t care about the age of the question, is still have the image and some more.
    – Falk
    Jan 2 '15 at 22:49
  • I think it's a shame that the camera didn't expect such a situation, they should put some key blocks every n (say 32) rows of blocks. the other problem is that I even don't know if there is a lossless compression applied after the lossy one, like Huffman. I'd rather play around with some bytes than open the image with graphic editors: first most of them don't want to open these images, second I don't think that I could find the exact correction playing around with some sliders. @Random832 thanks and please tell me if You know something more.
    – Falk
    Jan 2 '15 at 23:09
1

2) How could I safely open and edit the file in a binary text editor under Linux?

Lots of great binary editors can be found here: https://stackoverflow.com/questions/839227/how-to-edit-binary-file-on-the-unix-systems

My personal favorites are vim with :%!xxd hack and hexedit

2
  • 2
    Ok, and something easier to use? like nano.
    – Falk
    Jun 24 '13 at 14:17
  • something easy like shed?
    – Attie
    Oct 24 '17 at 19:33
0

Have you tried photorec? You can install it on Ubuntu like this:

sudo apt-get install testdisk

Check the manual with:

man photorec

and just run photorec from the terminal like so:

photorec

It will ask you to select the source and a destination and try to recover jpg files automatically.

To prevent damaging the original, I recommend making a copy with the dd command. Good luck!

7
  • 1
    Hi, photorec is designed to recover files from a corrupted filesystem, in my case the filesystem is fine, but the image is corrupted so it's a totally different situation.
    – Falk
    Oct 24 '17 at 22:27
  • 3
    Hi, as I wrote earlier there is nothing wrong with the filesystem, it's the JPEG file which has the error, thanks anyway.
    – Falk
    Oct 25 '17 at 13:03
  • 1
    I know how photorec works, and it's not what I need, it would just copy the picture as it is with out repairing it.
    – Falk
    Nov 1 '17 at 11:10
  • 1
    I'm just trying to help. You type would, so you didn't try? I actually ran it on an SD card and yes it copies them but it fixed them too. Can't hurt to try, right? If it's not worth trying, fine, good luck. All I am saying is that it did repair it for me. I will not respond any further to avoid endless discussion. Nov 1 '17 at 15:24
  • 2
    I wont try it because photorec is ment to be run with a device as parameter, the jpg file I have is on my hdd which is perfectly fine. It's just a diferent type of situation. As I said thanks anyway.
    – Falk
    Nov 1 '17 at 17:48
-1

I just used Photorec to recover pictures from a SD card that went corrupt. Although it did not recover all files, it did a great job recovering a good number of them. With that said, MP4 videos were recovered but could not be opened. Some JPEG files were recovered but they also couldn't be viewed or were really messed up, as the sample provided at the beginning of this thread. Photorec did not fix them.

Bottom line: Photorec is designed to retrieve lost files from a corrupt FILE SYSTEMS but apparently doesn't do anything to recover the content of corrupted FILES.

1
  • Hi, Wander, I know photorec, but it's not what I'm looking for. It won't fix corrupted files.
    – Falk
    Oct 23 '19 at 19:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.