Is there some program to analyze files, especially image files, for Linux, with functionality similar to hex editors, which will show what bytes changed after I paint some area of the image and etc.

  • 1
    Have you looked at Bless for hex editing? – Bratchley Sep 13 '14 at 16:48
  • You can try using gimp. That should give you a lot of information. – unxnut Sep 13 '14 at 16:58
  • Do you want to highlight the different pixels between two bitmaps? – Jonas Stein Sep 13 '14 at 17:02
  • 2
    Are you really looking to find what bytes have changed? Any hex editor would tell you that, but most image formats are compressed, so byte differences on images would be utterly irrelevant. – Gilles Sep 14 '14 at 0:06
  • You probably will need to roll your own, it should be quite easy e.g. with Python + scipy/scikit-image or with Octave. – Renan Sep 14 '14 at 0:42

If you're just looking for a way to compare an image after manipulation so that you can see what pixels (and in what channels) have changed you can use ImageMagick's compare tool. It's covered extensively here on the ImageMagick website: http://www.imagemagick.org/script/compare.php.

Here's an example from that page, but I'm using a rose image from this site instead. Say you have an image rose.jpg, and you run a sharpening function on it, saving the results to reconstruct.jpg.

$ convert rose.jpg -sharpen 0x1 reconstruct.jpg

      rose.jpg   reconstruct.jpg

We can then use the compare tool to construct a difference1.png image from the 2 images above like so:

$ compare rose.jpg reconstruct.jpg difference1.png


If we want to remove any hint of the original image from the difference1.png we can use the -compose src option to further remove the original image from the difference image. The results can be seen in difference2.png.

$ compare -compose src rose.jpg reconstruct.jpg difference2.png


This only scratches the surface of what compare can do. It can also show you the differences per color channel as well, among other things.

What's the -compose src doing?

This operation is discussed in detail here if you're interested.

excerpt - http://www.imagemagick.org/script/command-line-options.php#compose

-compose operator

Set the type of image composition. See Alpha Compositing for a detailed discussion of alpha compositing.

This setting effects image processing operators that merge two (or more) images together in some way. This includes the operators, -compare, -composite, -layers composite, -flatten, -mosaic, -layers merge, -border, -frame, and -extent.

It is also one of the primary options for the "composite" command.


Command Line Way

There are various command line programs, such as xxd or hexdump, which will output the hex contents of a file to your terminal. You can use vim to edit hex files. See this answer.

Is that really what you want to do though? You stated that you wanted to analyze image files especially. For that it is better to use a programming language.

Using a Programming Language

An image is simply a matrix of numbers. For example, an RGB image might be represented as 3 matrices containing values from 0 to 255. A 5x5 pixel pure red image would look like this:

Matrix 1 (red plane):

255 255 255 255 255
255 255 255 255 255
255 255 255 255 255
255 255 255 255 255
255 255 255 255 255

Matrix 2 (green plane):

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

Matrix 3 (blue plane):

0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0

To analyze images in this manner, various tools have been created. These tools are pretty standard in the image processing world:

  1. MATLAB (Matrix Laboratory) was originally created for this purpose. GNU Octave is mostly compatible with MATLAB and can be used in place of it.
  2. Python is great open source alternative for manipulating images using its scikit-image package.

They are both interactive and very easy to use. MATLAB gives you a >> prompt where you type commands, for instance. No compilation necessary.

MATLAB/Octave Example

To read an image:

>> im = imread('Penguins.jpg');

To extract the red plane from an image:

>> red = im(:,:,1);

This uses the : operator to extract all x coordinates and all y coordintes from the 1st z-plane (the red plane), of the image.

To peek at first 5x5 pixels of the red plane:

>> red(1:5, 1:5)

ans =

  116  118  118  120  118
  116  116  117  118  116
  118  117  117  118  118
  117  117  118  118  118
  119  118  117  118  118

I won't post Python examples but it is similarly easy to do.


If the files are not in some compressed, or otherwise encoded, format, and the changes are limited, you can easily do so with cmp -l.

When we got our first TargaVista graphics board that would provide images to a single shot tape-deck, it came with a simple commandline (DOS) upload utility and paint package, but without any documentation.¹

What was easily calculated is that uncompressed image did have the size of 18 * 3 * (width * height) pixels. I then created a complete black image, and derived a few files where on each only one pixel, in a primary colour, in one of the corners. By comparing these files (after transfer to SunOS) with cmp - it was easy to analyse the byte order of the rows and columns, as well as the order of the colors, and write a program to unpack our rendered .gif images to .tga

¹ This was in 1990 before there were open source libraries that supported the .tga/.vst
² It took the dealer, that sold us the card, several weeks to get us a barely readable, n-th copy, fax with the file format information from the US. Based on that I could implement the RunLengthEncoded version of the files and save a us a few seconds upload time per frame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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